Repository navigation
fix(provider): keep tools declared on no-tool-call turns; Bedrock budget-final turns no longer fail - #238
Merged
Conversation
…get-final turns no longer fail
On native Bedrock, a budget-final turn after any tool call failed with
"The toolConfig field must be defined when using toolUse and toolResult
content blocks": the run loop dropped the tools to ask for a text-only
answer, and Converse requires them once history holds tool blocks. A
bedrock/ run that ran out of budget ended `failed` instead of answering.
Add a provider-neutral `ToolChoice { Auto, None }` to `ModelRequest`. The
budget-final turn keeps its tools and asks for none:
- OpenAI Responses / Chat send `tool_choice: "none"`;
- Anthropic sends `tool_choice: {type: "none"}`;
- Gemini sends `toolConfig.functionCallingConfig.mode: NONE`;
- Bedrock Converse has no "none" choice and sends the tools unchanged.
The choice is advice: a call made anyway still settles the run as
budget_exhausted without running. `Auto`, and `None` with no tools,
leave every wire body byte-identical. The tool block and its cache
breakpoint are unchanged on the final turn, so the cached prefix survives.
Verified live on bedrock/ Claude Haiku 4.5 and Nova Micro with
`qq run --max-turns 2`: main fails at turn 2; this answers and settles
budget_exhausted.
Linear: ENG-1001
…unning Review follow-up (ENG-1001): Bedrock Converse cannot ask for no tool calls, so the existing settle path is now the only guard there. Pins it: the call never runs or commits, and the run settles budget_exhausted with final_response = false. Comments no longer call the turn tool-free. Linear: ENG-1001
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Oct 2, 2026
Merged
integrate-your-mind
approved these changes
Oct 5, 2026
integrate-your-mind
left a comment
Collaborator
There was a problem hiding this comment.
Approving. Budget-final turns keep the tool list and set tool choice to none, CI is green, and there is no protocol or store version change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: ENG-1001 · first PR of a two-PR stack; AP3b (ENG-1000) stacks on it.
What changes for users
On native
bedrock/, a run that runs out of budget now gives its final answer instead of failing.mainfails abedrock/run after any tool call once it hits its turn, tool-call, cost or token budget:Reproduced live on 2026-10-01 with
qq run --model bedrock/<model> --max-turns 2 "Read a.txt with read_file, then read it again with read_file, then tell me what it says.".mainfailed(the error above)failed(the same error)budget_exhaustedbudget_exhaustedDesign
The cause: to get a text-only final answer, the run loop removed the tools from the request. Converse requires a tool configuration whenever history holds
toolUseortoolResultblocks.The fix is to keep the tools declared and ask the model not to use them, through a new provider-neutral
qq_provider::ToolChoice { Auto, None }onModelRequest:ToolChoice::Noneon the wiretool_choice: "none"tool_choice: "none"tool_choice: {"type": "none"}toolConfig.functionCallingConfig.mode: "NONE"toolChoicehas onlyauto,anyandtoolbudget_exhausted(final_response: false) without running. This PR adds the test for that path, since on Bedrock it is the only guard.Auto(the default), andNonewith no declared tools, leave every wire body byte-identical, which the tests check per codec.AP3b's child final-answer turn (ADR-0054 § 3) will use the same mechanism, plus "the turn settles whatever it returns".
Verification
Noneshape, and thatAutoand no-tools add no key. The Bedrock test checks the tool configuration is identical underNoneandAuto.ToolChoice::None.a_tool_call_on_the_budget_final_turn_settles_without_running. It checks the call never starts or commits, and the outcome isbudget_exhaustedwithfinal_response = false.cargo test --workspace: 2035 passed;qq-provider --no-default-features --features test-support): 210 passed;--all-targets --all-features -D warnings) and fmt are clean.turn_overheadis within noise (medians 15.3 / 15.0 ms after against 15.3 / 15.3 ms before at 10 and 100 turns).provider_encode(1.1 MB request): Responses, Chat and Gemini are within noise. Anthropic encode is about 7% slower (≈1 900 → ≈2 040 µs) in isolated A/B runs, but I traced that to code layout, not this change:ModelRequestfield alone: no change;model.rsalone: no change;#[inline(never)]to an unrelated OpenAI Chat function: the same +7%.The body bytes and heap peak are identical. So this is a code-layout or inlining shift in the release build, not work this PR adds; Anthropic encode does no extra work for
Auto.Review
An independent read-only review approved this. Its should-fixes:
ValidationException, and declaring any tool fixes it. Filed as ENG-1002; it is a different code path with its own fix.Comment nits are fixed. The reviewer checked that Anthropic allows
tool_choice: nonetogether with thinking and effort.Residual risk: LiteLLM proxies routing to Bedrock may translate
tool_choice: "none"by dropping the tools. That is unverified, because I have no gateway key in this environment. A gateway that drops them would bring back this exact error on that route.Compatibility
qq-providerpublic API gainsToolChoice,ModelRequest::with_tool_choiceandModelRequest::tool_choice.Retained live evidence — 2026-10-04
The earlier live results above are the original author's report. This readiness pass found no raw provider request/response or session receipt in the PR comments, associated Linear issue attachments/comments, or the plan ledger; they have not been independently reproduced. No paid provider call or new Devin session was made. LiteLLM translation to Bedrock remains unverified.
Feature flow