You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Preflight: trigger object (wire resend) != fold object (kernel state) — converged folds can still fail-fast 502 on protected-heavy resends (remaining half of #1933 Evidence D) #1950
Split from #1933 (its most severe symptom, not fixed by PR #1940 — that PR fixes the premature-trigger caliber (F1 calibration) and the cross-provider baseline residue (F2), and softens the budget (F3); this issue tracks what remains). Review context: #1940 (comment)
Defect
The preflight gate measures the wire payload (what the client actually resent — for DSH, the full raw history every turn), while the folder can only compress ranges the kernel session state marks compressible. When the two views diverge sharply, preflight folds everything it is allowed to fold, still cannot get under the window, and returns a hard 502:
In the incident, ~91% of the resend sat in protected spans (recent band, tool results), so 12 foldable ranges only removed 9%. No budget size converges that payload — PR #1940's F3 (16→32 calls) softens but cannot fix this class.
Why it was deferred
The remaining remedies are behavior/product decisions, not mechanical fixes:
Forward-with-warning — trade a deterministic local 502 for an upstream-arbitrated attempt. The fail-fast exists deliberately (breaks the 多模态会话上下文控制失效 + preflight 救援 502(codex responses store:false) #488 400 re-forward loop); blindly forwarding reintroduces that class.
Fold the wire view — relaxing the protection regime for such requests touches preflight's core admission rules.
Suggested fix (B, from the review)
Generalize the existing #496 forward-once-then-learn pattern from the image lane to the preflight-convergence-failure path: when preflight exhausts its budget and the route holds positive evidence that its real billing scale is smaller than the local estimate (a settled usage baseline, or a published #1940 calibration factor k̂ making the calibrated estimate fit), forward once with a loud warn header/log:
upstream accepts → the session learns the scale (k̂ ring / baseline) and the false-positive class self-heals next turn;
The 502 then remains only for payloads with no supporting evidence — i.e. genuinely unserviceable ones.
Repro sketch
compress.modelContextLimit = 256000 on a native-1M model via an OpenAI-compatible relay whose real billing runs well below chars/4 (per DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933 Provider A: 1.3–2.5×);
grow the client history so the raw resend estimate lands ≫ limit while most messages sit in protected spans;
observe fail-fast 502 with budget ... exhausted even though the provider previously billed far under the window.
Env: observed on v0.1.180 (DSH profiles/web, session-48d5aa49-…, 2026-10-02 13:30–13:35).
Activity
ranxianglei commentedon Oct 3, 2026
[bot] 🏷
结论先行(判读 + 建议,尚未开工):缺陷我已在代码里核实成立;方案 B 方向正确,但它带一个硬依赖和一个必须你拍板的行为变更点,所以我先不直接动手,把核实结果和落地路径摆清楚,等你的 go/no-go。
一、是什么问题
preflight 闸门量的是 wire 视角(客户端实际重发的整包 payload),而折叠只能压 kernel 会话状态里标为可压缩的区间。两视角严重背离时——DSH 这类每轮重发全量原始历史、且 ~91% 落在保护带(recent band + tool results)——preflight 把允许折的都折完仍下不了窗口,就 fail-fast 502。预算给多大都救不了,因为保护内容在结构上不可折。
代码印证(当前树):触发/fit 全程用
outboundPayloadBreakdown()的 wire 估算(src/server.tspreflightCompressIfNeeded,payloadEstimate = estimateCoreMessages + overhead + imageTokens);折叠走src/preflight.ts的保护区间遍历;预算耗尽 →failure.kind = "exhausted"→ 末尾failFast(status, …)(server.ts:5236-5238一带)返回 502。二、什么原因导致的(分层)
tokenCount/textChannel/ post-foldfits/ per-roundroundText全改走applyEstimateCalibration)、F2 按路由 provenance 降级跨 provider 基线(lastInputTokensOrigin)、F3 折叠预算 16→32 随超窗比放大。这些让闸门不再被系统性偏高的 chars/4 误触发,但不改 kernel 认为哪些区间可折。三、方案 B 的评估(三点要钉死)
calibratedEstimate/calibrationRing/applyEstimateCalibration()目前只在本地未合并的pr-1940分支上,master 没有。B 只有等 fix(preflight): calibrate local estimates against provider usage, provenance-gate the baseline, scale the fold budget (#1933) #1940 落地才有这套机制可用。今天 master 上能用的只有更弱的「settled usage 基线」(lastInputTokensSource==="usage"+ [OpenCode v2] Configured model context limit never reaches the proxy (x-bili-plugin-context-window not stamped) - silent registry-peek fallback suppresses proactive nudge and misfires emergency shrink #1569 的lastUsageGradeTokens锚,src/cache-ledger.ts:497-503):单标量、无路由 provenance、无 plausibility 边界——正是 fix(preflight): calibrate local estimates against provider usage, provenance-gate the baseline, scale the fold budget (#1933) #1940 F2 要修的那类残留。四、落地路径(我的明确建议,不是选择题)
preflightCompressIfNeeded末尾、failFast(...)之前(result.failure.kind === "exhausted"且 payload 仍过窗处,当前树server.ts:5231-5248)。加一个 last-resort 逃逸:满足「预算耗尽 + 有证据该路由按更低尺度计费 + 一次性标记未用过」→return prepared(前向一次,loud warn header/log),并置一个内存态一次性标记(仿 「BUG」sideRequestGuard 会永久拦截进程内第三方插件的 LLM 调用,导致与MemOS冲突 #1110overflowArmTokens/ [Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726deadEndKey,按请求指纹 key)。settleUsageReport(cache-ledger.ts:486)→ k̂ 环加固 + usage 级基线,下一轮自愈;上游拒绝(overflow)→ 现有armOverflowShrink(「BUG」sideRequestGuard 会永久拦截进程内第三方插件的 LLM 调用,导致与MemOS冲突 #1110/任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839,server.ts:5640区)把 lastInputTokens 顶高并置 source,下一轮照旧 fail-fast。前向一次性、有证据门槛、拒绝即 re-arm,多模态会话上下文控制失效 + preflight 救援 502(codex responses store:false) #488 环保持断。五~七(回归 / 缓存 / 设计方向 / 新配置)
需要你拍板三件事:① go/no-go(502 → 一次有证据前向);② 闸门口径(只取 k̂-fit,还是加上「同路由近期窗口内真实 usage」这条更宽判据——我推荐后者,否则救不到事故类);③ 确认顺序(先 #1940 后 follow-up)。
拍板后我即按此路径出 follow-up PR(叠在 #1940 之上),PR 描述写清行为变更 旧→新 与回归清单。
(注:以上行号基于当前 worktree 所基于的旧 master;实际开工会先 rebase 到最新 master,行号会平移,以函数名为准。)
ranxianglei commentedon Oct 3, 2026
关闭,不做方案 B。
定性:
compress.modelContextLimit是运营的硬契约,不是可被上游真实容量否决的提示。保护内容累积到超过配置窗口 → 会话寿终正寝是设计内行为:fail-fast 502 + 行动指引(调高/移除设置)就是设计的死亡方式,不是缺陷。事故里上游"能收下"不构成绕过运营配置的理由——运营设 256K 可能就是成本上限。方案 B 否决:有证据前向一次 = 绕过运营配置继续跑(上游慷慨就永久超窗),把配置上限变成废纸,不做。
唯一真实的残留不归本 issue:死亡过程太贵(保护地板>窗口可在 walk 前算出,却烧了 5 分钟 + 32 次摘要调用)——由 #1851(preflight futility gate)处理,该 PR 继续走。