Repository navigation
[PR] fix: remember local preflight 413 refusals so estimate demotion cannot reopen oversized forwards - #3867
Conversation
… reopen oversized forwards (#3846) A locally refused over-window request (deterministic exhaustion -> 413, payload never forwarded) was re-forwarded on retry once the usage baseline demoted to an estimate (preflight-rebuild anchor or failure shrink): probeForEvidence saw baselineFloor=0, ran BEFORE the #726 dead-end check, and forwarded once for 'evidence' - billing the full payload upstream. Growing bodies also defeated the dead-end body-hash key, so every turn re-probed (prod: 606K/620K/633K input tokens, 32K cached each). - noteLocalRefusal() records {origin,model,window} at all three local-413 sites (probe doomed-bytes gate, fresh-session doom gate, final deterministic-exhaustion fail-fast); plain JSON in session.metadata, capped at 16 records, deduped per scope keeping the widest window; survives restart via existing metadata persistence. - localRefusalCovers() suppresses the four forward-once escapes (estimate-only probe, image arbitration immediate+post-fold, #1839 rebuilt-view divergence, #3146 fresh-session escape) at the same or tighter window for the same origin+model. Fitting payloads still forward; other origin/model/larger-window evaluated independently. Evidence is NEVER written into lastInputTokens/Source (it is not upstream usage). No config surface added; kernel untouched.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4568-pr.3867.2ba9827This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3867.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。open+closed 全量检索(按失败签名: local 413 / estimate demotion / forward-once / 标签: 本 PR 是处理 #3846 的 daemon 会话交付的工作(单 commit |
(ai: vllm-qwen/qwen3.8-27b) PR #3867 独立审核结论(不照抄 issue/提交侧八问,以下为审核侧独立重做:拉分支逐行读 diff、对照当前 master、本地 A/B 实测、测试有效性审查) 结构化八问
独立验证证据(非转述 PR 声明)
CI 现状(重要,非本 PR 之过)head f5af0dc 的运行:9 job 绿、2 job 红(
处置(按几行级小修纪律):已开修复 PR #3877(两个标注 commit:去掉 export + 提交重新生成的索引,共 5 行/3 文件,本地验证门绿 + tsc 绿),并立 [no-dispatch] 跟踪 issue #3878(查重:无)。#3877 合并后请 update/re-run 本 PR,即可拿到全量套件的最终裁决。 判定代码审核通过、行为变更已披露、回归面逐项审毕——可合;唯一待办是等 master 红修复(#3877)合入后的全量 CI 绿灯。人工合并(行为变更档)。 |
Closes #3846
The bug
A locally refused over-window request (deterministic exhaustion → local 413, payload never forwarded) was re-forwarded on retry once the usage baseline demoted to an estimate — which a preflight rebuild does (
src/server.tsanchor demotion:rebuiltTextSize > lastInputTokens→source="estimate") andarmFailureShrinkalso does. On retry,probeForEvidencesawbaselineFloor = 0, ran before the #726 dead-end check, and forwarded the payload once "to acquire usage evidence" — billing the full payload upstream. The #726 dead-end cannot save it: its key ismodel␀limit␀sha256(inboundBody), and growing bodies (prod session: 606524 → 620664 → 633349 input tokens, only 32768 cached each) defeat the hash every turn. The local refusal verdict — independent evidence that this payload does not fit that window — evaporated with the baseline's source label.The fix (host-only,
src/server.ts)noteLocalRefusal(session, origin, model, window)at all three local-413 sites — the probe doomed-bytes gate, the fresh-session doom gate, and the final deterministic-exhaustion fail-fast. Stored as plain JSON insession.metadata.localRefusals({origin, model, window, at}[], capped at 16 records, deduped per scope keeping the widest window). Persists across restarts through the existing metadata persistence; survives the JSON round-trip.localRefusalCovers(metadata, origin, model, window)matches on both origin and model equal AND recorded window ≥ current limit (same-or-tighter coverage only). When covered, the four forward-once escape hatches are suppressed:The doomed-bytes sub-gates still run (a doom-sized payload still gets an immediate 413).
Fitting payloads still forward everywhere; another origin, model, or a larger window is evaluated independently (probe stays open). The refusal evidence is never written into
lastInputTokens/lastInputTokensSource— it is not upstream usage and must not masquerade as one.Behavior changes (old → new)
No config surface added (no new env var / config key / CLI flag). Kernel untouched. No persistence-format change beyond the additive
metadata.localRefusalsarray.Interaction with PR #2928
#2928 (open, reviewed mergeable) restructures the doomed branch inside the probe gate (foldable → fold first, blob → terminal 502). This PR's edits there are additive — record at the 413 site, suppression inside the probe branch — and orthogonal in intent. If #2928 lands first, expect a small textual conflict on rebase; resolve by union of intent (both changes compose cleanly).
Tests
New
tests/issue3846-local-refusal-evidence.test.ts— 4 hermetic e2e tests (counting fake upstream, 20K-token window, non-foldable ~400KB system text):lastInputTokens/Sourceuntouched by the fix (estimate stays estimate), exactly one scoped refusal record.A/B verified against unpatched master (stash → run → pop): tests a/b fail pre-fix with
expected 413, actual 200(the exact reported symptom); c/d fail on the new evidence-channel assertions. Post-fix: 4/4 green.Adjacent suites pass locally (targeted runs):
issue2313-probe-forward,issue2490-ledger-floor-doomed-probe,issue1800-image-arbitration-compress,issue1839-ghost-denominator,issue496-forward-once-learn,preflight-fail-fast,preflight-compress— 26/26. Full-suite verdict is CI.