Skip to content

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

Closed as not planned

Description

@ranxianglei

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:

13:30:46.514 processTurn: 681 msgs            (client resent 13.1 MiB raw history)
13:30:46.581 context 1518355 tokens reached preflight target 256000
13:30:56.275 [acp-compress-obs] shrink 9% (~4588/50235 tok)   (fold view: 50K)
13:35:38.005 [error] preflight fail-fast 502 ... context ~624698 tokens ... 1 compressible range(s) still visible ... budget exhausted ... NOT forwarded

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:

  1. 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.
  2. Emergency truncation — deliberately dropping content = data-loss semantics, owner sign-off territory.
  3. 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:

The 502 then remains only for payloads with no supporting evidence — i.e. genuinely unserviceable ones.

Repro sketch

  1. 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×);
  2. grow the client history so the raw resend estimate lands ≫ limit while most messages sit in protected spans;
  3. 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

  1. ranxianglei commented on Oct 3, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷

    结论先行(判读 + 建议,尚未开工):缺陷我已在代码里核实成立;方案 B 方向正确,但它带一个硬依赖和一个必须你拍板的行为变更点,所以我先不直接动手,把核实结果和落地路径摆清楚,等你的 go/no-go。

    一、是什么问题

    preflight 闸门量的是 wire 视角(客户端实际重发的整包 payload),而折叠只能压 kernel 会话状态里标为可压缩的区间。两视角严重背离时——DSH 这类每轮重发全量原始历史、且 ~91% 落在保护带(recent band + tool results)——preflight 把允许折的都折完仍下不了窗口,就 fail-fast 502。预算给多大都救不了,因为保护内容在结构上不可折。

    代码印证(当前树):触发/fit 全程用 outboundPayloadBreakdown() 的 wire 估算(src/server.ts preflightCompressIfNeeded,payloadEstimate = estimateCoreMessages + overhead + imageTokens);折叠走 src/preflight.ts 的保护区间遍历;预算耗尽 → failure.kind = "exhausted" → 末尾 failFast(status, …)(server.ts:5236-5238 一带)返回 502。

    二、什么原因导致的(分层)

    • 根因是「触发对象 ≠ 折叠对象」这一结构背离,不是估算器精度本身。
    • fix(preflight): calibrate local estimates against provider usage, provenance-gate the baseline, scale the fold budget (#1933) #1940 修的是估算器这一层:F1 用 k̂ 校准本地估算(tokenCount / textChannel / post-fold fits / per-round roundText 全改走 applyEstimateCalibration)、F2 按路由 provenance 降级跨 provider 基线(lastInputTokensOrigin)、F3 折叠预算 16→32 随超窗比放大。这些让闸门不再被系统性偏高的 chars/4 误触发,但不改 kernel 认为哪些区间可折。
    • 所以残留下半段 = 即便估算已校准、预算已放大,保护重的重发包里可折比例太小、校准后仍过窗 → 依旧 502。这正是本 issue 跟踪的部分。

    三、方案 B 的评估(三点要钉死)

    1. 硬依赖 fix(preflight): calibrate local estimates against provider usage, provenance-gate the baseline, scale the fold budget (#1933) #1940(未合并)。B 的证据源之一「fix(preflight): calibrate local estimates against provider usage, provenance-gate the baseline, scale the fold budget (#1933) #1940 发布的 k̂ 使校准后估算 fit」——而 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 要修的那类残留。
    2. 这是 wire 行为变更,需你拍板(§7.4:wire/message-shape 留给人;也属 fallback/默认值变更)。旧行为:preflight 无法收敛 → 确定性 502;新行为:先做一次有证据支撑的前向再 502。须按政策披露 旧→新。
    3. 闸门口径有个坑(我核出来的):若只取「校准后估算 fit」单一判据,恰好在真正的残留场景会判 false——当 k̂ 只是温和偏低(路由按本地估算 ~0.4–0.6× 计费)、又保护重时,折叠后校准值仍 > 窗口,forward-once 不触发,502 照旧。要真正救到事故类,判据应放宽到「该路由最近确实接受过一个窗口内的真实 usage 报告」(同路由、经 fix(preflight): calibrate local estimates against provider usage, provenance-gate the baseline, scale the fold budget (#1933) #1940 F2 的 origin 门控),即「这条路由被证明按低于本地估算的尺度工作」,而非严格要求「当前这包的校准值 fit」。风险由一次性 + 拒绝后 re-arm 兜住。

    四、落地路径(我的明确建议,不是选择题)

    五~七(回归 / 缓存 / 设计方向 / 新配置)

    需要你拍板三件事:① go/no-go(502 → 一次有证据前向);② 闸门口径(只取 k̂-fit,还是加上「同路由近期窗口内真实 usage」这条更宽判据——我推荐后者,否则救不到事故类);③ 确认顺序(先 #1940 后 follow-up)。

    拍板后我即按此路径出 follow-up PR(叠在 #1940 之上),PR 描述写清行为变更 旧→新 与回归清单。

    (注:以上行号基于当前 worktree 所基于的旧 master;实际开工会先 rebase 到最新 master,行号会平移,以函数名为准。)

  2. ranxianglei commented on Oct 3, 2026

    @ranxianglei
    OwnerAuthor

    关闭,不做方案 B。

    定性:compress.modelContextLimit 是运营的硬契约,不是可被上游真实容量否决的提示。保护内容累积到超过配置窗口 → 会话寿终正寝是设计内行为:fail-fast 502 + 行动指引(调高/移除设置)就是设计的死亡方式,不是缺陷。事故里上游"能收下"不构成绕过运营配置的理由——运营设 256K 可能就是成本上限。

    方案 B 否决:有证据前向一次 = 绕过运营配置继续跑(上游慷慨就永久超窗),把配置上限变成废纸,不做。

    唯一真实的残留不归本 issue:死亡过程太贵(保护地板>窗口可在 walk 前算出,却烧了 5 分钟 + 32 次摘要调用)——由 #1851(preflight futility gate)处理,该 PR 继续走。

  3. added and removed
    bugSomething isn't working
    on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions