Skip to content

fix(shared): respect cached model context limits for Anthropic providers post-GA#2664

Merged
code-yeongyu merged 2 commits intocode-yeongyu:devfrom
kilhyeonjun:fix/anthropic-1m-ga-context-limit
Mar 25, 2026
Merged

fix(shared): respect cached model context limits for Anthropic providers post-GA#2664
code-yeongyu merged 2 commits intocode-yeongyu:devfrom
kilhyeonjun:fix/anthropic-1m-ga-context-limit

Conversation

@kilhyeonjun
Copy link
Copy Markdown
Contributor

@kilhyeonjun kilhyeonjun commented Mar 18, 2026

Summary

After Anthropic's 1M context GA (2026-03-13), the anthropic-beta: context-1m header is no longer required. However, context-limit-resolver.ts still relies on this header to detect 1M support via anthropicContext1MEnabled. Without the header, all Anthropic models fall back to the 200K default — even though models.dev (and OpenCode's cached model data) correctly reports 1M for claude-opus-4-6 and claude-sonnet-4-6.

This causes:

  • Premature context warnings at 140K tokens (70% of 200K)
  • Unnecessary preemptive compaction at 156K tokens (78% of 200K)
  • Agents proactively creating handoffs despite having ~860K tokens remaining

Changes

Update resolveActualContextLimit() to check per-model cached limits from provider config when the explicit 1M flag is not set.

Priority order:

  1. Explicit 1M mode (beta header flag or ANTHROPIC_1M_CONTEXT env var) → 1M for all Anthropic models
  2. Per-model cached limit from provider config (populated from models.dev data) → model-specific limit
  3. Default fallback → 200K

This preserves the #2460 fix (explicit 1M flag always takes priority over cached values, preventing the old regression where cached 200K overrode the 1M flag) while allowing post-GA models to use their correct limits from the cache.

Test Changes

  • context-limit-resolver.test.ts: 3 new test cases (GA cache hit, no cache fallback, explicit flag priority)
  • context-window-monitor.model-context-limits.test.ts: Updated to verify cached limits are respected for Anthropic providers, with both below-threshold and above-threshold scenarios

Verification

  • bun run typecheck
  • bun run build
  • bun test on all related files: 30/30 pass

Related Issues


Summary by cubic

Fixes Anthropic context limit detection post-1M GA by using cached limits only for GA 4.6 models when the explicit 1M flag is off. Older Anthropic models stay at 200K, while opus-4-6 and sonnet-4-6 get their correct 1M windows, preventing early warnings and compaction.

  • Bug Fixes
    • Updated resolveActualContextLimit priority: explicit 1M mode > cached per-model limit for GA 4.6 models (dash and dot IDs) > 200K default for others.
    • Expanded tests and context-window monitor to use cached limits for 4.6 and ignore cache for older models; added dot-version support and explicit-flag priority checks.

Written for commit bf804b0. Summary will update on new commits.

…ers post-GA

After Anthropic's 1M context GA (2026-03-13), the beta header is no
longer sent. The existing detection relied solely on the beta header
to set anthropicContext1MEnabled, causing all Anthropic models to
fall back to the 200K default despite models.dev reporting 1M.

Update resolveActualContextLimit to check per-model cached limits
from provider config (populated from models.dev data) when the
explicit 1M flag is not set. Priority order:
1. Explicit 1M mode (beta header or env var) - all Anthropic models
2. Per-model cached limit from provider config
3. Default 200K fallback

This preserves the code-yeongyu#2460 fix (explicit 1M flag always wins over
cached values) while allowing GA models to use their correct limits.

Fixes premature context warnings at 140K and unnecessary compaction
at 156K for opus-4-6 and sonnet-4-6 users without env var workaround.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Correctly updates Anthropic context limit resolution to respect cached model data post-GA, with explicit flag priority and comprehensive tests. No regressions identified.

@code-yeongyu code-yeongyu added the triage:bug Confirmed bug with repro steps label Mar 24, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 3 files (changes from recent commits).

Auto-approved: The change surgically enables cached context limits for specific Anthropic GA models while preserving existing behavior and priority for all other models, including the 1M explicit flag.

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

Labels

triage:bug Confirmed bug with repro steps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants