Repository navigation
fix(responses): one answer for which tool a bridged call is, read by the reply, tool permission and spend logs - #53269
Conversation
[High impact] The PR appears safe to merge, with no new actionable issues found.
|
|
bugbot run |
Bugbot is paused — your team has an unpaid invoiceBugbot is paused because your team has an unpaid invoice. Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically. (requestId: 62bab0d1-8d88-4eb3-a28f-57f48c413f7e) |
1799deb to
1288d12
Compare
91a2164 to
e970a95
Compare
|
@greptileai review |
e970a95 to
1aa91c9
Compare
|
@greptileai review |
1aa91c9 to
a1399b8
Compare
…umed turns and by tool permission The Responses-to-chat bridge sends a long namespace tool under a shortened name. The lookup from that name back to the caller's namespace and tool now also learns names from earlier namespaced calls in the history, so a resumed Codex session whose MCP tools are not listed yet gets the real tool back instead of an unknown call. The bridge records that one lookup on the request's logging object, and the tool permission guardrail reads the same record, so a rule written against the full name also applies to the shortened name the provider was sent. A client cannot set the record from its own request body.
… back The tool permission guardrail read a filtered copy of the bridge's name lookup, so a namespace tool that was not shortened, or a custom tool sharing a shortened name from history, was judged under a different name than the one the caller received. The lookup now leaves out custom tool names, the bridge records all of it, and only logs keep renaming just the shortened names.
… and spend logs A deferred top-level tool was recorded as if it were a member of a namespace with its own name, so tool permission judged it as name__name and a namespace allow rule could let it through. Each bridged name now maps to either a namespace member or a deferred top-level tool, and the reply, tool permission and spend logs all read that same answer without filtering it.
a1399b8 to
0d1f88a
Compare
|
@greptileai review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0d1f88a. Configure here.
…64 characters Codex sends the tool inside the mcp__vault namespace, so the joined name runs to 90 characters, past Bedrock's limit of 64. The row runs on every setup and passes on the random value the tool returns, with Codex seeing the tool's full original name. It guards LIT-10289, fixed by #53269
…64 characters (#49826) Codex sends the tool inside the mcp__vault namespace, so the joined name runs to 90 characters, past Bedrock's limit of 64. The row runs on every setup and passes on the random value the tool returns, with Codex seeing the tool's full original name. It guards LIT-10289, fixed by #53269
Handwritten 1-3 sentence description
We shorten long tool names when Codex calls /v1/responses on Claude through Bedrock, and now the reply, tool permission and spend logs all read one answer for which tool a short name stands for, so a deny rule on the real name finally fires.
Details
TLDR
execdidn't apply at all, and a deferred top-level tool was judged as if it sat in a namespace of its own name.Intentional product change: a tool permission rule on a namespace or tool name, like
^exec$, now also applies on/v1/responsesrequests that go through the chat completions bridge, where before it was skipped. Spend logs also name a bridged call by the tool the caller gets back, so a provider that answers with a namespace tool's bare name, likerun, now logs asexec__run. Calls the provider answers with the full or shortened name log the same as before.The shortening itself landed on main in #50768. This PR started as the LIT-10289 fix and was rebuilt on top of that, keeping only the gaps it left.
User Flow
Before: a Codex user resumes a session on Claude through LiteLLM, and the earlier MCP tool comes back under a name Codex doesn't know.
http://<litellm>/v1as aresponsesprovider, with an MCP servervaultwhose tool name is 78 characters/v1/responseswith the earlier vault call in the history but before the vault tool is listed againfunction_callnamedmcp__vault__read_the_current_secret_value_from_the_vaul_f96e7908with no namespaceunsupported call: mcp__vault__read_the_..._f96e7908After: the same resumed turn calls the real tool.
http://<litellm>/v1as aresponsesprovider, with an MCP servervaultwhose tool name is 78 characters/v1/responseswith the earlier vault call in the history but before the vault tool is listed againfunction_callnamedread_the_current_secret_value_from_the_vault_that_this_codex_session_was_givenwith namespacemcp__vaultThe same answer also fixes tool permission on POST
/v1/responses. A proxy admin who denies^exec$and allows everything else used to see a call to theruntool in namespaceexecgo through. A deny on the long vault tool's real name also didn't apply. Now both come back asPermission denied: Tool ... denied by rule ...instead of the call.Linear ticket
Resolves LIT-10289
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Before is the merge base
b1ea9ae7dcf. After is the latest product commit0d1f88a3685. One case also runs at9f9d069878e, the PR's previous tip, because that is where it broke. Every proxy runs from agit archiveof the named commit with one worker and no Redis, and the native bridge built atb1ea9ae7dcf(this PR touches no Rust). The spend log leg adds a throwaway Postgres. These are single requests with no shared rate limit, budget or router state. Tool permission runs are non-streaming because streaming/v1/responseswith a post-call tool permission guardrail already fails on main (see Caveats).Models are Anthropic
anthropic/claude-sonnet-5-5and Bedrockbedrock/us.anthropic.claude-sonnet-5-5. On Anthropic a deferred tool stays hidden until tool search loads it, so the model can't call it directly and the deferred case only runs on Bedrock. Case 4 uses neutral wording because Bedrock's content filter blocked an earlier version of that prompt.Proxy start, env var names, configs and clients
The spend log leg adds a Prisma client generated from the tree's schema at the front of
PYTHONPATH, setsDATABASE_URLto a fresh database on a local Postgres, adds--use_v2_migration_resolver, runs on port 4628, and readsGET /v1/tool/spendabout 20 seconds after the calls.Env var names:
LITELLM_MASTER_KEY(fresh random key),ANTHROPIC_API_KEY,AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN,AWS_REGION_NAME=us-east-1, plusDATABASE_URLandLITELLM_LICENSEfor the spend log leg.Resumed-turn config (no guardrail):
Namespace and custom tool config:
Vault tool config:
Deferred tool config:
Spend log config:
Resumed-turn client, run as
python resume_call.py <model> nostream|stream:Tool permission client, run as
python id_call.py <model> exec|custom_neutral|vault|deferred. The spend log leg runs the same client with the key and port read from the environment:Before (b1ea9ae)
[["mcp__vault__read_the_current_secret_value_from_the_vaul_f96e7908", null]], the short name with no namespace, non-stream and stream. Anthropic returned the same non-stream and made no tool call in its stream runexecnamespace tool with a deny on^exec$. Anthropic and Bedrock both returned[["function_call", "run", "exec"]], so the denied tool went through[["function_call", "read_the_current_secret_value_from_the_vault_that_this_codex_session_was_given", "mcp__vault"]], so the denied tool went throughPermission denied: Tool 'mcp__vault__read_the_current_secret_value_from_the_vaul_f96e7908' denied by rule 'deny_vault_named_custom_tool'. Main is fine herereadwith only^read__.*$allowed and a default of deny. Bedrock returnedPermission denied: Tool 'read' denied by default actiontwice. Main is fine hereexecand deferredreadcalls,GET /v1/tool/spendlistedmcp__vault__read_the_current_secret_value_from_the_vault_that_this_codex_session_was_given(2 calls),exec__run(2 calls) andread(1 call)Previous tip (9f9d069)
[["function_call", "read", "read"]]on Bedrock twice. The check judgedreadasread__read, so the namespace allow let it through. This is the bypass Veria foundAfter (0d1f88a)
[["read_the_current_secret_value_from_the_vault_that_this_codex_session_was_given", "mcp__vault"]], non-stream and stream. Anthropic returned the same in its stream run and made no tool call in its non-stream runPermission denied: Tool 'exec' denied by rule 'deny_exec_namespace'on Anthropic and BedrockPermission denied: Tool 'mcp__vault__read_the_current_secret_value_from_the_vault_that_this_codex_session_was_given' denied by rule 'deny_vault_read'on Anthropic and BedrockPermission denied: Tool 'mcp__vault__read_the_current_secret_value_from_the_vaul_f96e7908' denied by rule 'deny_vault_named_custom_tool'on Anthropic and BedrockPermission denied: Tool 'read' denied by default actionon Bedrock twiceEarlier rounds
At
b7a83256e24before and95a011b74f5as the previous tip, case 4 went through at95a011b74f5on Anthropic and Bedrock ([["custom_tool_call", "mcp__vault__read_the_current_secret_value_from_the_vaul_f96e7908", null]]), which is the bypass Greptile found, and case 2 went through too. At7c6ec9f5a09before and1288d12d6ceafter, the Codex row from #49826 onclaude_bedrockwith a resumed turn passed 4 of 4 on main and 3 of 3 on this branch.Unit tests
New tests run the real bridge and then the guardrail on what it recorded, for a namespace tool known only from history, a custom tool sharing a short name from history, and a deferred top-level tool under a namespace allow rule. A spend log test checks the logged name for a bare member, a joined member, a deferred tool and a plain function. The deferred guardrail test and the bare-member spend log case fail at
9f9d069878eand pass at the tip, and the other spend log cases pass at both. Older tests cover the resumed-turn mapping, the long-name deny, and a forged name map in the request body being ignored.Type
🐛 Bug Fix
Caveats (if any)
Medium
/v1/responseswith a post-call tool permission guardrail fails on main withError building chunks, before and after this PR. So the tool permission cases are shown without streamingLow
previous_response_idfollow-up only learns a name from history that the new input carriesNote
Medium Risk
Touches permission enforcement and spend attribution on bridged /v1/responses paths; behavior intentionally changes for namespace rules and bare-name logging.
Overview
Unifies which tool the caller sees when the Responses API is bridged through chat completions, replacing simple sent-name → full-name strings with structured
BridgedToolobjects (NamespaceMember,DeferredTopLevelTool).namespace_tool_name_mapnow accepts conversation history so shortened names from priorfunction_callitems resolve when tools are not listed again on resume. That single map drives response conversion, logging (record_bridged_tool_names), tool permission guardrails (rules match caller-facing names, not provider-only short names), and spend log tool indexing.Deferred top-level tools are no longer misclassified as namespace members. Client-forged bridged name maps are ignored in favor of values recorded on the logging object.
Reviewed by Cursor Bugbot for commit 0d1f88a. Bugbot is set up for automated code reviews on this repo. Configure here.