Skip to content

Skip context-1m beta header for excluded models#130

Open
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:upstream/context-1m-skip
Open

Skip context-1m beta header for excluded models#130
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:upstream/context-1m-skip

Conversation

@constkolesnyak

Copy link
Copy Markdown
Contributor

Problem

Some Claude OAuth subscriptions reject the context-1m-2025-08-07 beta for specific models. Example: a session on claude-sonnet-4-6 returns

400 long context beta not yet available for this subscription

while the same subscription accepts the beta on claude-opus-4-8. The current global agent.context_1m: bool is all-or-nothing — turning it off to fix Sonnet kills the 1M context on Opus too. Affected sessions break entirely with context_1m: true until manually downgraded.

Fix

Add AgentConfig.context_1m_excluded_models: list[str] — case-insensitive substring match against the resolved model name. When context_1m=True, the beta header is sent for every model whose name does not match any entry.

agent:
  context_1m: true
  context_1m_excluded_models:
    - claude-sonnet-4-6

New helper AgentConfig.context_1m_enabled_for(model: str | None) -> bool drives both:

  1. Beta header decision at session start (engine.py: betas = ["context-1m-2025-08-07"] if context_1m_enabled_for(model) else [])
  2. max_context value 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-existing tests/test_cron.py::TestMaybeRotateContext rotate_at failures unrelated to this change — present on main too).

The helper is a pure function on AgentConfig; substring match + the context_1m global guard cover the matrix.

Files

  • nerve/config.pycontext_1m_excluded_models field + context_1m_enabled_for(model) helper
  • nerve/agent/engine.py — use the helper at the beta-header decision and at the max_context site

Generated with Claude Code

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>
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