Skip to content

fix(models): advertise the context window Kiro actually serves - #137

Open
q8247990 wants to merge 1 commit into
tickernelz:masterfrom
q8247990:fix/context-windows
Open

q8247990 wants to merge 1 commit into
tickernelz:masterfrom
q8247990:fix/context-windows

Conversation

@q8247990

@q8247990 q8247990 commented Nov 3, 2026

Copy link
Copy Markdown

Problem

The registry advertises limit.context: 1_000_000 for the newer Claude models, but getContextWindowSize() returns 200_000 for every id without a -1m suffix. That split causes two different failures:

  • 5.x models: the service caps them at 600K, but every reported token count is computed as 200_000 * contextUsagePercentage / 100, i.e. ~2.75x too low. The context bar never approaches the limit, auto-compaction never fires, and the request eventually dies with Input is too long.
  • 4.6 models: these really are served at 1M, but they only exist as claude-opus-4-6 / claude-sonnet-4-6 (no -1m in the OpenCode-facing id), so their token counts are under-reported the same way.

Reported in #128, where the 166,512 plateau is 200_000 * 0.833% — the plugin's own 200K denominator, not the backend window.

Measurements

Method: grow a single generateAssistantResponse prompt, read the streamed contextUsagePercentage, keep growing until the service rejects it.

model 66,667 tok 400,000 tok 533,333 tok 600,000 tok implied window
claude-sonnet-4.5 38.75% — — 400 200K
claude-haiku-4.5 38.75% — — — 200K
claude-opus-4.6 7.75% 66.42% — 200 (800K: 88.4%) 1M
claude-opus-4.7 / 4.8 12.60% — — — 600K
claude-opus-5 12.67% 72.69% 96.67% 400 600K
claude-sonnet-5 12.66% 72.69% 96.66% 400 600K
claude-fable-5.1 12.75% — — — 600K
auto 12.60% — — — 600K

The 2.7M-char / ~600K-token request fails with CONTENT_LENGTH_EXCEEDS_THRESHOLD, confirming the 600K ceiling; 2.4M chars / ~533K tokens succeeds at 96.7%.

Fix

  • New src/plugin/context-windows.ts owns the measured table and is the single source for both the advertised limit.context and the percentage → token conversion. getContextWindowSize() now delegates to it.
  • MODEL_SPECS no longer carries a limit; buildModelRegistry() resolves it from the table, so the advertised window and the token math cannot drift again.
  • Expose claude-opus-4-6-1m / claude-sonnet-4-6-1m (with -thinking companions): the only ids actually served at 1M today.
  • Table entries for claude-opus-5-5 / sonnet-5-5 / fable-5-1 are already present so feat: add claude-opus-5.5, claude-sonnet-5.5 and claude-haiku-5.5 #136 gets the right caps once merged.

Notes

  • ListAvailableModels (the approach in feat(models): discover context windows from Kiro catalog #121) returns 403 Your subscription does not support this application on a Pro Max account, even with the exact headers that PR uses. Catalog discovery can only fall back to the heuristic there.
  • claude-sonnet-5-1m and claude-opus-4-7-1m are rejected with INVALID_MODEL_ID, so they are not advertised.
  • bun test 179 pass / 0 fail; tsc -p tsconfig.build.json clean.

Kiro advertises 1M for the 5.x Claude models but the Q layer caps them at
600K; 4.7/4.8 are capped too. The registry advertised 1M while
getContextWindowSize() returned 200K for any id without a `-1m` suffix, so:

- reported input tokens were ~2.75x too low on 5.x (the context bar never
  approached the limit and auto-compaction never fired), and
- even with correct token math, advertising 1M left ~400K of phantom
  headroom before `CONTENT_LENGTH_EXCEEDS_THRESHOLD`.

Measured 2026-11-03 by growing a single generateAssistantResponse prompt
until the service rejected it (2.4M chars / 533K tokens -> 96.7%; 2.7M
chars / 600K tokens -> 400 Input is too long):

  sonnet-4.0, sonnet/haiku/opus-4-5 : 200K
  opus-4-6, sonnet-4-6 (+ -1m)      : 1M
  opus-4-7/4-8, opus-5, sonnet-5,
  opus-5-5, sonnet-5-5, fable-5-1,
  auto                              : 600K

context-windows.ts becomes the single source for both the advertised
limit.context and the percentage->token conversion. Also expose
claude-opus-4-6-1m / claude-sonnet-4-6-1m, the only ids that are really
served at 1M today.
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