fix: hide gateway calls on terminal Messages rounds #346
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.47) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 498 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.372
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #346"
general
weight: 0.35
franciscojavierarceo
Summary
A
/v1/messagesgateway round can end while a gateway-ownedtool_useis still present. That happens whenever the stop reason is not a tool-call stop: amax_tokenstruncation mid-call, or anend_turnthe request context does not accept as a tool stop. The call is correctly not executed, but the loop returned the message unchanged, so the client received atool_usefor a tool it had declared for the gateway to run. A nativeweb_search_20250305declaration is rewritten into an ordinary function tool for upstream, so the surfaced call names a tool the client never agreed to execute.The streaming accumulator suppresses gateway blocks on every round, so the two transports disagreed on the same upstream turn:
| Upstream turn |
stream: falseonmain|stream: trueonmain|| --- | --- | --- |
| text +
web_searchtool_use,stop_reason: max_tokens|tool_usesurfaces | suppressed |strip_gateway_tool_usealready exists for this contract ("the client never sees a call it cannot execute"), but the loop applied it only on a round that also carried a client call. This moves it intodeliver, the terminal return for every assistant message, so hide-the-call holds on every terminal round. It is also what the Anthropic contract promises for a server tool: the API "executes the tool internally and incorporates the results directly into its response without requiring additional user interaction".Behavior notes:
pause_turncontinuation stays open (Open Q1inmessages_loop.rs). Anthropic resumes a paused turn by resending the response with its pendingserver_tool_useblock; the gateway has no client-facing representation of a pending hidden call on either transport, and a resent client-facingtool_usewith no result would not have resumed it either. This PR only stops the message from advertising a call the client cannot run.Related: #314 (equivalent behavior across execution paths), #313 (one public Messages lifecycle).
Test Plan
Red on unmodified
main(747cb62), green with this change, using a separate worktree with only the test files applied:messages_loop_hides_a_gateway_call_on_a_terminal_rounddrives a truncated round carrying text plus aweb_searchcall overmax_tokens,stop_sequence,pause_turn,refusal, and an unknown future stop reason. Onmainit fails with the call surfaced; it also asserts the visible text, the terminal reason, and usage are unchanged.messages_loop_hides_an_unexecuted_gateway_call_labelled_end_turncovers anend_turnthe request context does not accept as a tool stop (vLLM's labelling of a named call, here withtool_choiceunset), where the loop declines to execute the call. Onmainthe call surfaces as the only content block.messages_stream_hides_a_gateway_call_on_a_terminal_roundis the streaming parity test for the same upstream turn. It passes onmainand locks that behavior against regression.repro_f5), the model-facing history that must keep the call (repro_f3), and the tool-choice and Dynamo/vLLM cassette replays.pre-commit run --all-files(includingrust-file-sizeswithRUST_FILE_SIZE_BASE=origin/main),cargo fmt -- --check,cargo clippy --all-targets -- -D warnings, andcargo test --no-fail-fastacross the workspace pass on the exact commit from a clean worktree.