Skip to content

fix(bedrock): report 1M context for Opus 4.6+/Sonnet 4.6 - #54901

Closed
kilotone wants to merge 2 commits into
NousResearch:mainfrom
kilotone:fix/bedrock-1m-context
Closed

fix(bedrock): report 1M context for Opus 4.6+/Sonnet 4.6#54901
kilotone wants to merge 2 commits into
NousResearch:mainfrom
kilotone:fix/bedrock-1m-context

Conversation

@kilotone

Copy link
Copy Markdown

Problem

BEDROCK_CONTEXT_LENGTHS reported 200K for Opus 4.6 / Sonnet 4.6, but build_anthropic_bedrock_client() attaches the context-1m-2025-08-07 beta header unconditionally to the AnthropicBedrock client used by the Bedrock provider (wired at agent/agent_init.py:653). These models actually serve a 1M window on Bedrock, so context-usage accounting under-reported the real window (the client requests 1M on the wire while the meter capped at 200K).

Fix

Bump Opus 4.6/4.7/4.8 and Sonnet 4.6 to 1_000_000. Older 3.x / Sonnet-4 / Haiku models have no 1M support and stay at 200K.

Added an ordering note: get_bedrock_context_length() picks the longest matching substring, so specific keys (e.g. claude-opus-4-8) must precede the bare claude-opus-4 fallback for ids like us.anthropic.claude-opus-4-8.

Verification

  • Traced build_anthropic_bedrock_client (anthropic_adapter.py:867) -> sends the 1M beta unconditionally; confirmed it is the client wired for the provider at agent_init.py:653.
  • Verified live: status bar reports /1M for us.anthropic.claude-opus-4-8 after the fix.

The AnthropicBedrock client (build_anthropic_bedrock_client) attaches the
context-1m-2025-08-07 beta unconditionally, so these models actually serve
a 1M window on Bedrock. BEDROCK_CONTEXT_LENGTHS still reported 200K, causing
context-usage accounting to under-report the real window. Bump Opus 4.6/4.7/4.8
and Sonnet 4.6 to 1M; older 3.x/Sonnet-4/Haiku stay at 200K. Ordering note
added since get_bedrock_context_length picks the longest substring match.
Copilot AI review requested due to automatic review settings June 29, 2026 13:09

Copilot AI 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.

Pull request overview

Updates Hermes’ AWS Bedrock model metadata so context-window accounting matches the effective 1M context enabled by the Bedrock Anthropic SDK client headers for Claude Opus 4.6+ and Sonnet 4.6.

Changes:

  • Bumped BEDROCK_CONTEXT_LENGTHS for anthropic.claude-opus-4-6/4-7/4-8 and anthropic.claude-sonnet-4-6 from 200K to 1,000,000.
  • Added explanatory inline notes clarifying why these models should be treated as 1M on Bedrock.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agent/bedrock_adapter.py Outdated
Comment on lines +1308 to +1311
# Ordering matters: get_bedrock_context_length() picks the LONGEST matching
# substring, so more specific keys (e.g. "claude-opus-4-8") must precede the
# bare "claude-opus-4" / "claude-sonnet-4" fallbacks to win for an id like
# "us.anthropic.claude-opus-4-8".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, the wording was misleading — resolution is by longest matching key length, not insertion order. Rewrote the comment to say so explicitly (insertion order would only matter for same-length ties, which we don't have; keys are grouped specific-first purely for readability). Fixed in ea8038c.

Comment thread agent/bedrock_adapter.py
Comment on lines +1312 to +1315
"anthropic.claude-opus-4-8": 1_000_000,
"anthropic.claude-opus-4-7": 1_000_000,
"anthropic.claude-opus-4-6": 1_000_000,
"anthropic.claude-sonnet-4-6": 1_000_000,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Correct — those assertions would have failed CI. Updated in ea8038c: test_claude_opus_4_6, test_claude_sonnet_versioned, and test_inference_profile_resolves now assert 1_000_000, plus added test_claude_opus_versioned_newer (opus-4-8) and a test_claude_sonnet_4_5_stays_200k regression guard. All 9 in TestBedrockContextLength pass locally.

@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 — same BEDROCK_CONTEXT_LENGTHS table bump (Opus 4.6/4.7/4.8 + Sonnet 4.6 to 1M) in agent/bedrock_adapter.py. #24059 is the earliest open PR for this fix. Broader competing variants that the maintainer may prefer for extra scope: #44861 (also adds Fable + cache invalidation), #26769 (also bumps the anthropic SDK for bearer-token auth), #31309 (also forwards the beta on the native Converse adapter).

…ng note

Address Copilot review on NousResearch#54901:
- Update TestBedrockContextLength assertions to 1M for opus-4-6/sonnet-4-6
  (were still asserting 200K -> would fail CI). Add opus-4-8 and a
  sonnet-4-5-stays-200K regression guard.
- Correct the misleading 'ordering matters' comment: resolution is by longest
  key length, independent of insertion order (ties aside).
@kilotone

Copy link
Copy Markdown
Author

Thanks — both points fixed in ea8038c:

  1. Stale test assertions (would have failed CI) — test_claude_opus_4_6, test_claude_sonnet_versioned, test_inference_profile_resolves now assert 1M; added an opus-4-8 case and a sonnet-4-5-stays-200K regression guard. All 9 context-length tests pass locally.
  2. Misleading ordering comment — rewrote it: resolution is by longest matching key length, independent of insertion order (ties aside).

@kilotone

Copy link
Copy Markdown
Author

Thanks — you're right that #24059 (@patrick-muller, 2026-05-11) predates this and covers the same core bump (opus-4-6/4-7 + sonnet-4-6 → 1M, with sonnet-4-5/haiku-4-5 staying 200K). I'm happy to defer to it as the canonical fix.

One gap worth folding in before this is closed as a straight dupe: #24059's table does not include anthropic.claude-opus-4-8 — I confirmed against its head (patrick-muller:fix/bedrock-claude-1m-context-table), it stops at opus-4-7. opus-4-8 is the model I'm actually running, and without an entry it falls through to the 200K default, which is the exact bug this class of PR is meant to fix. My #54901 adds that row (+ an opus-4-8 test and a sonnet-4-5-stays-200K regression guard).

Suggestion: merge #24059 as the base and either cherry-pick the opus-4-8 line from here, or I can rebase #54901 down to just the opus-4-8 addition on top of #24059 so there's no overlap. Whatever's least work for the maintainer — I'll close this in favour of #24059 if you'd rather the opus-4-8 entry be added there directly.

@kilotone

Copy link
Copy Markdown
Author

Unifying the Bedrock 1M-context PR family

I reviewed every open/closed PR touching BEDROCK_CONTEXT_LENGTHS and the 1M-context path so this doesn't keep getting re-opened. Posting the synthesis here, then closing this PR (#54901) — see the conclusion. cc @patrick-muller @avifenesh @bcwilsondotcom @xxxigm @mmcclean-aws @alt-glitch

The family (6 PRs, 2 concerns)

PR Author State Scope Unique strength Gap
#16686 mmcclean-aws closed table only (+3/-2) first to spot it no tests; superseded
#24059 patrick-muller open table + tests best docs: Anthropic-doc citations + explicit "stays 200K" guard tests for sonnet-4-5/haiku-4-5 no opus-4-8; no Fable
#26769 bcwilsondotcom open table + SDK bump bumps anthropic 0.86→0.102 (bearer-token auth) SDK bump is orthogonal to context table
#31309 xxxigm open Converse beta forwarding only PR that actually sends the beta on the native Converse adapter, opt-in via HERMES_BEDROCK_1M_CONTEXT, de-dupes caller betas larger surface (+373); orthogonal to the metadata table
#44861 avifenesh open table + cache invalidation most complete table (adds Fable + opus-4-8) and drops stale Bedrock cache entries in model_metadata.py so a cached 200K can't override the bump
#54901 (this) open table + ordering fix opus-4-8 entry + corrected longest-key comment + plumbing test strict subset of #44861's table

Two genuinely separate concerns

  1. Metadata (what window the agent thinks it has) → drives /usage, compression threshold, subagent budgets. This is the BEDROCK_CONTEXT_LENGTHS table. PRs: fix(bedrock): correct context lengths for Claude 4.x models to 1M tokens #16686, fix(bedrock): align Claude context-window table with Anthropic docs #24059, fix(bedrock): add 1M context for Opus 4.6/4.7 + Sonnet 4.6, bump anthropic SDK for bearer-token auth #26769, fix(bedrock): Fable reports 128K context — add Fable + Claude 4.6/4.7/4.8 1M entries to Bedrock table, invalidate stale cache #44861, fix(bedrock): report 1M context for Opus 4.6+/Sonnet 4.6 #54901.
  2. Transport (whether the beta is sent on the wire) → only matters on the native Converse adapter for accounts whose models still require the context-1m-2025-08-07 beta. PR: fix(bedrock): forward context-1m beta on native Converse adapter (#31277) #31309. Note Opus 4.6+/Sonnet 4.6 are 1M GA on Bedrock (no header), so fix(bedrock): forward context-1m beta on native Converse adapter (#31277) #31309 is a niche add for entitled-but-beta-gated setups, not a prerequisite for the metadata fix.

Recommended unified merge path (best-of, no redundant code)

  1. Land fix(bedrock): Fable reports 128K context — add Fable + Claude 4.6/4.7/4.8 1M entries to Bedrock table, invalidate stale cache #44861 as the canonical metadata PR — it already supersets fix(bedrock): align Claude context-window table with Anthropic docs #24059, fix(bedrock): add 1M context for Opus 4.6/4.7 + Sonnet 4.6, bump anthropic SDK for bearer-token auth #26769(table), and fix(bedrock): report 1M context for Opus 4.6+/Sonnet 4.6 #54901: Fable + opus-4-8 + opus-4-7/4-6 + sonnet-4-6, plus the stale-cache invalidation the others all miss (without it, a previously-cached 200K entry silently wins over the corrected table).
  2. Cherry-pick from fix(bedrock): align Claude context-window table with Anthropic docs #24059 into fix(bedrock): Fable reports 128K context — add Fable + Claude 4.6/4.7/4.8 1M entries to Bedrock table, invalidate stale cache #44861 before merge: its Anthropic-doc citation block + the explicit test_claude_sonnet_4_5_is_200k / test_claude_haiku_4_5_is_200k guard tests. fix(bedrock): Fable reports 128K context — add Fable + Claude 4.6/4.7/4.8 1M entries to Bedrock table, invalidate stale cache #44861 has the better table; fix(bedrock): align Claude context-window table with Anthropic docs #24059 has the better documentation and regression guards. Merge the two and you lose nothing.
  3. Keep fix(bedrock): forward context-1m beta on native Converse adapter (#31277) #31309 as its own PR (transport, opt-in env var) — don't fold it into the metadata PR.
  4. Keep fix(bedrock): add 1M context for Opus 4.6/4.7 + Sonnet 4.6, bump anthropic SDK for bearer-token auth #26769's SDK bump as its own PR — bearer-token auth is unrelated to context windows.

Conclusion for this PR

#54901's only deltas over #44861 were the opus-4-8 row (already in #44861) and a corrected longest-key-wins comment. Nothing here is worth a competing PR. Closing #54901 in favor of #44861 (+ the #24059 doc/test cherry-pick). The one line worth carrying over if reviewers prefer #24059 as the base instead of #44861: add "anthropic.claude-opus-4-8": 1_000_000 and a us./global. inference-profile test for it — that's the only model currently shipping that the #24059 table omits.

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) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants