Skip to content

fix: size the 1M context window for the bracket alias form (opus[1m]) - #302

Merged
saucam merged 1 commit into
mainfrom
fix/one-million-window-bracket-alias
Aug 25, 2026
Merged

fix: size the 1M context window for the bracket alias form (opus[1m])#302
saucam merged 1 commit into
mainfrom
fix/one-million-window-bracket-alias

Conversation

@saucam

@saucam saucam commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

The bug

contextWindowForModel matched only the -1m suffix, so the bracket form Claude Code actually emitsopus[1m], claude-opus-5[1m] — fell through to the conservative 200k default.

The result inverts caller intent: asking explicitly for the 1M variant sized the window worse than the bare alias.

model before after
opus[1m] 200,000 ❌ 1,000,000
sonnet[1m] 200,000 ❌ 1,000,000
claude-opus-5[1m] 200,000 ❌ 1,000,000
opus 1,000,000 1,000,000
haiku 200,000 200,000

How it surfaced

Found while investigating a real prompt is too long: 1000076 tokens > 1000000 maximum on a live session pinned to opus[1m], where codeoid computed a 200k window against ~999k of actual usage.

Blast radius (traced, not assumed)

Affected — the two production consumers of this function:

  • percent-of-window on SessionInfo (session.ts:2826) — reads ~500% occupancy
  • fork / provider-switch seed budget (seedBudgetChars via targetContextWindow) — 5× too small, so history seeds over-truncate

Not affected:

  • auto-rotatedecideRotation is passed the static Session.CONTEXT_WINDOW (hardcoded 1_000_000), not this per-model resolution. An earlier revision of this description claimed otherwise; that was wrong.

What this does not fix

It did not cause that overflow. The rotation path never consulted this value, and separately, under-sizing would make rotation fire earlier rather than later. The overflow has an independent cause — compaction firing reactively after the API error rather than proactively at a threshold — which is upstream SDK behavior and is being tracked separately.

Verification

lint + typecheck clean, 2370 pass / 0 fail. Four regression assertions on the bracket form including case-insensitivity, plus a haiku guard so a bracket suffix can't manufacture a 1M window where no such variant exists.

🤖 Generated with Claude Code

`contextWindowForModel` matched only the `-1m` suffix, so the bracket form
Claude Code actually emits — `opus[1m]`, `claude-opus-5[1m]` — fell through to
the conservative 200k default. Asking EXPLICITLY for the 1M variant therefore
sized the window WORSE than the bare `opus` alias, which resolves to 1M.

Observed on a live session pinned to `opus[1m]`: codeoid computed a 200k window
against ~999k of real usage. Affected consumers:

  - the percent-of-window figure on SessionInfo (session.ts) — reads ~500%
  - the fork / provider-switch seed budget (seedBudgetChars via
    targetContextWindow) — 5x too small, so history seeds over-truncate

Auto-rotate is NOT affected: decideRotation is passed the static
`Session.CONTEXT_WINDOW` (1M), not this per-model resolution.

This also did NOT cause the "prompt is too long" overflow seen on that session
— that has a separate cause (compaction firing reactively after the API error
rather than proactively). This is an independent defect surfaced while
investigating it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@saucam
saucam force-pushed the fix/one-million-window-bracket-alias branch from a03f15e to d1285f6 Compare August 25, 2026 04:36
@saucam
saucam merged commit 99bb2e8 into main Aug 25, 2026
4 checks passed
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.

2 participants