Skip to content

fix: name the operator-shrunk window in preflight fail-fast errors - #737

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-13_failfast-window-shrink-hint
Sep 20, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-13_failfast-window-shrink-hint

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

When preflight compression cannot bring an over-window payload under the window, the fail-fast error ends with "Raise the model context window or restart the session to recover." — which sends operators to the upstream when the actual wall is bili's own compress.modelContextLimit setting.

#736 is exactly that misdirection in the wild: the log shows [window] source=table-or-registry native=128000 effective=16000 — the model's registered window is 128K and the local upstream demonstrably served it (an earlier turn of the same session reported 82022 input tokens; a sibling session was billed at 16589) — yet every fail-fast only ever said "raise the model context window", while the ceiling was a compress.modelContextLimit: 16000-style override edited into the web UI minutes before the brick.

This change threads the resolved native window + shrink reason (operator / codex) from the per-request window-resolution block into preflightCompressIfNeeded, and when effective < native the fail-fast message now adds:

  • operator case: "Note: bili's effective window 16000 is below the model's full window 128000 — your compress.modelContextLimit setting overrides it; if the upstream actually serves the larger window, raise or remove that setting (hot-reloaded, no session restart needed)."
  • codex case: the note names the codex align instead, with the explicit-opt-out pointer.

Also normalizes the doubled period at the detail seam (...recover.. → ...recover.), visible verbatim in the #736 log.

Why not just docs

The message is the only surface an operator sees at the moment of failure; the #736 thread shows how far "raise the model context window" leads when the registry already knows the true window. The hint is emitted only when bili itself shrank the window below the resolved native value, so it can never point at a setting that isn't the cause (output-headroom reservation and self-heal paths leave windowShrinkReason unset → no note).

Tests

New e2e in tests/preflight-fail-fast.test.ts: incompressible payload under an operator-shrunk 4k window (model declares 10k) → 502 message names both numbers and compress.modelContextLimit; negative control without the override asserts no note. Harness startProxy gained an optional compress-overrides param.

Pre-flight: npm run typecheck clean · npm test 1430 pass / 0 fail / 2 skipped (E2E-gated) · npm run build OK.

Fixes #736

@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-13_failfast-window-shrink-hint (8db98fd)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-737

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei mentioned this pull request Sep 13, 2026
ranxianglei pushed a commit that referenced this pull request Sep 13, 2026
… compare

#737 review of the #736 operator-shrunk-window hint: the note was gated on
`limit < resolvedNativeWindow`, but the per-request output-headroom reservation
(reserveOutputHeadroom = window - max_tokens) ALSO lowers reqConfig.modelContextLimit
below native for every non-Anthropic turn with a max_tokens — with no operator
setting involved. Comparing alone therefore emitted "your compress.modelContextLimit
setting overrides it" for a reduction the operator never made, contradicting the
stated invariant that the hint "can never point at a setting that isn't the cause".

Gate on windowShrinkReason (set ONLY by the operator-override and codex-align paths).
Adds an OpenAI-chat regression test: an incompressible payload under a headroom-shrunk
window must NOT carry the shrink note. Verified the old gate produced the false note
and the new gate does not.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Reviewed PR #737. Diff is clean (single commit, 2 files, focused). I found one real correctness bug, reproduced it, and fixed it directly on the branch — please merge the follow-up commit, not just the original.

Bug: the shrink note fires for output-headroom reductions the operator never made

The note was gated on limit < resolvedNativeWindow:

const shrinkNote = resolvedNativeWindow !== undefined && limit < resolvedNativeWindow
    ? ` Note: bili's effective window ${limit} is below the model's full window ${resolvedNativeWindow} — ... your compress.modelContextLimit setting overrides it ...`

But limit (= reqConfig.modelContextLimit) is lowered below native by the per-request output-headroom reservation (reserveOutputHeadroom = window - max_tokens, applied at src/server.ts:1548-1562) for every non-Anthropic turn with a max_tokens — no operator setting involved. So comparing alone emits the "your compress.modelContextLimit setting overrides it" note for a reduction the operator never made. That contradicts the PR's own invariant: "it can never point at a setting that isn't the cause (output-headroom reservation and self-heal paths leave windowShrinkReason unset → no note)."

Reproduced under the original gate (OpenAI-chat endpoint, model declared 10k, no override, max_tokens: 4000, incompressible protected tool result):

context ~15032 tokens exceeds the model window 6000 (model=gpt-small) ... Raise the model context window or restart the session to recover.
Note: bili's effective window 6000 is below the model's full window 10000 — your compress.modelContextLimit setting overrides it; if the upstream actually serves the larger window, raise or remove that setting ...

The operator never set compress.modelContextLimit; the 10000→6000 drop is pure headroom reservation. The message sends them to edit a setting they never touched.

Root cause / layer

The window can fall below native through several independent mechanisms. Only two mean "bili deliberately told you this is your wall": the operator override and the codex align — and those are exactly what windowShrinkReason records. Headroom reservation and self-heal are internal accounting, not an operator wall. The original code conflated "window is smaller than native" with "an operator/codex decision made it smaller."

Fix (pushed — commit 2da365b)

Gate the note on the deliberate-shrink signal instead of the raw comparison:

const shrinkNote = windowShrinkReason !== undefined && resolvedNativeWindow !== undefined && limit < resolvedNativeWindow

windowShrinkReason is set only by the operator-override path and the codex-align path, so the note now fires exactly when bili shrunk the window on purpose — matching the documented intent, in both compression modes (this shared failFast path serves proxy and plugin/launcher alike).

Added a regression test (tests/preflight-fail-fast.test.ts): an OpenAI-chat incompressible payload under a headroom-shrunk window asserts the reported window is 6000 (proves the headroom path ran) and that the message contains neither full window nor compress.modelContextLimit. The existing Anthropic-only #736 test couldn't catch this — Anthropic is exempt from headroom reservation, so its negative control never exercised the buggy branch.

Pre-flight (on the fixed branch)

  • npm run typecheck — clean
  • npm test — 1431 pass / 0 fail / 2 skipped (E2E-gated)
  • npm run build — OK
  • Verified old gate reproduces the false note; new gate silences it.

Everything else in the original PR looks sound: resolvedNativeWindow = native is captured at the right point (fully-resolved native before any reduction), the codex/operator branch split is mutually exclusive, and the detail.replace(/\.\s*$/, "") period normalization correctly fixes the ...recover.. seam seen in the #736 log without over-stripping other failFast details.


中文摘要:修复了 #736 提示误报——原实现仅按"有效窗口 < 原生窗口"判断就提示"你的 compress.modelContextLimit 覆盖了窗口",但非 Anthropic 请求的输出预留(headroom)也会把窗口压低、与算子设置无关,导致误导用户去改一个没动过的配置;已改为仅在 bili 主动缩窗(operator/codex)时提示并补了 OpenAI 回归测试,已推到分支(commit 2da365b),可合并。

ework-agent added 2 commits September 20, 2026 00:55
… compare

#737 review of the #736 operator-shrunk-window hint: the note was gated on
`limit < resolvedNativeWindow`, but the per-request output-headroom reservation
(reserveOutputHeadroom = window - max_tokens) ALSO lowers reqConfig.modelContextLimit
below native for every non-Anthropic turn with a max_tokens — with no operator
setting involved. Comparing alone therefore emitted "your compress.modelContextLimit
setting overrides it" for a reduction the operator never made, contradicting the
stated invariant that the hint "can never point at a setting that isn't the cause".

Gate on windowShrinkReason (set ONLY by the operator-override and codex-align paths).
Adds an OpenAI-chat regression test: an incompressible payload under a headroom-shrunk
window must NOT carry the shrink note. Verified the old gate produced the false note
and the new gate does not.
@ranxianglei
ranxianglei force-pushed the 2026-09-13_failfast-window-shrink-hint branch from 2da365b to 8db98fd Compare September 19, 2026 16:57
@ranxianglei
ranxianglei merged commit 25ccc40 into master Sep 20, 2026
8 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-13_failfast-window-shrink-hint branch October 15, 2026 05:32
ranxianglei pushed a commit that referenced this pull request Oct 21, 2026
…e identified-fresh escape (#4185)

The widened #3146 gate forwards zero-evidence identified sessions once for
upstream arbitration when the exhaustion is DETERMINISTIC (nothing compressible
left after maximum folding) — exactly the #4185 shape. Two preflight-fail-fast
pins are that shape (#301 nothing-compressible 413, #737 headroom-shrunk
nothing-compressible 413); they now seed a settled usage baseline so they keep
pinning the evidence-driven verdict while
tests/issue4185-identified-fresh-forward.test.ts owns the new contract.
Relay-dependent failure pins (429'd / empty / truncated summaries, gateway 524)
stay on the classic fail-fast path and need no seeding — verified per file.

No source changes. Verified: full preflight family + issue2313/3846/3918 +
context-overflow + anthropic-beta-window + issue4185 suites green except four
pre-existing master failures tracked in #4194.
ranxianglei pushed a commit that referenced this pull request Nov 13, 2026
…ive input budget 7500', not 'model window 7500'

The #3663 change (buildEffectiveWallClause) intentionally relabels a
headroom-reserved wall from 'the model window N' to 'the effective input
budget N (model window NATIVE, ... reserved ...)'. The pre-existing #737
e2e in tests/preflight-fail-fast.test.ts still asserted the old substring
'model window 7500', which no longer appears — the message now reads
'the effective input budget 7500 (model window 10000, 2500 tokens
reserved ...)'. The test's intent (prove the headroom path was exercised:
the cited wall is 7500, not the declared 10000) is preserved by asserting
the new substring; the other #737 guards (no shrink note, no
compress.modelContextLimit blame) are unchanged and still hold.
sauyler pushed a commit to sauyler/billion-context that referenced this pull request Nov 23, 2026
…rd, and let the upstream's own verdict be authoritative (ranxianglei#7537)

Owner ruling 2026-11-22 (issue ranxianglei#7537, KDD ranxianglei#19/ranxianglei#20): every LOCAL estimate-
based 413 refusal is a product of bili's local guess multiplied by a window
value that is itself often wrong (fallback windows ranxianglei#7205). Their product
silently killed requests that would have succeeded (the ranxianglei#7167/ranxianglei#7382/ranxianglei#2490/
ranxianglei#2847/ranxianglei#2847/ranxianglei#736/ranxianglei#737/ranxianglei#4079 family).

- server.ts: the four local size-413 sites (probe doom gate, ranxianglei#1839 measured
  gate, post-fold measured/doom-bytes gates, deterministic-exhaustion
  mapping) now FORWARD with the local measurement logged as evidence.
  Relay-side refusals keep their status: summary relay down -> 502, relay
  429 -> 503. The BILI_MAX_MESSAGES count gate and the 5GiB byte cap are
  exact resource guards and stay.
- relay.ts: the egress window fuse's two size gates log a profile and
  forward; a NEW upstream size-verdict annotation (413 / size-keyword 400)
  logs bili's own measurement, marks the response x-bili-retryable: false
  and merges a bili_evidence block into JSON error bodies so status-driven
  hosts do not retry-loop an unchanged body.
- server.ts: NEW evidence-backed loop guard — an outbound body that already
  drew an upstream size verdict (SHA-1 scoped, 10-min TTL) is refused
  locally as a byte-identical resend (ranxianglei#496 family); changed bodies and the
  identity fast path re-forward freely.
- The window-shrink note now rides the forward warns (the 413 fail-fast it
  decorated is gone); the duplication profile moved onto the over-window
  forward.
- AGENTS.md KDD ranxianglei#19 + reference/design-decisions.md ranxianglei#20 record the ruling.
- Tests: NEW tests/issue7537-preflight-passthrough.test.ts (3); re-pinned
  issue1841/2490/2847/3645/4079/4185/preflight-fail-fast to passthrough
  semantics; tests/issue3846-local-refusal-evidence.test.ts deleted (the
  local refusal it pinned no longer exists — the loop guard replaces it).

Supersedes PR ranxianglei#7507 (whose two new gates no longer need to exist under
this ruling). Refs ranxianglei#7537 ranxianglei#7507 ranxianglei#7167 ranxianglei#7382 ranxianglei#2490 ranxianglei#2847 ranxianglei#736 ranxianglei#737 ranxianglei#4079
ranxianglei#4543 ranxianglei#1841 ranxianglei#3645 ranxianglei#496 ranxianglei#3846 ranxianglei#3461 ranxianglei#5000
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