Skip to content

fix: prioritize Anthropic 1M limits over cached context limits#2460

Merged
code-yeongyu merged 1 commit intodevfrom
fix/2366-regression
Mar 11, 2026
Merged

fix: prioritize Anthropic 1M limits over cached context limits#2460
code-yeongyu merged 1 commit intodevfrom
fix/2366-regression

Conversation

@code-yeongyu
Copy link
Copy Markdown
Owner

@code-yeongyu code-yeongyu commented Mar 11, 2026

Summary

  • Fix limit resolution precedence in context-window-monitor.ts and dynamic-truncator.ts
  • Anthropic 1M mode check now runs FIRST, cached limits only used for non-Anthropic providers
  • Previously: cachedLimit ?? anthropicLimit — cached 200K could override 1M mode
  • Now: Anthropic provider → getAnthropicActualLimit(), others → cached limit
  • Added regression tests for both modules

Fixes regression from #2366


Summary by cubic

Ensures Anthropic’s 1M context window is always used when 1M mode is enabled, instead of being overridden by cached 200K limits. Prevents incorrect context warnings and truncation for Anthropic sessions.

  • Bug Fixes
    • Anthropic providers now resolve limits via getAnthropicActualLimit() and ignore cached model limits.
    • Non-Anthropic providers continue to use cached model-specific limits in context-window-monitor.ts and dynamic-truncator.ts.
    • Added regression tests covering the 1M override behavior.

Written for commit 4516b2e. Summary will update on new commits.

@code-yeongyu code-yeongyu merged commit 404b8dc into dev Mar 11, 2026
8 checks passed
@code-yeongyu code-yeongyu deleted the fix/2366-regression branch March 11, 2026 11:44
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 4 files

Confidence score: 5/5

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

Auto-approved: Fixes a precedence regression where cached limits overrode Anthropic 1M mode, with new tests verifying the fix.

kilhyeonjun added a commit to kilhyeonjun/oh-my-opencode that referenced this pull request Mar 18, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant