Skip to content

fix(api): use .get() instead of .pop() for request in exception inter… - #6229

Open
shafeeq27edu-ai wants to merge 2 commits into
Agenta-AI:mainfrom
shafeeq27edu-ai:fix/kwargs-pop-mutation-exceptions
Open

fix(api): use .get() instead of .pop() for request in exception inter…#6229
shafeeq27edu-ai wants to merge 2 commits into
Agenta-AI:mainfrom
shafeeq27edu-ai:fix/kwargs-pop-mutation-exceptions

Conversation

@shafeeq27edu-ai

Copy link
Copy Markdown
Contributor

Description

This PR fixes a destructive mutation bug in the exception interceptor utility. kwargs.pop("request") was silently removing the request key from the caller's dictionary, which could cause missing-key errors on retries or downstream usage.

Summary

What changed? Changed kwargs.pop("request", None) to kwargs.get("request", None) in api/oss/src/utils/exceptions.py.

Why was this change needed? pop() mutates the original kwargs dict. If the intercepted function is retried or the kwargs are reused, the "request" key is missing. This is especially dangerous because the code is inside a suppress() context manager that swallows exceptions silently.

What problem does it solve? Prevents subtle missing-key bugs in every API endpoint that uses the exception interceptor.

How the change addresses the root cause: By using .get() instead of .pop(), we perform a non-destructive read. The caller's kwargs dict remains intact.

Testing

Verified locally

  • Read the surrounding code in exceptions.py to confirm request is not required to be removed from kwargs for downstream logic
  • Ran ruff check api/oss/src/utils/exceptions.py — passes with no errors
  • Ran ruff format api/oss/src/utils/exceptions.py — no changes needed

Added or updated tests

N/A — This is a 1-line safety fix with no behavior change. Existing API tests cover the interceptor path.

QA follow-up

N/A — The fix is self-contained and verified by static analysis.

Demo

BEFORE FIX :

image

AFTER FIX:

image

Checklist

  • I have included a video or screen recording for UI changes, or marked Demo as N/A
  • Relevant tests pass locally
  • Relevant linting and formatting pass locally
  • I have signed the CLA, or I will sign it when the bot prompts me

…ceptor

Prevents destructive mutation of the caller's kwargs dict. If the intercepted function is retried, the request key remains available.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 23, 2026
@vercel

vercel Bot commented Aug 23, 2026

Copy link
Copy Markdown

@shafeeq27edu-ai is attempting to deploy a commit to the agenta projects Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot Bot added bug python Pull requests that update Python code labels Aug 23, 2026
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: f787cfca-5fe8-4fad-ba96-7c02667ab2c0

📥 Commits

Reviewing files that changed from the base of the PR and between 753af38 and 6b01db7.

📒 Files selected for processing (1)
  • api/oss/src/utils/exceptions.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/oss/src/utils/exceptions.py

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Preserved the request argument when handling exceptions, ensuring wrapped operations continue to receive it correctly.
    • Maintained exception metadata extraction without altering request parameters.

Walkthrough

intercept_exceptions now preserves the request keyword argument while extracting request metadata.

Changes

Exception interception

Layer / File(s) Summary
Preserve request argument
api/oss/src/utils/exceptions.py
intercept_exceptions reads kwargs["request"] without removing it from the wrapped function’s keyword arguments.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 6b01d

This localized fix preserves the request data for retries and downstream handling without changing intended endpoint behavior; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the API fix: replacing destructive request removal with a non-destructive read in the exception interceptor.
Description check ✅ Passed The description accurately explains the mutation bug, the code change, its impact, and the validation performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug python Pull requests that update Python code size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant