fix(anthropic): resolve thinking as disabled when legacy budget is below 1024#101415
Conversation
…low 1024 When adjustMaxTokensForThinking collapses the thinking budget below the Anthropic minimum (1024), option resolution now sets thinkingEnabled to false instead of always forcing it to true. This keeps every downstream consumer (payload, replay, temperature, tool-choice) consistent — they all see the same disabled state instead of an enabled flag with a missing or API-rejected thinking block. || → ?? in both builders is defensive: the resolution layer already prevents invalid budgets from reaching the builder through the normal path, but ?? preserves an explicit zero when the builder is called directly. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Codex review: needs changes before merge. Reviewed July 7, 2026, 3:22 AM ET / 07:22 UTC. Summary PR surface: Source +22, Tests +98, Other +163. Total +283 across 5 files. Reproducibility: yes. at source level: current main forces thinkingEnabled true and uses the || 1024 fallback in the legacy budget path, while the Anthropic contract requires enabled budget_tokens to be at least 1024. I did not execute the proof script in this read-only review. Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: The durable end state is the paired provider and transport guard with regression tests, while proof evidence stays in PR discussion rather than an ad hoc root script. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main forces thinkingEnabled true and uses the || 1024 fallback in the legacy budget path, while the Anthropic contract requires enabled budget_tokens to be at least 1024. I did not execute the proof script in this read-only review. Is this the best way to solve the issue? Yes for the runtime fix: normalizing option resolution plus guarding both builders covers the simple, transport, and raw direct-call paths. The committed root proof script is not part of the best solution and should be removed. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7c55ce53e268. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +22, Tests +98, Other +163. Total +283 across 5 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (2 earlier review cycles)
|
…nimum budgets
Add budget guards in both Anthropic payload builders so direct
streamAnthropic and bundled-plugin callers (e.g. Mantle) that bypass
option resolution also get the disabled-state rule instead of producing
API-rejected { type: "enabled", budget_tokens: < 1024 } requests.
Add proof-anthropic-thinking-budget.mts driving real production
functions with terminal output and negative control.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
@clawsweeper re-review Pushed 1. Builder guards added for raw/bundled-plugin path Both 2. Real behavior proof added
After fix: 7 passed, 0 failed. Origin/main negative control: 3 passed, 4 failed. Vitest: 65 + 102 = 167 passed. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Co-authored-by: Pick-cat <[email protected]>
|
Merged via squash.
|
…low 1024 (openclaw#101415) * fix(anthropic): resolve thinking as disabled when legacy budget is below 1024 When adjustMaxTokensForThinking collapses the thinking budget below the Anthropic minimum (1024), option resolution now sets thinkingEnabled to false instead of always forcing it to true. This keeps every downstream consumer (payload, replay, temperature, tool-choice) consistent — they all see the same disabled state instead of an enabled flag with a missing or API-rejected thinking block. || → ?? in both builders is defensive: the resolution layer already prevents invalid budgets from reaching the builder through the normal path, but ?? preserves an explicit zero when the builder is called directly. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(anthropic): guard raw streamAnthropic builder path against sub-minimum budgets Add budget guards in both Anthropic payload builders so direct streamAnthropic and bundled-plugin callers (e.g. Mantle) that bypass option resolution also get the disabled-state rule instead of producing API-rejected { type: "enabled", budget_tokens: < 1024 } requests. Add proof-anthropic-thinking-budget.mts driving real production functions with terminal output and negative control. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(anthropic): normalize legacy thinking budgets Co-authored-by: Pick-cat <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
…low 1024 (openclaw#101415) * fix(anthropic): resolve thinking as disabled when legacy budget is below 1024 When adjustMaxTokensForThinking collapses the thinking budget below the Anthropic minimum (1024), option resolution now sets thinkingEnabled to false instead of always forcing it to true. This keeps every downstream consumer (payload, replay, temperature, tool-choice) consistent — they all see the same disabled state instead of an enabled flag with a missing or API-rejected thinking block. || → ?? in both builders is defensive: the resolution layer already prevents invalid budgets from reaching the builder through the normal path, but ?? preserves an explicit zero when the builder is called directly. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(anthropic): guard raw streamAnthropic builder path against sub-minimum budgets Add budget guards in both Anthropic payload builders so direct streamAnthropic and bundled-plugin callers (e.g. Mantle) that bypass option resolution also get the disabled-state rule instead of producing API-rejected { type: "enabled", budget_tokens: < 1024 } requests. Add proof-anthropic-thinking-budget.mts driving real production functions with terminal output and negative control. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(anthropic): normalize legacy thinking budgets Co-authored-by: Pick-cat <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
…low 1024 (openclaw#101415) * fix(anthropic): resolve thinking as disabled when legacy budget is below 1024 When adjustMaxTokensForThinking collapses the thinking budget below the Anthropic minimum (1024), option resolution now sets thinkingEnabled to false instead of always forcing it to true. This keeps every downstream consumer (payload, replay, temperature, tool-choice) consistent — they all see the same disabled state instead of an enabled flag with a missing or API-rejected thinking block. || → ?? in both builders is defensive: the resolution layer already prevents invalid budgets from reaching the builder through the normal path, but ?? preserves an explicit zero when the builder is called directly. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(anthropic): guard raw streamAnthropic builder path against sub-minimum budgets Add budget guards in both Anthropic payload builders so direct streamAnthropic and bundled-plugin callers (e.g. Mantle) that bypass option resolution also get the disabled-state rule instead of producing API-rejected { type: "enabled", budget_tokens: < 1024 } requests. Add proof-anthropic-thinking-budget.mts driving real production functions with terminal output and negative control. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(anthropic): normalize legacy thinking budgets Co-authored-by: Pick-cat <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Legacy/manual Anthropic thinking budgets can collapse below the API minimum when a model or caller token cap cannot fit the selected reasoning budget. The old path still marked thinking enabled, producing either a silently inflated default or an API-invalid
budget_tokensvalue.This affected the direct Anthropic provider, the agent transport, and sibling Anthropic-compatible owners in Bedrock Converse, Bedrock Mantle, and Vertex.
Why This Change Was Made
The pinned
@anthropic-ai/[email protected]contract requires enabledbudget_tokensto be at least 1,024 and less thanmax_tokens; the official Anthropic and AWS Bedrock documentation states the same minimum.The fix now resolves an invalid manual budget to one closed disabled state before replay, sampling, tool-choice, headers, and payload construction. Simple and transport option resolution apply the same rule, and the Bedrock, Mantle, and Vertex sibling paths no longer forward sub-minimum manual budgets. Adaptive-thinking models remain unchanged.
User Impact
Requests whose token cap cannot fit the selected manual reasoning budget now continue with thinking disabled instead of failing Anthropic-compatible API validation. Valid manual budgets and adaptive-thinking requests retain their existing behavior.
Evidence
aws, leasecbx_0c68726a976c, runrun_6cb2a9667997: 67 direct-provider tests, 102 transport tests, and 76 Bedrock/Mantle/Vertex tests passed (245 total) on the reviewed PR head plus maintainer fixup.aws, leasecbx_0c68726a976c, runrun_a3ed7411e93e:pnpm check:changedpassed, including all-project tsgo, core/extensions oxlint, guards, and runtime import-cycle checks.patch is correct, confidence 0.82).@anthropic-ai/sdkThinkingConfigEnabled and Anthropic extended thinking docs; AWS Bedrock extended thinking docs.Fixes the sub-minimum manual thinking-budget request failure while preserving contributor credit for @Pick-cat.