Skip to content

fix(anthropic): resolve thinking as disabled when legacy budget is below 1024#101415

Merged
steipete merged 3 commits into
openclaw:mainfrom
Pick-cat:fix/thinking-budget-resolution
Jul 7, 2026
Merged

fix(anthropic): resolve thinking as disabled when legacy budget is below 1024#101415
steipete merged 3 commits into
openclaw:mainfrom
Pick-cat:fix/thinking-budget-resolution

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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_tokens value.

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 enabled budget_tokens to be at least 1,024 and less than max_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

  • Sanitized AWS Crabbox, provider aws, lease cbx_0c68726a976c, run run_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.
  • Sanitized AWS Crabbox, provider aws, lease cbx_0c68726a976c, run run_a3ed7411e93e: pnpm check:changed passed, including all-project tsgo, core/extensions oxlint, guards, and runtime import-cycle checks.
  • Autoreview on the exact fixup patch: clean, no accepted/actionable findings (patch is correct, confidence 0.82).
  • Dependency proof: @anthropic-ai/sdk ThinkingConfigEnabled 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.

…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]>
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 7, 2026
@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 7, 2026, 3:22 AM ET / 07:22 UTC.

Summary
The PR changes Anthropic direct-provider and agent transport thinking-budget resolution so sub-1024 legacy budgets disable or omit thinking, adds regression tests, and adds a root proof script.

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.

  • Ad hoc proof script: 1 added at repository root. The root script is proof evidence rather than integrated test coverage and is the remaining cleanup blocker before merge.

Root-cause cluster
Relationship: canonical
Canonical: #101415
Summary: This PR is the current viable open candidate for the Anthropic legacy thinking budget sub-1024/|| 1024 root cause; earlier similar PRs are closed unmerged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Delete proof-anthropic-thinking-budget.mts while keeping the terminal proof in the PR body or comment.
  • Rerun the focused Anthropic provider and transport tests after the cleanup.

Risk before merge

  • [P1] The provider behavior change is compatibility-sensitive for callers that intentionally pass sub-1024 legacy thinking budgets; the intended outcome is now disabled/omitted thinking instead of inflated or API-rejected enabled thinking.
  • [P1] The branch is behind current main, so exact-head review and checks should refresh before merge.

Maintainer options:

  1. Land guarded behavior after cleanup (recommended)
    Remove the root proof script, keep the after-fix and negative-control proof in the PR evidence, and require focused provider and transport tests before merge.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Remove proof-anthropic-thinking-budget.mts from the branch without changing runtime behavior, then run the focused Anthropic provider and transport tests.

Next step before merge

  • [P2] A narrow automated repair can remove the committed root proof script; the functional provider and transport code should be left unchanged.

Security
Cleared: Cleared: the diff changes provider payload construction/tests and adds a dummy-key proof script, with no lockfile, workflow, dependency, permission, or secret-handling changes.

Review findings

  • [P2] Remove the committed proof script — proof-anthropic-thinking-budget.mts:1-10
Review details

Best 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:

  • [P2] Remove the committed proof script — proof-anthropic-thinking-budget.mts:1-10
    This is still the prior cleanup blocker: the PR now has sufficient terminal proof in the body/comment, but this ad hoc root script is not an integrated test or package surface. Keeping it in the repo adds one-off maintenance noise; move the transcript to PR evidence and delete the file.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7c55ce53e268.

Label changes

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.

Label justifications:

  • P2: This is a normal-priority provider bug fix with limited blast radius and one concrete cleanup blocker remaining.
  • merge-risk: 🚨 compatibility: The PR intentionally changes Anthropic legacy thinking payload behavior for sub-1024 budgets, which can affect existing direct-provider, transport, and bundled-plugin callers.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body and follow-up comment include terminal output from production payload hooks for seven after-fix cases plus a negative control; this is sufficient despite the script needing removal from the repo.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and follow-up comment include terminal output from production payload hooks for seven after-fix cases plus a negative control; this is sufficient despite the script needing removal from the repo.
Evidence reviewed

PR surface:

Source +22, Tests +98, Other +163. Total +283 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 36 14 +22
Tests 2 98 0 +98
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 163 0 +163
Total 5 297 14 +283

Acceptance criteria:

  • [P1] git diff --check.
  • [P1] pnpm test packages/ai/src/providers/anthropic.test.ts src/agents/anthropic-transport-stream.test.ts.

What I checked:

  • Current main source behavior: Current main still forces legacy budget-based Anthropic thinking on after adjustMaxTokensForThinking and passes the adjusted budget through to buildParams. (packages/ai/src/providers/anthropic.ts:1076, 7c55ce53e268)
  • Current main builder behavior: Current main uses options?.thinkingBudgetTokens || 1024 in the budget-based builder path, so explicit 0 is replaced with 1024 and positive sub-minimum budgets can still be emitted. (packages/ai/src/providers/anthropic.ts:1355, 7c55ce53e268)
  • PR direct-provider fix: The PR head resolves sub-1024 adjusted budgets as thinkingEnabled false and guards direct streamAnthropic builder calls with budgetTokens >= 1024 before emitting thinking.enabled. (packages/ai/src/providers/anthropic.ts:1075, 8c7fe0a3ce69)
  • PR transport fix: The PR head applies the same sub-1024 disabled-state rule and builder guard in src/agents/anthropic-transport-stream.ts. (src/agents/anthropic-transport-stream.ts:1191, 8c7fe0a3ce69)
  • Dependency contract: The official Anthropic Messages API reference says enabled thinking requires a minimum budget of 1,024 tokens and budget_tokens must be >=1024 and less than max_tokens.
  • SDK type contract: Anthropic SDK source documents ThinkingConfigEnabled.budget_tokens as required to be >=1024 and less than max_tokens.

Likely related people:

What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-07T06:42:28.738Z sha aa1a4d8 :: needs real behavior proof before merge. :: [P1] Normalize direct stream budgets before preserving zero
  • reviewed 2026-07-07T07:05:03.092Z sha 8c7fe0a :: needs changes before merge. :: [P1] Normalize raw thinking state before the guard | [P2] Remove the committed proof script

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 7, 2026
…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]>
@Pick-cat

Pick-cat commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Pushed 8c7fe0a3ce addressing both P1 rank-up blockers:

1. Builder guards added for raw/bundled-plugin path

Both buildParams budget branches now check budgetTokens >= 1024 before emitting { type: "enabled" }. Protects direct streamAnthropic and bundled-plugin callers (Mantle) that bypass option resolution.

2. Real behavior proof added

proof-anthropic-thinking-budget.mts drives real streamAnthropic and streamSimpleAnthropic production functions, captures payload via onPayload before network. 7 cases:

  • 3 simple-path cases (option resolution): zero/sub-minimum/valid
  • 4 raw-path cases (builder-only): zero/sub-minimum/valid/disabled

After fix: 7 passed, 0 failed. Origin/main negative control: 3 passed, 4 failed.

node --import tsx proof-anthropic-thinking-budget.mts
=== Proof Summary ===
ALL PROOF ASSERTIONS: 7 passed, 0 failed

Vitest: 65 + 102 = 167 passed.

@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@steipete steipete self-assigned this Jul 7, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 7, 2026
@steipete
steipete merged commit e72dadb into openclaw:main Jul 7, 2026
119 of 123 checks passed
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

sheyanmin pushed a commit to sheyanmin/openclaw that referenced this pull request Jul 8, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 8, 2026
…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]>
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: amazon-bedrock extensions: anthropic-vertex merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants