Skip to content

fix(context-limit-resolver): check modelContextLimitsCache before Anthropic hardcoded fallback#2837

Closed
anas-asghar4831 wants to merge 1 commit intocode-yeongyu:devfrom
anas-asghar4831:fix/anthropic-context-limit-cache-bypass
Closed

fix(context-limit-resolver): check modelContextLimitsCache before Anthropic hardcoded fallback#2837
anas-asghar4831 wants to merge 1 commit intocode-yeongyu:devfrom
anas-asghar4831:fix/anthropic-context-limit-cache-bypass

Conversation

@anas-asghar4831
Copy link
Copy Markdown

@anas-asghar4831 anas-asghar4831 commented Mar 25, 2026

Summary

  • resolveActualContextLimit() now checks modelContextLimitsCache first for all providers before falling back to provider-specific logic
  • Anthropic providers previously skipped the cache entirely, ignoring user-configured context limits from opencode.json

Fixes #2836

Problem

resolveActualContextLimit() had an early return for Anthropic providers that bypassed modelContextLimitsCache:

if (isAnthropicProvider(providerID)) {
  return getAnthropicActualLimit(modelCacheState) // ← cache never checked
}

This caused Claude Opus 4.6 (1M context, GA since March 2026) to report as 200K when used behind a proxy that doesn't return the context-1m beta header.

Fix

Check the config-populated cache first, then fall back to provider-specific defaults:

const cached = modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`)
if (cached) return cached

if (isAnthropicProvider(providerID)) {
  return getAnthropicActualLimit(modelCacheState)
}
return null

Changes

  • src/shared/context-limit-resolver.ts — Reorder resolution: cache → provider-specific → null
  • src/shared/context-limit-resolver.test.ts — Update test to validate cache is respected for Anthropic; add fallback test

Testing

  • Updated existing test: cache entry for Anthropic now returns cached value (was asserting 200K)
  • Added new test: no cache entry + 1M disabled → falls back to 200K default
  • Existing tests for aliases and non-Anthropic providers pass unchanged

Summary by cubic

Respect cached model context limits by checking modelContextLimitsCache before provider fallbacks in resolveActualContextLimit(). Fixes Anthropic models incorrectly reporting 200K when a cached 1M limit is configured from opencode.json.

  • Bug Fixes
    • Reordered resolution to: cache → provider-specific logic → null (for all providers).
    • Anthropic no longer bypasses the cache; tests updated for cached 1M and default 200K fallback.

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

…hropic hardcoded fallback

resolveActualContextLimit() skipped modelContextLimitsCache for Anthropic
providers, always falling back to the hardcoded 200K default. Users who
configured model context limits in opencode.json had their config silently
ignored for Anthropic providers.

Now checks the config-populated cache first for ALL providers, then falls
back to provider-specific logic only when no cached entry exists.

Fixes code-yeongyu#2836
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@anas-asghar4831
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Mar 25, 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.

No issues found across 2 files

Confidence score: 5/5

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

Auto-approved: Correctly prioritizes user-configured context limits for Anthropic providers, fixing a bug where they were bypassed, while maintaining identical logic for all other providers.


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@code-yeongyu
Copy link
Copy Markdown
Owner

Superseded by #2664 which was merged and addresses the same context-limit-resolver cache priority issue. The approach in #2664 also handles the Anthropic 4.6 vs older model distinction. Thanks @anas-asghar4831!

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.

bug: resolveActualContextLimit skips modelContextLimitsCache for Anthropic providers — hardcodes 200K

2 participants