Skip to content

[PR] fix: identified sessions escape the preflight 413 dead-end (#4185) - #4188

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-22_clamp-forward-escape
Oct 22, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-22_clamp-forward-escape

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

(ai: zai/glm-5.3)

Fixes #4185. Branch: 2026-10-22_clamp-forward-escape (base fe5ba591).

Root cause

The #3146 fresh-session escape hatch (src/server.ts, if (unknownBaseline && !growthArmed)) keyed on unknownBaseline = anonymous && session.stats.lastInputTokens <= 0. The anonymous conjunct is a #553 trigger-side concern; dsh/codex/claude-code lanes stamp their own session ids, so their FIRST over-headroom request skipped the gate, hit the final fail-fast (413), and noteLocalRefusal (#3846) pinned every retry — the session was dead from message one (2026-10-21 raccoon incident: ~227K calibrated estimate vs the 192001 headroom target while payload + clamped output budget fit the 256000 native window).

Fix — three-arm arbitrate gate

const deterministicExhaustion = f?.kind === "exhausted" && f.deterministic;
const noUpstreamEvidence = session.stats.lastInputTokens <= 0 && statedWall <= 0 && deterministicExhaustion;
// outbound budget read from the prepared (already-clamped) body
const nativeFitAfterClamp = statedWall <= 0 && outboundBudgetTokens !== undefined
    && resolvedNativeWindow > 0 && outboundCalibrated + outboundBudgetTokens <= resolvedNativeWindow;
if ((unknownBaseline || noUpstreamEvidence || nativeFitAfterClamp) && !growthArmed) { /* #2490 doom → #3846 → forward once */ }

All arms keep the #2490 doomed-bytes 413, the #3846 local-refusal pin, and the growthArmed breaker.

Evidence

  • Red on master: test 1 of tests/issue4185-identified-fresh-forward.test.ts reproduces the incident 413 ("exceeds the model window … NOT forwarded") with the exact raccoon shape (identified session, giant protected tool result, fresh baseline); green with this patch (forwarded once, usage baseline settles).
  • 4 new tests: fresh-identified forward (arm2), armed-baseline forward with clamped max_tokens === 4096 (arm3), doomed-bytes still 413, genuinely-over-native still 413.
  • No regression: preflight-empty-summary 9/9, preflight-stream-summary-config 6/6, wire-exit-gap-cells 5/5, preflight-fork-estimate ([Bug] 新会话(无 usage 基线)preflight 把字符数当 token——折叠其实成功(2263796→1111212)却 fail-fast 502,上游实际只计费 540828 #3146) 2/2, codex e2e green (ACP_TEST_E2E=1).
  • Earlier revision (arm2 ungated) broke 8 relay-failure fail-fast tests; caught by re-running the full local matrix on both this tree and pristine master — fixed by the deterministicExhaustion gate above.

Non-goals

@ranxianglei ranxianglei changed the title fix: identified sessions escape the preflight 413 dead-end (#4185) [PR] fix: identified sessions escape the preflight 413 dead-end (#4185) Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-22_clamp-forward-escape (4f65ae3)

Option A — Install this exact build (recommended)

npm install -g [email protected]

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

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

Install instructions are refreshed on each push.

…tting clamped payload escape the preflight 413 dead-end (#4185)

The #3146 forward-once gate keyed on unknownBaseline, whose anonymous &&
excluded identified sessions (dsh/codex/claude-code all stamp a session id).
A fresh identified session whose request exceeded the headroom-adjusted
window with zero compressible ranges hit the final fail-fast: deterministic
413, #3846 pin, every client retry re-failing — the session was permanently
unusable from message one (2026-10-21 raccoon incident: ~227K est vs the
192001 headroom target while payload + clamped output fit the 256000 native
window).

The gate now takes three arms with unchanged internals (doom bytes #2490,
#3846 pin, forward once): unknownBaseline (original), noUpstreamEvidence
(identified but no usage baseline and no stated wall), and
nativeFitAfterClamp (the #453/#2096-clamped outbound body plus its declared
output budget fits the NATIVE window — the headroom reservation is policy,
not physics). Genuinely doomed bytes and payloads over the native window
still fail fast 413; both directions pinned.

Fixes #4185
@ranxianglei
ranxianglei force-pushed the 2026-10-22_clamp-forward-escape branch from b17fb1b to 43598f9 Compare October 21, 2026 16:51
awork added 2 commits October 22, 2026 01:12
…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.
…he identified-fresh escape (#4185)

The full-suite A/B on the merge ref found four more pins that assert the
local fail-fast contract for zero-evidence identified sessions in exactly
the shape the #4185 gate now escapes (deterministic exhaustion after
maximum folding): #2391 eager/loaded overflow stop-before-forward, #1841 A
futility skip, #3645 uncalibrated futility control, and #736 shrunken-window
fail-fast (main + no-override control). Each seeds a settled usage baseline
so it keeps testing the evidence-driven verdict; the new contract stays
pinned by tests/issue4185-identified-fresh-forward.test.ts.
@ranxianglei
ranxianglei merged commit 399c8bc into master Oct 22, 2026
50 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.736-master.399c8bc (rolling master tag).

npm install -g [email protected]  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant