Skip to content

fix: cap tier-gated registry windows at the standard window without tier evidence (#1321) - #1325

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-25_tier-window-cap
Sep 25, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-25_tier-window-cap

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

models.dev advertises the MAX window a tier-gated model id can serve (anthropic/claude-opus-5-5 → 1,000,000), but a plain subscription serves the standard 200K until the client negotiates otherwise — Claude Code sends the context-1m-* beta header only when it actually negotiated 1M. The warm registry peek outranks the built-in table by design (#344 fresher-source-wins), so a claude-native session on a standard subscription resolved to 1M and every nudge/emergency threshold sat up to 5× beyond the client's own wall: unreachable while Claude Code enforced 200K locally (#1310 item 2 → #1321).

Fix at the single decision point where all sources are adjudicated (src/server.ts native-window chain):

  • expandedContextSuffixWindow (src/server/context-window.ts): an [Nm]-suffixed model name (claude-opus-5-5[1m]) is now recognized as tier evidence, alongside the context-Nm beta header — same evidence class carried in the model id instead of a header. Resolved like the header: N × 1,000,000 clamped to MAX_ANTHROPIC_BETA_WINDOW.
  • capRegistryWindowByStandard: for TIER-GATED families only (/^claude-/i, src/config.ts TIER_GATED_FAMILIES + tierGatedStandardWindow), a registry-derived window above the built-in standard is capped back to the standard when the request carries no tier evidence. One info log line per model.
  • Applied to both registry sites (warm peek + async fetch); operator sources (per-model config, launcher windows, plugin report, runtime-info) are exempt — deployment-specific truth, never registry guesses.

Scope deliberately narrow: a blanket table-over-registry flip would pin every family at its stale table value — qwen (table 200k vs real 1M–10M), future gpt-5.x growth — violating #344/#852 (a stale-low table entry must never pin a grown registry window). Only families whose larger tier requires per-request negotiation are capped; for those the error direction is safe: capped worst case = over-compression (self-heals), uncapped worst case = dead sessions (#1310 lockout).

⚠️ Behavior change (old → new)

Case Before After
claude-*, no beta header / no [Nm] suffix, registry > 200k registry max (e.g. 1,000,000) built-in standard 200,000
claude-* with context-Nm-* beta header or [Nm] suffix header → N×1M; suffix unrecognized (fell through chain) unchanged / now N×1M
registry ≤ 200k for claude (e.g. hypothetical 128k entry) registry wins unchanged (fresher source)
non-claude families fresher-source-wins (#344) unchanged
operator per-model config / launcher / plugin windows outrank everything unchanged (exempt from cap)

Both compression modes reasoned: plugin-mode windows reported by the agent itself are exempt; proxy-mode claude-native (the reporter's posture) is the fixed path. The launcher-side chain (resolveLauncherWindow) already ranks the table over the registry — unaffected.

Tests

  • New tests/issue1321-tier-window-cap.test.ts: unit (suffix parsing incl. clamp/case/anchor edges; tierGatedStandardWindow family scoping; cap pass-throughs) + e2e through the real proxy pipeline (no-evidence → 200K; beta header → 1M; [1m] suffix → 1M; non-tier-gated control gpt-5.4 → 1,050,000 uncapped; [bug] claude native: stitched-stream usage double count after in-stream compress locks session ('Prompt is too long') — #300 variant #1310 symptom pin: 261,206-token session fires EMERGENCY again at the 200K window).
  • Updated tests/issue-393-registry-window.test.ts: the no-evidence claude→1M expectation flips to 200K (this PR's intentional change, documented in the file header); Fix-1 hostless-lookup coverage re-anchored on openai/gpt-5.4 (1,050,000 — only the registry can produce it, so the assertion still proves the lookup runs in --upstream mode); wire-mode recording test likewise switched to gpt-5.4 so it still proves the recorded number is fully resolved, not a hardcoded/table fallback.
  • A/B verified: with the cap temporarily reverted, the two regression pins fail exactly as the issue describes (window resolves to 1M; EMERGENCY suppressed at 261K).

Pre-flight (rebased head e8e1c05, master d4f630b)

  • npm run typecheck ✅
  • npm test ✅ 2581 tests, 0 fail, 10 skipped (gated e2e)
  • npm run build ✅
  • Real-client e2e-codex: skipped locally (local upstream unreachable from this environment); CI runs it automatically — this diff touches src/server.ts (hot-file trigger).

Fixes #1321

…ier evidence (#1321)

models.dev advertises the MAX window a tier-gated model id can serve
(anthropic/claude-opus-5-5 -> 1,000,000), but a plain subscription serves
the standard 200K until the client negotiates otherwise. The warm registry
peek outranks the built-in table by design (#344 fresher-source-wins), so a
claude-native session without the context-1m beta header resolved to 1M and
every nudge/emergency threshold sat up to 5x beyond the client's own wall
(#1310 item 2).

- recognize [Nm]-suffixed model names as tier evidence, alongside the
  context-Nm beta header (expandedContextSuffixWindow)
- cap registry-derived windows at the built-in standard window for
  tier-gated families (claude-) when no tier evidence is present
  (capRegistryWindowByStandard); operator sources stay exempt, other
  families keep fresher-source-wins (#344/#852)
- one info log line per capped model

Behavior change: claude-* requests WITHOUT a context-Nm beta header or [Nm]
suffix now resolve to the built-in standard window (200K) instead of the
registry-advertised max when the latter is larger. WITH evidence, or for
non-claude families, resolution is unchanged.

Fixes #1321
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_tier-window-cap (e8e1c05)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1325

Each push to this PR publishes a new version under the pr-1325 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1325.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。这是本账号已完成的 PR(分支 2026-09-25_tier-window-cap,head e8e1c05e,base master d4f630b7,Fixes #1321)——不重做,现在做收尾核验:拉取分支核对代码、查 CI 状态,结论稍后回帖。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Verification complete. This is the account's own completed PR, so per the own-PR rule I did NOT redo the work — I fetched branch 2026-09-25_tier-window-cap @ e8e1c05e, reviewed the diff against current master, ran targeted local verification, and confirmed CI.

① Issue direction (#1321): verified. Without tier evidence, models.dev reports 1M for Claude tier-gated models (bundled snapshot: anthropic/claude-opus-5 → 1,000,000) while the standard window is 200K (#393). The proxy used the registry max as its compression denominator → budget misalignment and #1310-class emergency compressions. The fix addresses the root cause (registry value consumed without a tier check) at the decision point in src/server.ts, not a downstream mask.

② Regression audit — existing behavior of touched paths:

  • lookupContextLimit refactored onto shared modelRoots(): semantics preserved (full-name precedence over basename, 窗口溢出报错 #736) — held.
  • Registry peek + async fetch: capped ONLY when ^claude-/i family AND no tier evidence (anthropic-beta header or [Nm] suffix) AND registry > standard. Non-claude families untouched (control test: gpt-5.4 → 1,050,000) — held except the intended change below.
  • Operator sources (plugin report / runtime info / launcher window / configured limit): exempt from the cap — held.
  • Launcher chain (resolveLauncherWindow, src/launcher.ts:902): untouched; the table already outranks the registry there — held.
  • nativeFromFallback cleared by suffix evidence exactly like the beta header — consistent.
  • Additive only: wsSource gains "model-suffix"; one info log per capped model (model name only, no secrets).
  • No config schema / persistence / wire-shape / acp-kernel pin / update.ts changes; both compression modes unaffected (window resolution precedes mode-specific injection).

③ Code: single linear commit (+415/−26, 5 files). Cap logic is a pure function with pass-throughs for undefined / has-evidence / sub-standard inputs; per-model log dedup via module-level Set. Suffix parser anchored, case-insensitive, clamped to MAX_ANTHROPIC_BETA_WINDOW, rejects [0m]/[m]/mid-id markers.

④ Test validity: real teeth. E2E through the actual proxy: no-evidence claude → effectiveContextLimit 200,000 (would be 1M pre-fix); beta header and [1m] suffix both unlock 1M; control gpt-5.4 stays uncapped at 1,050,000; and the #1310 symptom pin — a measured 261,206-token input now fires EMERGENCY ("Context limit reached") at 131% of the 200K window, where pre-fix it silently rode a 1M denominator. The updated issue-393 expectations document the intentional flip in-file.

⑤ Diff cleanliness: every line serves the fix; no unrelated churn, no lockfile/generated noise.

Behavior change (old → new):

CI at head e8e1c05e: all 11 checks green (test ubuntu/windows × 22/24, e2e, hermetic registry e2e, real codex + pi lanes, build-artifact, version-guard). Base d4f630b7 == current master — no rebase needed. Local: typecheck ✅, build ✅, both PR test files 14/14 ✅.

Verdict: ready to merge. I can't merge PRs — system rules forbid it. Please merge yourself: #1325

一句话中文摘要:修复了无 tier 证据时 claude-* 模型误用 models.dev 报告的 1M 窗口做压缩分母(标准窗口实为 200K,导致预算错位与 #1310 紧急压缩)的问题——现在无证据时回落到内置标准窗口,有 beta 头或 [Nm] 后缀时仍按 1M,其余路径行为不变;CI 全绿、本地验证通过,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Coexistence verification on current master head: both this and the sibling claude-native estimation PR (#1325/#1326) cherry-picked cleanly onto today's master and pass the full gate together — typecheck ✓ / 2608 tests 0 fail (10 e2e-gated skips) / build ✓. Shared-file regions are disjoint (window resolution vs prepareAnthropic thinking projection), any merge order works.

@ranxianglei
ranxianglei merged commit c224c78 into master Sep 25, 2026
11 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,并独立复核了一遍——结论一致:两个 PR 可共存、任意顺序合并均可。

补充我这边的独立验证(你的 cherry-pick 报告之外):

无额外动作需要我做;PR 保持 open 等你合并(合并按系统规则只能由人执行):#1325

一句话中文摘要:master 前进后(新增 kernel 0.0.91 等)我用真实 merge 模拟重新验证了本 PR 与新 master 零冲突且全部门禁通过,确认与兄弟 PR 任意顺序可合并,无需我再改动,等你人工合并即可。

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] window resolution: registry 1M advertisement outranks built-in 200k standard window for claude native without context-1m beta header

1 participant