Skip context-1m beta header for excluded models#130
Open
constkolesnyak wants to merge 1 commit into
Open
Conversation
Some Claude OAuth subscriptions reject the context-1m-2025-08-07 beta for specific models (e.g. claude-sonnet-4-6 returns 400 "long context beta not yet available for this subscription"), which broke any session running on those models even with context_1m=True. Add AgentConfig.context_1m_excluded_models (case-insensitive substring match on the resolved model name) and a context_1m_enabled_for(model) helper. The helper drives both the beta-header decision and the max_context value used for context-bar usage metadata, so excluded models report the correct 200k ceiling in the UI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some Claude OAuth subscriptions reject the
context-1m-2025-08-07beta for specific models. Example: a session onclaude-sonnet-4-6returnswhile the same subscription accepts the beta on
claude-opus-4-8. The current globalagent.context_1m: boolis all-or-nothing — turning it off to fix Sonnet kills the 1M context on Opus too. Affected sessions break entirely withcontext_1m: trueuntil manually downgraded.Fix
Add
AgentConfig.context_1m_excluded_models: list[str]— case-insensitive substring match against the resolved model name. Whencontext_1m=True, the beta header is sent for every model whose name does not match any entry.New helper
AgentConfig.context_1m_enabled_for(model: str | None) -> booldrives both:betas = ["context-1m-2025-08-07"] if context_1m_enabled_for(model) else [])max_contextvalue used for context-bar usage metadata (so excluded sessions report the right 200k ceiling, not the 1M one)Empty list keeps the existing all-or-nothing behaviour — no behaviour change for users who don't set the new field.
Tests
Existing test suite stays green:
1151 passed, 2 skipped(excluding pre-existingtests/test_cron.py::TestMaybeRotateContextrotate_at failures unrelated to this change — present onmaintoo).The helper is a pure function on
AgentConfig; substring match + thecontext_1mglobal guard cover the matrix.Files
nerve/config.py—context_1m_excluded_modelsfield +context_1m_enabled_for(model)helpernerve/agent/engine.py— use the helper at the beta-header decision and at themax_contextsite