Skip to content

fix(provider): keep tools declared on no-tool-call turns; Bedrock budget-final turns no longer fail - #238

Merged
lg2m merged 2 commits into
mainfrom
fix/eng-1001-tool-choice-none
Oct 5, 2026
Merged

lg2m merged 2 commits into
mainfrom
fix/eng-1001-tool-choice-none

Conversation

@lg2m

@lg2m lg2m commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

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.

main fails a bedrock/ run after any tool call once it hits its turn, tool-call, cost or token budget:

error: provider response failed: ValidationException: The toolConfig field must be defined when using toolUse and toolResult content blocks.

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.".

Build Claude Haiku 4.5 Nova Micro
main failed (the error above) failed (the same error)
this PR final answer, then budget_exhausted final answer, then budget_exhausted

Design

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 toolUse or toolResult blocks.

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 } on ModelRequest:

Codec ToolChoice::None on the wire
OpenAI Responses (standard and Codex) tool_choice: "none"
OpenAI Chat Completions tool_choice: "none"
Anthropic Messages tool_choice: {"type": "none"}
Gemini toolConfig.functionCallingConfig.mode: "NONE"
Bedrock Converse tools sent unchanged; Converse toolChoice has only auto, any and tool
  • The choice is advice, not the bound. A call made anyway still settles the run as budget_exhausted (final_response: false) without running. This PR adds the test for that path, since on Bedrock it is the only guard.
  • No change for other requests. Auto (the default), and None with no declared tools, leave every wire body byte-identical, which the tests check per codec.
  • Better caching. The tool block, and on Anthropic its cache breakpoint, are now identical on the final turn, so the tools' cache entry survives. The system text still differs (the budget-final notice), as before.
  • Better estimates. Tool-schema bytes now count on the final turn, because the tools really are sent.
  • No provider branching in core. Core sets the choice; each codec maps it.

AP3b's child final-answer turn (ADR-0054 § 3) will use the same mechanism, plus "the turn settles whatever it returns".

Verification

  • Codec tests per adapter: each checks the None shape, and that Auto and no-tools add no key. The Bedrock test checks the tool configuration is identical under None and Auto.
  • Budget tests: budget-final requests keep the turn-1 tools and use ToolChoice::None.
  • New test: a_tool_call_on_the_budget_final_turn_settles_without_running. It checks the call never starts or commits, and the outcome is budget_exhausted with final_response = false.
  • Checks:
    • cargo test --workspace: 2035 passed;
    • the minimal profile (qq-provider --no-default-features --features test-support): 210 passed;
    • clippy (--all-targets --all-features -D warnings) and fmt are clean.
  • Live: both Bedrock models above, run before and after.
  • Benchmarks:
    • turn_overhead is 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:

      • adding the unused ModelRequest field alone: no change;
      • changing model.rs alone: no change;
      • changing only the OpenAI Chat file, which the Anthropic encoder never calls: the same +7%;
      • adding one #[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:

  1. Test the path where the model calls a tool anyway: added.
  2. Compaction summarizers have the same Bedrock bug. I verified that live: a summary request with tool history and no tools gets the same 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: none together 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

  • No protocol, descriptor or store change.
  • The qq-provider public API gains ToolChoice, ModelRequest::with_tool_choice and ModelRequest::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

flowchart LR
  A["Budget reached after tool history"] --> B["Keep declared tools; request ToolChoice None"]
  B --> C["Provider codec compiles final request"]
  C --> D["Final reply or model tool call"]
  D --> E["Settle budget; execute no new tool"]
Loading

lg2m added 2 commits October 1, 2026 23:47
…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
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@integrate-your-mind integrate-your-mind left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lg2m
lg2m merged commit 378724a into main Oct 5, 2026
4 checks passed
@lg2m
lg2m deleted the fix/eng-1001-tool-choice-none branch October 5, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants