Skip to content

fix(bedrock): map Claude opus/sonnet 4.6+ to 1M context window - #54918

Closed
iizotov wants to merge 1 commit into
NousResearch:mainfrom
iizotov:fix/bedrock-context-claude-4x-1m
Closed

fix(bedrock): map Claude opus/sonnet 4.6+ to 1M context window#54918
iizotov wants to merge 1 commit into
NousResearch:mainfrom
iizotov:fix/bedrock-context-claude-4x-1m

Conversation

@iizotov

@iizotov iizotov commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

The Bedrock static context-length table (BEDROCK_CONTEXT_LENGTHS in agent/bedrock_adapter.py) only had entries up to the Claude 4.6 generation and capped every Claude model at 200K. Newer model IDs (opus-4-7, opus-4-8, sonnet-4-7, sonnet-4-8) silently inherited 200K via the generic anthropic.claude-opus-4 / ...-sonnet-4 substring fallback.

This contradicted the native Anthropic table in agent/model_metadata.py (DEFAULT_CONTEXT_LENGTHS), which already maps claude-opus-4-8 / 4-7 / 4-6 and claude-sonnet-4-6 to 1,000,000. The same model resolved to 1M on the native path but 200K on the Bedrock path.

Symptom

A Bedrock user running global.anthropic.claude-opus-4-8 got a 200K context window instead of 1M, forcing a manual model.context_length: 1000000 override in config.yaml.

Fix

Add explicit 1M entries for the opus/sonnet 4.6 / 4.7 / 4.8 generations. Longest-substring matching ensures the versioned entries win over the generic anthropic.claude-opus-4 / ...-sonnet-4 200K fallbacks.

Models that genuinely have no 1M window are explicitly held at 200K so the 4.x bump doesn't sweep them up:

Model Context
opus 4.6 / 4.7 / 4.8 1,000,000
sonnet 4.6 / 4.7 / 4.8 1,000,000
sonnet 4.5 200,000
haiku 4.5 200,000 (no 1M window)
opus 4.5 / 4.1 / 4 200,000
Claude 3.x and older 200,000

Values verified against the authoritative Anthropic model list (1M window for Fable/Mythos 5, opus 4.6–4.8, sonnet 4.6; 200K for everything 4.5 and older, including Haiku 4.5).

Tests

tests/agent/test_bedrock_adapter.py::TestBedrockContextLength:

  • test_claude_opus_4_8 → 1M (new)
  • test_claude_opus_4_6 / test_claude_sonnet_versioned → updated 200K → 1M
  • test_claude_haiku_4_5_stays_200k → 200K guard (new)
  • test_claude_sonnet_4_5_stays_200k → 200K guard (new)

Impact

Bedrock users on Claude opus/sonnet 4.6+ get the correct 1M window without a manual config override. No change for Haiku 4.5, Claude 4.5/4/3.x, Nova, Llama, Mistral, or DeepSeek.

The Bedrock static context table only had entries up to the 4-6
generation and capped all Claude models at 200K. Newer model IDs
(opus/sonnet 4-7, 4-8) silently inherited 200K via the generic
"anthropic.claude-opus-4" / "...-sonnet-4" substring fallback,
contradicting the native Anthropic table in model_metadata.py which
already maps these to 1M.

Map opus/sonnet 4-6/4-7/4-8 to 1_000_000 on Bedrock. Haiku 4.5,
sonnet 4.5, legacy Claude 4 and 3.x stay at 200K (no 1M window).

Add opus-4-8 coverage and haiku/sonnet-4-5 200K guards.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/bedrock AWS Bedrock (boto3, IAM) P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jun 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #24059 (earliest open PR aligning the Bedrock Claude context-window table to 1M for the 4.x generations). The core change here -- bumping the opus/sonnet 4.6/4.7/4.8 entries in BEDROCK_CONTEXT_LENGTHS from 200K to 1M -- matches #24059's diff. Sibling #54901 was already flagged as a duplicate of the same anchor. Related broader variants: #26769 (also bumps the anthropic SDK), #44861 (also adds Fable + invalidates stale cache). Closing as a duplicate is a maintainer call; flagging the cluster so they can pick the canonical PR.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: LGTM

Clean, well-scoped change with no concerns.

--- Reviewed by Hermes Agent

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused Bedrock metadata update. The underlying 200K fallback is still present on current main, but one existing test must be updated with the table change.

Problems

  • tests/agent/test_bedrock_adapter.py:1191 still expects us.anthropic.claude-sonnet-4-6 to resolve to 200K. The proposed anthropic.claude-sonnet-4-6: 1_000_000 entry wins under the longest-substring resolver in agent/bedrock_adapter.py:1335-1342, so this unchanged test will fail.
  • The new comment says agent/model_metadata.py maps the 4.6+ Opus/Sonnet generations to 1M, but current DEFAULT_CONTEXT_LENGTHS only lists Opus 4.6/4.7/4.8 and Sonnet 4.6 at agent/model_metadata.py:216-223.

Suggested changes

  • Change the inference-profile expectation at tests/agent/test_bedrock_adapter.py:1191 to 1_000_000.
  • Scope the explanatory comment to the native mappings actually present, or support the additional Sonnet mappings with an independent Bedrock citation.

Automated hermes-sweeper review.

Comment thread agent/bedrock_adapter.py
"anthropic.claude-sonnet-4-6": 200_000,
# Anthropic Claude models on Bedrock.
# The opus/sonnet 4.6+ generations expose a 1M context window on Bedrock,
# matching the native Anthropic API (see DEFAULT_CONTEXT_LENGTHS in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_CONTEXT_LENGTHS currently contains 1M entries for Opus 4.6/4.7/4.8 and Sonnet 4.6, but not Sonnet 4.7/4.8 (agent/model_metadata.py:216-223). Please narrow this “matching the native Anthropic API” claim or cite Bedrock independently for those additional mappings.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #67977 — your commit (Opus 4.8 row + the longest-substring guard tests) was cherry-picked onto current main with your authorship preserved (rebase merge), on top of #24059's earlier table flip. Thanks for catching that the generic anthropic.claude-opus-4 fallback must not swallow the 4-8 lookups!

#67977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have provider/bedrock AWS Bedrock (boto3, IAM) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants