Skip to content

fix: honor Bedrock adaptive max token caps - #97248

Closed
yungchentang wants to merge 1 commit into
openclaw:mainfrom
yungchentang:codex/bedrock-adaptive-max-tokens
Closed

yungchentang wants to merge 1 commit into
openclaw:mainfrom
yungchentang:codex/bedrock-adaptive-max-tokens

Conversation

@yungchentang

Copy link
Copy Markdown
Contributor

Closes #97176

AI-assisted with Codex.

What Problem This Solves

Fixes an issue where users running Bedrock Claude Fable or adaptive-thinking Claude models could have Converse requests capped at the core default 4096 output tokens when the resolved model metadata had a larger maxTokens cap. At higher thinking effort, the thinking block could consume that whole budget and end the turn at length before a visible answer or tool call.

Why This Change Was Made

Bedrock simple-option resolution now carries the model-backed maxTokens into Fable, mandatory adaptive, and explicit adaptive-thinking requests when the caller did not set maxTokens. Explicit caller maxTokens remains the override path, and the existing adaptive thinking payload and temperature behavior are preserved.

User Impact

Bedrock adaptive-thinking Claude requests can use the configured model/catalog output-token cap instead of silently falling back to 4096, reducing length-truncated turns for long or high-thinking generations.

Evidence

  • Red test first: node scripts/run-vitest.mjs extensions/amazon-bedrock/stream.runtime.test.ts failed before the fix with 4 assertions showing inferenceConfig: {} instead of model-backed maxTokens.
  • env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1 PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false pnpm check:changed -- extensions/amazon-bedrock/stream.runtime.ts extensions/amazon-bedrock/stream.runtime.test.ts
  • node scripts/run-vitest.mjs extensions/amazon-bedrock/stream.runtime.test.ts extensions/amazon-bedrock/discovery.test.ts (2 files, 44 tests passed)
  • pnpm test:extension amazon-bedrock (11 files, 172 tests passed)
  • pnpm format:check -- extensions/amazon-bedrock/stream.runtime.ts extensions/amazon-bedrock/stream.runtime.test.ts
  • git diff --check

@clawsweeper

clawsweeper Bot commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 27, 2026, 9:06 AM ET / 13:06 UTC.

Summary
The branch changes Amazon Bedrock simple option resolution and tests so Fable, mandatory adaptive, and explicit adaptive-thinking Claude requests use model-backed maxTokens unless the caller set maxTokens.

PR surface: Source +13, Tests +77. Total +90 across 2 files.

Reproducibility: yes. source-reproducible: current main only sends Bedrock inferenceConfig.maxTokens from resolved options, and the Fable/adaptive branches do not derive that value from model.maxTokens. I did not run a live AWS Bedrock request in this read-only review.

Review metrics: 1 noteworthy metric.

  • Provider request cap branches: 3 changed. Fable, mandatory adaptive, and explicit adaptive-thinking simple-option branches now populate maxTokens from model metadata, which matters for truncation and Bedrock quota behavior.

Stored data model
Persistent data-model change detected: vector/embedding metadata: extensions/amazon-bedrock/stream.runtime.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #97176
Summary: This PR is a candidate fix for the canonical Bedrock adaptive-thinking maxTokens bug; a second open candidate exists but is not merged or proof-positive enough to supersede this one.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body lists source-level and mocked SDK/test evidence, but no redacted live Bedrock payload, runtime log, terminal output, recording, or linked artifact shows the after-fix provider request; redact private details and update the PR body to trigger re-review.

Risk before merge

  • [P1] No redacted live Bedrock payload, runtime log, terminal output, recording, or linked artifact shows AWS accepting an after-fix adaptive/Fable request with the raised inferenceConfig.maxTokens.
  • [P1] Merging raises maxTokens sent for existing Bedrock adaptive/Fable simple-stream requests when callers omit maxTokens, which fixes truncation but can change provider quota reservation or cost behavior.
  • [P1] Another open candidate PR targets the same canonical issue; maintainers should choose one fix shape rather than land both.

Maintainer options:

  1. Add Bedrock proof before merge (recommended)
    Attach a redacted after-fix Bedrock payload, runtime log, terminal output, or linked artifact showing adaptive thinking fields and the raised inferenceConfig.maxTokens on a real request.
  2. Accept source-level provider proof
    A maintainer can intentionally accept the source path, mocked SDK assertions, AWS SDK contract, and the linked issue's direct Bedrock evidence if live credentials are unavailable.
  3. Pause and pick one branch
    Hold this PR until maintainers decide whether this branch or fix(bedrock): apply model maxTokens to adaptive-thinking and Fable 5 requests #97182 should be the single landing candidate.

Next step before merge

  • [P1] Human review is needed for the external proof gate, compatibility acceptance, and choosing between the two open candidate PRs.

Security
Cleared: The diff only changes Bedrock runtime option construction and tests, with no dependency, CI, credential, package, or script surface change.

Review details

Best possible solution:

Land one focused Bedrock runtime fix after redacted real Bedrock proof or explicit maintainer acceptance of the quota/cost behavior change.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main only sends Bedrock inferenceConfig.maxTokens from resolved options, and the Fable/adaptive branches do not derive that value from model.maxTokens. I did not run a live AWS Bedrock request in this read-only review.

Is this the best way to solve the issue?

Yes, this is a narrow maintainable fix shape because it reuses the Bedrock provider's simple option resolver and avoids adding a new config surface. The remaining question is proof and maintainer acceptance of the larger default request cap.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority provider runtime bugfix with clear source evidence and a blast radius limited to Bedrock adaptive-thinking Claude requests.
  • merge-risk: 🚨 compatibility: The PR changes the maxTokens sent for existing Bedrock adaptive/Fable simple-stream requests, which can affect provider quota reservation or cost behavior on upgrade.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists source-level and mocked SDK/test evidence, but no redacted live Bedrock payload, runtime log, terminal output, recording, or linked artifact shows the after-fix provider request; redact private details and update the PR body to trigger re-review.
Evidence reviewed

PR surface:

Source +13, Tests +77. Total +90 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 0 +13
Tests 1 78 1 +77
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 91 1 +90

What I checked:

Likely related people:

  • steipete: Authored and merged the Opus 4.8 and Fable 5 adaptive-thinking PRs that changed the Bedrock stream, discovery, and thinking-policy surfaces involved here. (role: recent feature contributor and merger; confidence: high; commits: 1188aa3b81ef, 0e7b5c34292c; files: extensions/amazon-bedrock/stream.runtime.ts, extensions/amazon-bedrock/discovery.ts, extensions/amazon-bedrock/thinking-policy.ts)
  • vincentkoc: Recently changed adjacent Bedrock adaptive-thinking request shaping and discovery paths that feed model metadata and request policy. (role: recent area contributor and merger; confidence: high; commits: d6081f99ff42, 6b0f718b9a4b, fdf1ec9f5cf8; files: extensions/amazon-bedrock/stream.runtime.ts, extensions/amazon-bedrock/discovery.ts, extensions/amazon-bedrock/thinking-policy.ts)
  • wirjo: Authored Bedrock inference-profile discovery and known context-window discovery changes adjacent to the model metadata used by this fix path. (role: adjacent discovery contributor; confidence: medium; commits: 78fe96f2d4c7, 2a15a3bb53f9; files: extensions/amazon-bedrock/discovery.ts, extensions/amazon-bedrock/discovery.test.ts)
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.

@yungchentang
yungchentang marked this pull request as ready for review June 27, 2026 13:06
@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. labels Jun 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer note: closing this as superseded by #97343, which landed the canonical fix for #97176 in merge commit a083c76. Thanks for working on the same Bedrock adaptive maxTokens issue; the merged branch was the cleanest ready candidate with proof and focused tests.

@vincentkoc vincentkoc closed this Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: amazon-bedrock merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bedrock adaptive-thinking models hard-capped at 4096 output tokens; model maxTokens ignored, no config override

2 participants