Skip to content

fix(bedrock): honor adaptive model max tokens - #97343

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
LiLan0125:fix/97176-bedrock-adaptive-max-tokens
Jun 28, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
LiLan0125:fix/97176-bedrock-adaptive-max-tokens

Conversation

@LiLan0125

Copy link
Copy Markdown
Contributor

Summary

  • Bedrock adaptive-thinking request shaping now uses the configured model maxTokens when no per-request cap is supplied.
  • Explicit request maxTokens still wins over the model-level value.
  • Known OpenClaw fallback caps stay omitted for adaptive requests so Bedrock native defaults remain available.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security
  • Chore

Scope

  • Gateway
  • Skills
  • Auth
  • Memory
  • Integrations
  • API
  • UI/UX
  • CI

Verification

  • node scripts/run-vitest.mjs extensions/amazon-bedrock/stream.runtime.test.ts -> passed 1 Vitest shard in 12.80s.
  • node scripts/run-vitest.mjs extensions/amazon-bedrock/discovery.test.ts -> passed 1 Vitest shard in 22.64s.
  • git diff --check -> passed.

Real behavior proof

Behavior addressed: Bedrock adaptive-thinking options now carry configured high output-token caps while leaving fallback caps unset.

Environment tested: Node runtime on Linux in the local fix/97176-bedrock-adaptive-max-tokens branch.

Steps run after the patch: Ran a node --import tsx --no-warnings -e command that imports testing from ./extensions/amazon-bedrock/stream.runtime.ts and calls resolveSimpleBedrockOptions plus buildAdditionalModelRequestFields with configured, explicit, and fallback max-token cases.

Evidence after fix:

{
  "configuredAdaptiveMaxTokens": 128000,
  "configuredAdaptiveReasoning": "high",
  "explicitMaxTokens": 32000,
  "discoveryFallback4096MaxTokensValue": null,
  "normalizedFallback8192MaxTokensValue": null,
  "registryFallback16384MaxTokensValue": null,
  "additionalFields": {
    "thinking": {
      "type": "adaptive",
      "display": "summarized"
    },
    "output_config": {
      "effort": "high"
    }
  }
}

Observed result: The configured model cap resolves to 128000, the explicit request cap remains 32000, fallback caps 4096, 8192, and 16384 remain unset, and adaptive request fields are still produced.

Not tested: Live AWS Bedrock request with real credentials was not run.

Impact Assessment

  • Scope: Bedrock stream runtime option resolution and its regression tests only.
  • Downstream: The shared simple Bedrock options helper feeds Fable, mandatory adaptive, and adaptive request branches; non-adaptive request paths are unchanged.
  • Edge cases: absent request cap, explicit request cap, configured high model cap, and fallback model caps were covered.
  • Hard-coded values: the fix uses configured/runtime caps and preserves caller caps; only existing OpenClaw fallback cap values are excluded from becoming explicit Bedrock request caps.
  • Existing fixes: no competing open PR was found for #97176 before implementation.
  • Import paths: no new imports were added.

Root Cause

  • Root cause: Bedrock adaptive request options relied on request-level maxTokens, so configured model-level output caps were not forwarded when callers omitted a per-request cap.
  • Missing guardrail: Regression coverage did not cover configured adaptive output caps or fallback caps.

Regression Test Plan

  • Added focused stream runtime tests for configured adaptive caps, explicit request caps, fallback caps, mandatory adaptive behavior, and Fable defaults.
  • Re-ran the Bedrock discovery tests to verify discovery fallback behavior stayed unchanged.

User-visible / Behavior Changes

Users with Bedrock adaptive-thinking models and configured high maxTokens values can receive the intended response budget without adding a per-request override. OpenClaw fallback caps are still left to Bedrock defaults instead of reducing native capacity.

Security Impact

  • New permissions? No
  • Secrets handling changed? No
  • New network calls? No

Closes #97176

@clawsweeper

clawsweeper Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 27, 2026, 9:53 PM ET / 01:53 UTC.

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

PR surface: Source +19, Tests +62. Total +81 across 2 files.

Reproducibility: yes. at source level: 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 paths: 3 branches changed. The changed Fable, mandatory adaptive, and explicit adaptive-thinking branches decide whether existing Bedrock requests send a model-backed output cap, which matters for truncation, quota, and cost behavior.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #97176
Summary: This PR is a candidate fix for the canonical Bedrock adaptive-thinking maxTokens issue; several older open PRs target the same root cause but are not merged.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

Risk before merge

  • [P1] Merging raises maxTokens sent for existing Bedrock adaptive/Fable requests when model metadata carries a high cap, which can affect Bedrock quota reservation or cost behavior.
  • [P1] Several open PRs target the same canonical issue, so maintainers should pick one landing branch and close or supersede the rest.
  • [P1] Two broad CI checks and the real-behavior-proof check were still pending in the latest gh pr checks output; that is not a patch defect but still needs normal merge gating.

Maintainer options:

  1. Land one canonical branch (recommended)
    Treat this PR as the landing candidate if CI remains green and maintainers accept the changed Bedrock maxTokens quota behavior.
  2. Request live Bedrock proof
    Ask for a redacted after-fix Bedrock request, runtime log, or terminal output showing adaptive fields and raised inferenceConfig.maxTokens before merge.
  3. Pause duplicate candidates
    Hold or close overlapping PRs once maintainers choose the single canonical fix for [Bug]: Bedrock adaptive-thinking models hard-capped at 4096 output tokens; model maxTokens ignored, no config override #97176.

Next step before merge

  • [P2] Human review should choose the canonical landing branch and accept the Bedrock quota/cost behavior; there is no narrow automated repair left from this review.

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

Review details

Best possible solution:

Land one focused Bedrock runtime fix, likely this branch if CI finishes cleanly and maintainers accept the source-level/terminal proof plus the Bedrock quota behavior, then close overlapping candidate PRs once the canonical fix lands.

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

Yes, at source level: 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 the best fix shape among the candidates inspected: it stays inside the Bedrock simple option resolver, preserves explicit request caps, and avoids turning known synthetic fallback caps into explicit Bedrock request caps.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority provider runtime bugfix with a clear source path and blast radius limited to Bedrock adaptive-thinking Claude requests.
  • merge-risk: 🚨 compatibility: The PR changes maxTokens sent for existing Bedrock adaptive/Fable requests when callers omit maxTokens, which can affect provider quota reservation or cost behavior on upgrade.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output from a Node runtime probe of the Bedrock option resolver showing configured, explicit, fallback, and adaptive-field cases; it is not a live AWS smoke.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from a Node runtime probe of the Bedrock option resolver showing configured, explicit, fallback, and adaptive-field cases; it is not a live AWS smoke.
Evidence reviewed

PR surface:

Source +19, Tests +62. Total +81 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 19 0 +19
Tests 1 62 0 +62
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 81 0 +81

What I checked:

Likely related people:

  • steipete: Authored and merged recent Opus 4.8 and Fable adaptive-thinking PRs that touched the Bedrock stream, discovery, and thinking-policy paths involved here. (role: recent feature contributor; confidence: high; commits: 1188aa3b81ef, 0e7b5c34292c; files: extensions/amazon-bedrock/stream.runtime.ts, extensions/amazon-bedrock/discovery.ts, extensions/amazon-bedrock/thinking-policy.ts)
  • Vincent Koc: Recently changed adjacent Bedrock optional/adaptive thinking request shaping and discovery behavior that feeds this option resolver. (role: recent area contributor; 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 and context-window discovery work adjacent to the model metadata used by this maxTokens 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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 28, 2026
@vincentkoc
vincentkoc merged commit a083c76 into openclaw:main Jun 28, 2026
138 of 145 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Jul 4, 2026
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Jul 8, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

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