Skip to content

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

Closed

Description

@prasithg

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

For Amazon Bedrock Claude models that use adaptive thinking (e.g. us.anthropic.claude-opus-4-8), every request is capped at 4096 output tokens regardless of the model's configured maxTokens, and no configuration raises it; at higher thinking effort the extended-thinking block alone consumes the 4096-token budget, so the turn ends with stop_reason: "length" before emitting any answer or tool call.

Steps to reproduce

  1. Configure an agent with amazon-bedrock/us.anthropic.claude-opus-4-8 and thinking level high.
  2. Send a prompt that needs more than 4096 output tokens in one generation, e.g. Output the integers from 1 to 2000, one per line. No other text. (or any reasoning-heavy synthesis where extended thinking exceeds ~4096 tokens).
  3. The turn fails with no deliverable content.

Expected behavior

The Bedrock Converse request's inferenceConfig.maxTokens is derived from the model's resolved maxTokens (or an agent-level output-token setting) for adaptive-thinking models too, leaving budget for thinking plus the answer, instead of defaulting to 4096. This matches the non-adaptive Claude branch (which already factors model.maxTokens via adjustMaxTokensForThinking) and the Anthropic-direct transport (which honors model.maxTokens).

Actual behavior

inferenceConfig.maxTokens is the core default 4096 for adaptive-thinking models, and nothing the user configures changes it. The run ends with stopReason: "length" and only a (truncated) thinking block; the UI surfaces "Agent couldn't generate a response."

OpenClaw version

2026.6.10 (aa69b12)

Operating system

macOS 26.5.1 (Darwin 25.5.0, arm64)

Install method

npm global (/opt/homebrew/lib/node_modules/openclaw)

Model

amazon-bedrock/us.anthropic.claude-opus-4-8 (api: bedrock-converse-stream, thinking level high, contextWindow 1000000, configured maxTokens 128000)

Provider / routing chain

openclaw -> amazon-bedrock (bedrock-converse-stream, region us-east-1)

Additional provider/model setup details

The static catalog entry in ~/.openclaw/openclaw.json under models.providers.amazon-bedrock.models[] sets maxTokens: 128000 and contextWindow: 1000000 for us.anthropic.claude-opus-4-8. That value is retained in the model catalog but ignored on the adaptive-thinking request path (see root cause in evidence).

Logs, screenshots, and evidence

# Root cause, traced through the published dist (@openclaw/amazon-bedrock-provider@2026.6.10).
# Three things combine; #3 is the actual blocker:

# 1. discovery.js — resolveKnownMaxTokens(modelId) returns 128000 ONLY for Claude Fable 5;
#    every other model (including opus-4-8) returns undefined and falls back to
#    DEFAULT_MAX_TOKENS = 4096.

# 2. discovery-shared.js — mergeImplicitBedrockProvider keeps a user static models[] array,
#    so a configured maxTokens (128000) IS retained in the catalog (so #1 alone is not the blocker).

# 3. stream.runtime.js — in resolveSimpleBedrockOptions, when supportsAdaptiveThinking(model) is
#    true (opus-4-8) the builder returns `base` unchanged and NEVER applies model.maxTokens.
#    The non-adaptive Claude branch DOES, via adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, ...).
#    The request is then built as inferenceConfig.maxTokens = options.maxTokens = base.maxTokens,
#    and core buildBaseOptions sets maxTokens = options?.maxTokens (the core default ~4096),
#    NOT model.maxTokens. No zod config key feeds this path, so the cap is effectively unconfigurable.
#    The Claude Fable 5 contract branch has the same defect.

# Live evidence: session trajectories show
#   terminalError: non_deliverable_terminal_turn
#   lastCallUsage.output: 4096
# and the final assistant message has stopReason: "length" containing only a truncated thinking block
# (17 such truncations observed in a single session).

# Proof this is a wiring gap, not a Bedrock limit — a direct Bedrock Converse call accepts a far larger cap
# for the same model (also verified at maxTokens=64000 and 96000):
aws bedrock-runtime converse \
  --region us-east-1 \
  --model-id us.anthropic.claude-opus-4-8 \
  --messages '[{"role":"user","content":[{"text":"reply OK"}]}]' \
  --inference-config maxTokens=128000          # returns 200 OK

Impact and severity

  • Affected: any agent using a Bedrock adaptive-thinking Claude model; opus-4-8 is a common default.
  • Severity: High for agentic + long-form use. Tool-call round-trips usually fit under 4096 so it is often invisible, but any single turn whose thinking (at medium/high/xhigh effort) or output exceeds ~4096 tokens fails with no deliverable content.
  • Frequency: deterministic whenever a single generation needs more than 4096 tokens; raising thinking effort makes failures more likely, which is counterintuitive.
  • Consequence: failed turns with no answer or tool call ("Agent couldn't generate a response").

Additional information

Suggested fix: in stream.runtime.js, the adaptive-thinking branch should apply the resolved model.maxTokens (or an agent-level maxOutputTokens) to inferenceConfig.maxTokens, the way the non-adaptive branch already does; ensure the value comfortably exceeds the thinking budget so thinking plus answer fit. And/or expose a config key that feeds settingsParams.maxOutputTokens, and broaden resolveKnownMaxTokens beyond Fable-5. Apply the same fix to the Fable-5 branch.

Workaround: lower thinking effort (off/minimal/low/medium) so thinking fits under 4096, leaving room for the answer; single output-heavy generations (>4096 tokens) still truncate regardless of effort. A local patch mirroring the non-adaptive branch (apply model.maxTokens in the adaptive + Fable branches) was verified to raise the built inferenceConfig.maxTokens from 4096 to 128000 with the adaptive thinking/output_config.effort fields preserved. Happy to open a PR.

Activity

  1. clawsweeper commented on Jun 27, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 27, 2026, 12:47 AM ET / 04:47 UTC.

    Summary
    Keep open: current main and v2026.6.10 still leave Bedrock adaptive-thinking/Fable option resolution on the base maxTokens path while only the non-adaptive Claude branch applies the model maxTokens cap, and no merged duplicate fix was found.

    Reproducibility: yes. at source level: current main shows adaptive Bedrock requests keep options.maxTokens unset while the non-adaptive Claude path derives a cap from model.maxTokens. I did not run a live AWS Bedrock repro in this read-only pass, so this is source-reproducible rather than fully reproduced.

    Root-cause cluster
    Relationship: canonical
    Canonical: #97176
    Summary: This issue is the canonical known report for the Bedrock adaptive-thinking maxTokens cap; provided related refs are false positives from numbered-list text and targeted searches found no separate owner.

    Members:

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

    Next step
    This is a narrow provider-runtime repair with clear source proof, likely files, and focused regression tests; live Bedrock proof can be added when credentials are available.

    Review details

    Best possible solution:

    Make Bedrock adaptive-thinking and Fable option resolution populate maxTokens from resolved model metadata when no explicit caller cap is set, preserving explicit maxTokens overrides and adaptive thinking payload behavior.

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

    Yes, at source level: current main shows adaptive Bedrock requests keep options.maxTokens unset while the non-adaptive Claude path derives a cap from model.maxTokens. I did not run a live AWS Bedrock repro in this read-only pass, so this is source-reproducible rather than fully reproduced.

    Is this the best way to solve the issue?

    Yes: the narrow maintainable fix is to reuse existing model-cap maxTokens semantics in the Bedrock provider runtime, not to add a new config surface. Existing params.maxTokens behavior should remain the explicit override path.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No live AWS Bedrock repro was run in this read-only review; a fix PR should add live provider proof when credentials are available.

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

    Label changes

    Label justifications:

    • P2: This is a normal-priority provider runtime bug with a clear source path and a blast radius limited to Bedrock adaptive-thinking Claude requests.
    • impact:message-loss: The reported failure mode can end a turn at length before any visible answer or tool call is delivered.
    • impact:auth-provider: The bug is in provider/model request wiring for Amazon Bedrock Claude output-token limits.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs extensions/amazon-bedrock/stream.runtime.test.ts extensions/amazon-bedrock/discovery.test.ts
    • git diff --check
    • Optional when AWS credentials are available: run a live Bedrock Converse smoke for us.anthropic.claude-opus-4-8 with adaptive thinking and maxTokens above 4096.

    What I checked:

    • Current main source: Bedrock request uses options.maxTokens: streamBedrock builds Converse inferenceConfig.maxTokens only when BedrockOptions.maxTokens is populated, so resolveSimpleBedrockOptions must carry the model cap into options for it to reach Bedrock. (extensions/amazon-bedrock/stream.runtime.ts:213, fbfadbd806e1)
    • Current main source: adaptive and Fable branches skip model-cap adjustment: resolveSimpleBedrockOptions returns base options for the Fable branch and the supportsAdaptiveThinking branch, while the non-adaptive Claude branch calls adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, ...) and assigns the adjusted maxTokens. (extensions/amazon-bedrock/stream.runtime.ts:356, fbfadbd806e1)
    • Shared option contract confirms base options do not use model.maxTokens: buildBaseOptions copies maxTokens only from SimpleStreamOptions, and adjustMaxTokensForThinking is the existing helper that falls back to modelMaxTokens when no explicit caller cap exists. (src/llm/providers/simple-options.ts:10, fbfadbd806e1)
    • Current tests encode the uncovered adaptive path: The adaptive Claude alias test currently expects inferenceConfig to be empty, so the missing maxTokens propagation has no regression coverage yet. (extensions/amazon-bedrock/stream.runtime.test.ts:493, fbfadbd806e1)
    • Catalog docs make model maxTokens a supported configuration surface: The gateway config docs say matching model contextWindow/maxTokens use the higher explicit or implicit value, and model/provider maxTokens fields are documented output-token caps. Public docs: docs/gateway/config-tools.md. (docs/gateway/config-tools.md:521, fbfadbd806e1)
    • Discovery currently only gives known maxTokens to Fable: resolveKnownMaxTokens returns 128000 only for Claude Fable 5; Opus 4.8 has known context metadata but falls back to the default maxTokens unless user catalog config supplies it. (extensions/amazon-bedrock/discovery.ts:173, fbfadbd806e1)

    Likely related people:

    • steipete: Authored and merged the Opus 4.8 support and Fable adaptive-thinking PRs that changed the Bedrock stream, discovery, and thinking-policy surfaces 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)
    • vincentkoc: Recently maintained adjacent Bedrock adaptive-thinking behavior and merged Bedrock discovery work that feeds provider model metadata. (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)
    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.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    no-staleExclude from stale automation
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    and removed
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    on Jun 27, 2026
  3. changed the title [-]Bedrock adaptive-thinking models hard-capped at 4096 output tokens; model maxTokens ignored, no config override[/-] [+][Bug]: Bedrock adaptive-thinking models hard-capped at 4096 output tokens; model maxTokens ignored, no config override[/+] on Jun 27, 2026
  4. added 8 commits that reference this issue on Jun 27, 2026
    33a0074
    fecb09f
    f65d28f
    ab0fe84
    c97da60
    d4050f2
  5. locked as resolved and limited conversation to collaborators on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions