openclaw - ✅(Solved) Fix amazon-bedrock discovery: contextWindow defaults to 32000 for Claude 3.x/4.x; need per-model override [6 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#73328Fetched 2026-04-29 06:20:57
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Timeline (top)
cross-referenced ×6commented ×1referenced ×1

extensions/amazon-bedrock/discovery.ts's toModelDefinition function applies a single defaults.contextWindow to every model returned by ListFoundationModelsCommand. The default in current openclaw releases is 32000. Anthropic Claude 3.x and 4.x models have a 200K context window per Anthropic's published docs. With cw=32000 in the gateway's in-memory model registry, prompts that fit comfortably in 200K trigger context-overflow → compaction-fail → session-restart loops on tight prompts (the in-memory state is sourced from this discovery code path; the on-disk models.json cache is not re-read at runtime).

Root Cause

extensions/amazon-bedrock/discovery.ts's toModelDefinition function applies a single defaults.contextWindow to every model returned by ListFoundationModelsCommand. The default in current openclaw releases is 32000. Anthropic Claude 3.x and 4.x models have a 200K context window per Anthropic's published docs. With cw=32000 in the gateway's in-memory model registry, prompts that fit comfortably in 200K trigger context-overflow → compaction-fail → session-restart loops on tight prompts (the in-memory state is sourced from this discovery code path; the on-disk models.json cache is not re-read at runtime).

Fix Action

Workaround

A flake.nix overlay against discovery.ts (nix/patches/bedrock-claude-context-window.patch) that applies the override inside toModelDefinition. We've classified this as upstream-debt and our overlay's postPatch includes a forcing function that fails the build if a config knob ships, so we'll know to retire the overlay.

PR fix notes

PR #73359: fix(amazon-bedrock): add modelContextWindowOverrides for per-model context window config

Description (problem / solution / changelog)

Summary

Fixes #73328

Issue

Amazon Bedrock discovery defaults contextWindow to 32000 for all Claude 3.x/4.x models, which is incorrect for newer models with larger context windows.

Solution

Add modelContextWindowOverrides config option that allows users to specify per-model context window overrides via regex patterns. The known-model table takes precedence; regex overrides are checked only when no exact match is found.

Changes

  • extensions/amazon-bedrock/discovery.ts: Add modelContextWindowOverrides support with regex-based model matching
  • extensions/amazon-bedrock/discovery.test.ts: Add tests for override behavior
  • src/config/types.models.ts: Add config type definition

Changed files

  • docs/providers/bedrock.md (modified, +4/-0)
  • extensions/amazon-bedrock/discovery.test.ts (modified, +146/-0)
  • extensions/amazon-bedrock/discovery.ts (modified, +60/-11)
  • extensions/amazon-bedrock/openclaw.plugin.json (modified, +10/-1)
  • src/config/types.models.ts (modified, +6/-0)

PR #73382: fix(amazon-bedrock): resolve 200K context window for Claude 3.x and unlisted Anthropic Bedrock variants

Description (problem / solution / changelog)

Summary

  • Problem: extensions/amazon-bedrock/discovery.ts only listed a handful of Anthropic models in KNOWN_CONTEXT_WINDOWS. Common Bedrock IDs such as anthropic.claude-3-opus-20240229-v1:0, anthropic.claude-3-sonnet-20240229-v1:0, and anthropic.claude-3-5-sonnet-2024{0620,1022}-v{1,2}:0 fell through to defaults.contextWindow (32K by default), so prompts well below the model's actual 200K window tripped context-overflow precheck and triggered auto-compaction restart loops.
  • Why it matters: every Bedrock customer using a Claude 3.x base model that wasn't already enumerated saw the gateway's in-memory model registry advertise 32K and refuse prompts the model could otherwise serve.
  • What changed: backfill the missing Claude 3 / 3.5 / Opus 4 base entries at 200K, then add a small KNOWN_CONTEXT_WINDOW_FAMILIES table with an ^anthropic\.claude-(3|4) regex so unlisted future variants and region-prefixed inference profiles (us.anthropic.claude-*, jp.anthropic.claude-*, etc.) default to 200K. Explicit table entries still win for higher-tier (1M) Claude rows.
  • What did NOT change (scope boundary): no other vendor families. The defaultContextWindow config knob is untouched. Inference-profile prefix stripping logic and existing strict matches are unchanged.

Change Type

  • Bug fix

Scope

  • amazon-bedrock plugin (provider discovery)

Linked Issue/PR

  • Closes #73328
  • This PR fixes a bug or regression

Root Cause

  • Root cause: KNOWN_CONTEXT_WINDOWS was a hand-maintained map and missed the Claude 3 / 3.5 base IDs that most users encounter on Bedrock. There was no family-level fallback, so any unmatched model fell through to resolveDefaultContextWindow (32K default).
  • Missing detection / guardrail: no test verified the family-level resolution; existing tests only cover Claude 3.7 / 4.x rows that happened to be in the map.
  • Contributing context: AWS does not expose token-limit metadata via ListFoundationModelsCommand, so any unmatched model gets the conservative default.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file: extensions/amazon-bedrock/discovery.test.ts
  • Scenarios the test locks in:
    • Claude 3.5 Sonnet v2 (anthropic.claude-3-5-sonnet-20241022-v2:0) resolves to 200K via the explicit table entry.
    • An unlisted future Claude 3 variant (anthropic.claude-3-future-preview-v9:0) resolves to 200K via the KNOWN_CONTEXT_WINDOW_FAMILIES fallback rather than 32K.
    • The same family fallback works for region-prefixed inference profiles (us.anthropic.claude-3-future-preview-v9:0).
  • Why this is the smallest reliable guardrail: the bug surface is "missing entry / no fallback in resolveKnownContextWindow". The new tests pin both the table backfill and the family fallback, including the inference-profile prefix path.

User-visible / Behavior Changes

  • Bedrock-discovered Claude 3.x models now report 200K context windows in the gateway's in-memory model registry instead of 32K.
  • Bedrock-discovered Anthropic models with IDs not listed in KNOWN_CONTEXT_WINDOWS default to 200K via family fallback instead of 32K.
  • No other providers are affected.

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Steps

  1. Configure a Bedrock provider with default discovery and a Claude 3.5 Sonnet (or any unlisted Claude 3.x) model.
  2. Boot the gateway and inspect the in-memory model registry / /health/deep.
  3. Send a prompt totalling ~16K input tokens.

Expected

  • contextWindow reported as 200000 for anthropic.claude-* Bedrock models, no context-overflow precheck triggered for the 16K prompt.

Actual (before fix)

  • contextWindow=32000; the 16K prompt is treated as nearly full and triggers [context-overflow-precheck] estimatedPromptTokens=16300 promptBudgetBeforeReserve=15616Auto-compaction failed.*Restarting session.

Evidence

  • Static reproduction is provided by the new unit tests in extensions/amazon-bedrock/discovery.test.ts. Live Bedrock validation requires AWS credentials and is left to CI / downstream verification.

Human Verification

  • Verified scenarios: TypeScript clean on touched files; new tests added next to existing discovery.test.ts Claude/Sonnet suite.
  • Edge cases checked: explicit table entries still win (e.g. Claude Sonnet 4.6 @ 1M), region-prefixed inference profiles route through stripping then family fallback, non-Claude families (Llama, Mistral, etc.) untouched.
  • What I did NOT verify: a live Bedrock call with AWS credentials; full pnpm check / pnpm test was not exercised locally, leaving CI as the verification surface.

Compatibility / Migration

  • Backward compatible? Yes — existing explicit table entries are unchanged. Only previously-incorrect 32K resolutions become 200K.
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: a non-Anthropic Bedrock model id happens to start with anthropic.claude-3 or anthropic.claude-4.
    • Mitigation: AWS's Bedrock model id namespace is provider-prefixed (anthropic.), so this regex is well-scoped to the Claude family. The explicit map still takes precedence and any future tier-bump (e.g. another 1M variant) just needs another explicit entry.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • extensions/amazon-bedrock/discovery.test.ts (modified, +60/-0)
  • extensions/amazon-bedrock/discovery.ts (modified, +27/-2)

PR #73907: fix(amazon-bedrock): add modelContextWindowOverrides for per-model context window config

Description (problem / solution / changelog)

Summary

Fixes #73328

Issue

Amazon Bedrock discovery defaults contextWindow to 32000 for all Claude 3.x/4.x models, which is incorrect for newer models with larger context windows.

Solution

Add modelContextWindowOverrides config option that allows users to specify per-model context window overrides via regex patterns. The known-model table takes precedence; regex overrides are checked only when no exact match is found.

Changes

  • extensions/amazon-bedrock/discovery.ts: Add modelContextWindowOverrides support with regex-based model matching, sorted cache keys, and stripped-ID fallback
  • extensions/amazon-bedrock/discovery.test.ts: Add tests for override behavior
  • extensions/amazon-bedrock/openclaw.plugin.json: Add config schema and uiHints
  • docs/providers/bedrock.md: Add documentation for the new config option
  • src/config/types.models.ts: Add config type definition

Notes

  • Replaces closed PR #73359 with all P2 fixes applied

Changed files

  • docs/providers/bedrock.md (modified, +4/-0)
  • extensions/amazon-bedrock/discovery.test.ts (modified, +146/-0)
  • extensions/amazon-bedrock/discovery.ts (modified, +60/-11)
  • extensions/amazon-bedrock/openclaw.plugin.json (modified, +10/-1)
  • src/config/types.models.ts (modified, +6/-0)

PR #73912: fix(amazon-bedrock): add modelContextWindowOverrides for per-model context window config

Description (problem / solution / changelog)

Summary

Fixes #73328

Issue

Amazon Bedrock discovery defaults contextWindow to 32000 for all Claude 3.x/4.x models, which is incorrect for newer models with larger context windows.

Solution

Add modelContextWindowOverrides config option that allows users to specify per-model context window overrides via regex patterns. The known-model table takes precedence; regex overrides are checked only when no exact match is found.

Changes

  • extensions/amazon-bedrock/discovery.ts: Add modelContextWindowOverrides support with regex-based model matching, sorted cache keys, stripped-ID fallback, and deterministic override ordering
  • extensions/amazon-bedrock/discovery.test.ts: Add tests for override behavior
  • extensions/amazon-bedrock/openclaw.plugin.json: Add config schema and uiHints
  • docs/providers/bedrock.md: Add documentation for the new config option
  • src/config/types.models.ts: Add config type definition

History

  • Closed #73359 (initial submission, 2 P2 issues)
  • Closed #73907 (P1: cache key/matching order mismatch)
  • This PR includes all fixes

Changed files

  • docs/providers/bedrock.md (modified, +4/-0)
  • extensions/amazon-bedrock/discovery.test.ts (modified, +146/-0)
  • extensions/amazon-bedrock/discovery.ts (modified, +64/-11)
  • extensions/amazon-bedrock/openclaw.plugin.json (modified, +10/-1)
  • src/config/types.models.ts (modified, +6/-0)

PR #73935: fix(amazon-bedrock): add modelContextWindowOverrides for per-model context window config

Description (problem / solution / changelog)

Summary

Fixes #73328

Issue

Amazon Bedrock discovery defaults contextWindow to 32000 for all Claude 3.x/4.x models, which is incorrect for newer models with larger context windows.

Solution

Add modelContextWindowOverrides config option that allows users to specify per-model context window overrides via regex patterns. The known-model table takes precedence; regex overrides are checked only when no exact match is found.

Changes

  • extensions/amazon-bedrock/discovery.ts: Add modelContextWindowOverrides support with regex-based model matching, sorted cache keys, stripped-ID fallback, deterministic override ordering, and ReDoS note
  • extensions/amazon-bedrock/discovery.test.ts: Add tests for override behavior
  • extensions/amazon-bedrock/openclaw.plugin.json: Add config schema and uiHints
  • docs/providers/bedrock.md: Add documentation for the new config option with match ordering clarification
  • src/config/types.models.ts: Add config type definition

History

  • #73359 (initial, 2 P2)
  • #73907 (P1: cache key/matching order mismatch)
  • #73912 (2 P2: docs ordering + ReDoS note)
  • This PR includes all fixes

Changed files

  • docs/providers/bedrock.md (modified, +4/-0)
  • extensions/amazon-bedrock/discovery.test.ts (modified, +146/-0)
  • extensions/amazon-bedrock/discovery.ts (modified, +68/-11)
  • extensions/amazon-bedrock/openclaw.plugin.json (modified, +10/-1)
  • src/config/types.models.ts (modified, +6/-0)

PR #73959: fix(amazon-bedrock): add modelContextWindowOverrides for per-model context window config

Description (problem / solution / changelog)

Summary

Fixes #73328

Issue

Amazon Bedrock discovery defaults contextWindow to 32000 for all Claude 3.x/4.x models, which is incorrect for newer models with larger context windows.

Solution

Add modelContextWindowOverrides config option that allows users to specify per-model context window overrides via regex patterns. The known-model table takes precedence; regex overrides are checked only when no exact match is found.

Changes

  • extensions/amazon-bedrock/discovery.ts: regex overrides with deterministic key-sorted matching, cache key normalisation, stripped-ID lookup, Number.isInteger guard
  • extensions/amazon-bedrock/discovery.test.ts: tests for override behaviour
  • extensions/amazon-bedrock/openclaw.plugin.json: config schema + uiHints
  • docs/providers/bedrock.md: config docs with match ordering clarification
  • src/config/types.models.ts: type definition

Changed files

  • docs/providers/bedrock.md (modified, +4/-0)
  • extensions/amazon-bedrock/discovery.test.ts (modified, +146/-0)
  • extensions/amazon-bedrock/discovery.ts (modified, +68/-11)
  • extensions/amazon-bedrock/openclaw.plugin.json (modified, +10/-1)
  • src/config/types.models.ts (modified, +6/-0)
RAW_BUFFERClick to expand / collapse

Summary

extensions/amazon-bedrock/discovery.ts's toModelDefinition function applies a single defaults.contextWindow to every model returned by ListFoundationModelsCommand. The default in current openclaw releases is 32000. Anthropic Claude 3.x and 4.x models have a 200K context window per Anthropic's published docs. With cw=32000 in the gateway's in-memory model registry, prompts that fit comfortably in 200K trigger context-overflow → compaction-fail → session-restart loops on tight prompts (the in-memory state is sourced from this discovery code path; the on-disk models.json cache is not re-read at runtime).

Repro

  1. Configure a Bedrock provider with default discovery.
  2. Boot the gateway. Observe /health/deep shows contextWindow=32000 for every anthropic.claude-* and us.anthropic.claude-* entry.
  3. Send a prompt that produces ~16400 input tokens (well below 200K). Observe [context-overflow-precheck] estimatedPromptTokens=16300 promptBudgetBeforeReserve=15616 (= 32000 − 16384 reserve) and Auto-compaction failed.*Restarting session.

Expected

Per-model context windows respected, either via:

  • A built-in lookup table for known Anthropic models (Claude 3.x/4.x → 200000), OR
  • A config knob models.providers.amazon-bedrock.modelContextWindowOverrides accepting a regex → integer map honored by toModelDefinition or downstream.

Workaround

A flake.nix overlay against discovery.ts (nix/patches/bedrock-claude-context-window.patch) that applies the override inside toModelDefinition. We've classified this as upstream-debt and our overlay's postPatch includes a forcing function that fails the build if a config knob ships, so we'll know to retire the overlay.

Reference

  • Discovered during a downstream investigation (compaction-loop on agent:main:main on dual-user gateways).
  • Downstream overlay PR: github.com/markthebest12/openclaw-infra#1236

extent analysis

TL;DR

Apply a per-model context window override to respect Anthropic Claude 3.x and 4.x models' 200K context window.

Guidance

  • Identify the toModelDefinition function in extensions/amazon-bedrock/discovery.ts as the source of the issue, where a single defaults.contextWindow is applied to every model.
  • Consider using a built-in lookup table or a config knob models.providers.amazon-bedrock.modelContextWindowOverrides to override the context window for specific models.
  • Apply the provided nix/patches/bedrock-claude-context-window.patch as a temporary workaround to override the context window inside toModelDefinition.
  • Monitor for an upstream fix that introduces a config knob, and be prepared to retire the overlay when it becomes available.

Example

No code snippet is provided as the issue does not contain sufficient information to generate a minimal code example.

Notes

The provided workaround is specific to the Anthropic Claude 3.x and 4.x models, and may not be applicable to other models. The upstream debt is tracked, and the overlay includes a forcing function to fail the build if a config knob ships, ensuring the overlay is retired when the issue is resolved.

Recommendation

Apply the workaround by using the nix/patches/bedrock-claude-context-window.patch to override the context window inside toModelDefinition, as it provides a temporary solution to respect the per-model context windows.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix amazon-bedrock discovery: contextWindow defaults to 32000 for Claude 3.x/4.x; need per-model override [6 pull requests, 1 comments, 2 participants]