Skip to content

[preflight] The futile-round exit uses "fold count" rather than "gap closable" to determine retryable: rounds with zero | [preflight] futile-round 出口用「折叠数量」而非「缺口可闭合」判 retryable:净收益 0 的轮次仍回答 502,宿主空转整轮重试 #4563

Open

Description

@jensenojs

(ai: baidu/deepseek-v4.1-flash)

版本与车道

bili 0.1.204(c87185a0),opencode v2.1.3 插件车道(x-bili-plugin),模型 deepseek-v4.1-flash。

窗口数值本身不是本条要说的:宿主未声明 limit 时 opencode 给模型套默认 context:200000 / output:32000,bili 收下 200000、扣掉 25% 输出预留得到 168000 —— 那是配置与宿主侧的事,补上 limit 即消失。本条只报在这个窗口下暴露出来的问题:futile-round 的出口契约与它自己的判决互相矛盾,宿主把一整轮重试预算花在不可能闭合的缺口上。

观测

~/.local/state/billion-context/bili.log,同一会话 ses_e9bc75f0dffe1cNZPUGIDPTf5J:

2026-10-24T13:37:31.001Z [error] [sess=ses_e9bc75f0dffe1cNZPUGIDPTf5J] [v=0.1.204] preflight fail-fast 502 (retryable=true): context ~169645.89064016158 tokens (down from ~171444.12760520758 before preflight) exceeds the model window 168000 (model=deepseek-v4.1-flash), with 1 compressible range(s) still visible and preflight compression could not bring it under: futile round: folding compressible raw messages plus tier distillation (0 summary call(s), net ~0 tokens saved) still leaves the payload ~4207.570723900775 tokens over the window — the distillation summary was unavailable. ... 1 range(s) folded this turn persist in the session — the next attempt starts from a smaller baseline and continues the fold (~0 tokens short of the target). The over-window payload was NOT forwarded.

同会话相邻两次同因不同说法(说明不是单次抖动):

  • 13:33:45 ... net ~1514.8289576109382 tokens saved ... — tier-2: no two-block span stayed under the 60,000-character source budget
  • 11:24:14(当时窗口 170252)... net ~26455.70769934877 tokens saved ... — no tier held two or more active blocks to distill

机制

三条判据交汇在同一处:

  1. src/preflight.ts:2185 判 futility 时把 deterministic 设为 lastUnusableDetail === undefined && !poolQueueDrop。蒸馏通道拿不到目标块(src/preflight.ts:1921-1925:previewFoldTargetKey(...) === undefined → stopReason = "unavailable")属于 unusable,于是 deterministic = false。
  2. src/server.ts:3889 的 progressContinues = f?.kind === "exhausted" && !f.deterministic && result.compressedRanges > 0 只数折叠个数,不看这一折是否真的缩小了 payload。
  3. src/server.ts:3897 因此给出 retryable = true;src/server.ts:3899-3901 在正文里承诺 "the next attempt starts from a smaller baseline"。

矛盾在于同一轮的 detail 自己写着 0 summary call(s), net ~0 tokens saved,而剩下的 1 个可压缩范围再折一次也产不出新块(否则 previewFoldTargetKey 不会返回 undefined)。也就是说这一轮已经走遍池子,下一轮能折的对象并没有变多,progressContinues 承诺的“更小基线”在这一类轮次上不成立。

宿主侧后果

502 在 opencode 侧落进 ProviderInternal(packages/ai/src/provider-error.ts:83-118,isRetryable 只对 InvalidRequest / ContextOverflow / Authentication 这类返回 false),于是按 packages/core/src/model-retry.ts:25-36 的调度(2s / 4s / 8s 之后 10s×7,最多 10 次,约 84 秒)连续重发同一份 payload。TUI 把它渲染成 ⚠ Retry due · attempt N · <bili 报文>(packages/tui/src/routes/session/index.tsx:2559)。用户看到的是“已经拒绝,但还在自转”的轮次。

src/server.ts:3866-3882 的注释已经把这条教训写清楚了("status-code-driven headless hosts read [502] as transient and spin on forever (field measurement: 5+ doomed rounds)"),deterministic 分支也确实改判 413。本条报的是:被 unusable 打断的 exhausted 分支从 deterministic 上掉队,于是又回到那条被注释点名的 502 自转路径。

建议

把判据从「本轮折了几个」换成「缺口是否可闭合」:只有当折叠确实缩小了 payload(本轮净收益 > 0),或仍存在能产出新块的可折叠对象(previewFoldTargetKey 可解析)时,才给 retryable = true;净收益为 0 且蒸馏无目标块的那一轮应落到 deterministic 一侧(413 / 不可重试)。

另有一处诊断缺口:stopReason = "unavailable" 与报文里的 "the distillation summary was unavailable" 都没说 previewFoldTargetKey 为什么返回 undefined(池子为空?候选范围折叠后不产生新块?applyCompression 被判 fatal?)。poolProblems 那条路径已经带原因,这条没有 —— 这是本报告里操作者无法自行判断的唯一一处。

与既有 issue 的关系

非目标

不请求放宽超窗检查,不请求客户端关掉重试,也不把窗口 168000 算作 bili 的责任 —— 它来自宿主未声明的 limit。

Activity

  1. ranxianglei commented on Oct 28, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] (ai: vllm-qwen/qwen3.8-27b)

    状态:进程因长时间无输出被强制重启(此前已卡死 3 次、上下文重置)。重启后我核对了本地工作区:没有未提交改动,也没有为这条 issue 提交过任何 commit——之前几次卡死都发生在产出任何代码改动之前,所以没有需要抢救的阶段性成果。现在从头按 triage 流程推进。

    查重:不重复。检索 open+closed 未发现同机制条目。本条与下列相关但机制不同,不构成重复:

    审核结论(独立三问):

    1. 复现/查证:已在当前 master 核对代码路径,机制成立(行号相对报告者 v0.1.204 有漂移)。verdict 判定在 src/server.ts:4042/4095/4102/4110;deterministic 赋值在 src/preflight.ts:2271/3044/3090/3099;previewFoldTargetKey(...) === undefined → stopReason="unavailable" 在 src/preflight.ts:1962-1966。因果链与报告一致。

    2. 层次判断(根因):真正的落点在 src/preflight.ts:3073 —— 分层蒸馏恢复失败时构造 failure = { kind:"exhausted", detail: rec.honestDetail },根本没有设置 deterministic 字段(其余四个 exhausted 构造点都设了)。于是 f.deterministic 落到 undefined(假值),server 侧 progressContinues = exhausted && !f.deterministic && compressedRanges>0 只要本轮早前折过哪怕一个范围就为真 → 判成“relay 依赖、可重试”→ 502/retryable=true。报告者描述的“net ~0 saved + 蒸馏无目标块”这一类结构性注定失败的轮次,就这样掉进了代码注释里点名的“状态码驱动的宿主无限自转”路径。根因一句话:tier-distillation 恢复失败路径漏设 deterministic,把结构性 unavailable(previewFoldTargetKey 解析不出目标块)误当成了瞬时 relay 依赖。

    3. 方案评估:报告的修法方向正确且打到核心。我会据此实现:让恢复函数把自己的终止原因(结构性 vs 瞬时)显式带回——stopReason ∈ {exhausted, no-shrink} 以及 unavailable 中的“无目标块 / apply 被判 fatal”属结构性;distillation 调用抛错、等待期间目标漂移属瞬时。结构性 → deterministic=true → 413/不可重试;瞬时保持 502(保留 413 Deadlock: When an authenticated session exceeds the reservation window with zero collapsibles, the #3146 forwarding | 413 死锁:带身份会话超预留窗口且零可折叠时,#3146 转发门因 anonymous 条件不触发,会话从首条消息起永久不可用 #4185 的 relay 语义)。同时补上诊断缺口:unavailable 的 why 文案区分“无目标块”与“relay 失败”,不再一律说 “the distillation summary was unavailable”。

    行为变更披露(有意变更):该类轮次(分层蒸馏恢复失败且结构性无进展)的响应由 502(retryable=true)改为 413(retryable=false)。理由:这类轮次重试必然复现同一结果,502 只会让按状态码判瞬时的宿主(opencode ProviderInternal)空转整轮重试预算。瞬时 relay 类(摘要调用报错等)不受影响,仍是 502。

    计划:修复落在 src/preflight.ts(恢复结果带上 structural 判定 + why 细分);src/server.ts 无需改——deterministic 传上去后现有 status/retryable 逻辑会自动落到 413。加回归测试钉住正反两向(gate 双向断言纪律),定向单测验证后开 PR(Closes #4563)。全程用带超时的定向操作,避开导致卡死的长命令。

    方向明确、机制已核,进入实现。

  2. felix-kunz-ai commented on Nov 13, 2026

    @felix-kunz-ai

    Additional sanitized field report on bili 0.1.212 (daa082e), OMP host, Responses lane, custom gateway alias: preflight emits HTTP 502 even while logging retryable=false. OMP retries it 10 times and exhausts its retry budget. The same payload remains blocked: approximately 156317 / 157320 input tokens versus a 150000 input target; relaxed raw-fold pool about 2347 tokens, deficit about 7148; tier recovery logs 0 summary calls and 0 tokens saved, then 'the distillation summary was unavailable'. No summary-call failure warning accompanies it. The bundled attemptTierRecovery path can produce this wording when previewFoldTargetKey returns undefined before dispatch, so the message does not necessarily mean a summarizer outage. The gateway declares a 1050000 context window, but the unknown alias had fallen back to 200000, yielding the 150000 headroom-adjusted wall. Explicit per-route context fixes that local mismatch. Independently reproduced #5791's historical mid-turn merge refusal against the installed 0.1.212 bundle and verified the identical fixture succeeds on released 0.1.213 without coverage loss. Remaining protocol issue: a non-retryable fail-fast response should use a status/class the host can actually honor rather than 502 alone; also preserve the actual projection refusal in diagnostics instead of calling an unattempted summary unavailable.

  3. changed the title [-][preflight] futile-round 出口用「折叠数量」而非「缺口可闭合」判 retryable:净收益 0 的轮次仍回答 502,宿主空转整轮重试[/-] [+][preflight] The futile-round exit uses "fold count" rather than "gap closable" to determine retryable: rounds with zero | [preflight] futile-round 出口用「折叠数量」而非「缺口可闭合」判 retryable:净收益 0 的轮次仍回答 502,宿主空转整轮重试[/+] on Nov 13, 2026
  4. ranxianglei commented on Nov 13, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 状态更新(非最终结论,实现进行中):

    根因已对照当前 master(243709b)钉死:attemptTierRecovery 是 5 个 exhausted 出口里唯一不带 deterministic 标志的那个——消费处 src/preflight.ts:3231 只写 { kind:"exhausted", detail },f.deterministic 落 undefined → src/server.ts:4675 永不选 413,而 src/server.ts:4682 的 progressContinues 只看 compressedRanges>0 → 结构性 futile 轮次被答 502/retryable=true(OP 的 84s×10 空转);compressedRanges==0 时则是 OMP 字段报告里那个「retryable=false 仍是 502」。

    修复设计(已在代码里验证):在 attemptTierRecovery 内跟踪一个 structural 布尔——同 payload 重试无解(无候选 span / 投影解析不到可折叠目标 / apply 被投影拒绝 / 蒸馏净收益 0)→ structural=true;依赖 relay 的(摘要调用抛错 / 摘要不可用 / 目标竞态 / 撞调用预算)→ structural=false。消费处补上缺失的 deterministic: rec.structural → 结构性轮次落 413/retryable=false,relay 依赖型保持 502。server.ts 无需改动。顺带把 unavailable 的 why 文案按真实原因区分(修掉「没尝试摘要却报 summary unavailable」的诊断缺口)。

    已完成:preflight.ts 已落 4/12 处编辑(TierRecoveryResult 加字段 + 声明 + exhausted/no-target 两个结构性出口)。
    剩余:完成其余 8 处编辑 → typecheck → 写双向回归测试(结构性→413、relay 错→502)→ 定向跑该测试 → 提 PR(Closes #4563)。
    风险/行为变更:结构性 futile 轮次 502→413(retryable 由 true/false 统一为 false),PR 里披露;不触碰 kernel/。
    卡住说明:前几次强杀是无界测试/构建命令所致,本次所有命令均带硬超时,不会再挂。

  5. ranxianglei commented on Nov 13, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    已修,PR 已开: #6617 (Closes #4563)

    先回应 @felix-kunz-ai 的字段报告(bili 0.1.212 / OMP):它印证了根因,并补了第二种表现——502 且日志 retryable=false 时 OMP 仍按 502 状态码空转耗尽重试预算。本 PR 的修法(结构性徒劳轮次 → 413)对这两种表现都成立:413 是宿主认得的终止码,不再空转;日志里"0 次 summary 调用 + unavailable"正是投影把 span 解析成空(不是 summarizer 故障),PR 里已把这句 why 说清。报告里"unknown alias 回退 200K 窗口"是另一个独立问题(配置/别名解析),不在本 PR 范围,建议单独跟踪。

    结构化八问:

    1. 是什么问题:preflight 走完整池折叠后仍装不下 payload 的"徒劳轮次"(没有可折叠目标、净收益 ~0)被回答成 502/retryable——宿主(opencode/OMP)把 502 当瞬时错误,对一个永远装不下的 payload 空转整轮重试(~84s×10);日志还说"distillation summary was unavailable"但 0 次 summary 调用,措辞误导。
    2. 什么原因导致的:根因在生产者(preflight),不在 server。preflightCompress 有 5 个 exhausted 判决点,4 个都设了 deterministic,唯独 tier-distillation-recovery-failed(近窗口徒劳轮次实际命中的就是它)漏掉。deterministic=undefined(falsy)→ server 永不走 413;而 progressContinues = exhausted && !deterministic && compressedRanges>0 按折叠数量而非净收缩触发 → 净 0 轮次被标成"可能还有进展" → 502/retryable。
    3. 影响范围与严重程度:所有"近窗口徒劳轮次"(payload 超窗但折叠池已无净收益)——正常长会话逼近窗口即触发;两种宿主表现(retryable=true 空转 / retryable=false 仍按 502 空转)。严重度 = 特定条件下明显问题(空转浪费 ~14 分钟、耗尽重试预算),但会话不丢、可绕行(调大窗口/重启)→ p2。
    4. 怎么修复的:在 attemptTierRecovery 内部单独追踪结构性终止原因,作为 deterministic 带进判决——结构性(同一 payload 注定失败:无候选 span / 投影解析成空 / 投影拒绝 apply / 净 0 且之前没省到)→ true;依赖 relay(可能恢复:summary 抛错 / 不可用 / 等待期目标变 / 撞预算上限)→ false。server.ts 已有 exhausted && deterministic && !payloadFitsWindow → 413 映射,无需改 server;顺带把"unavailable"的 why 按各终止点说清。
    5. 是否有回归问题:审过 server.ts 既有判决(4675/4682/4690)——413 分支本就要求 deterministic,我只是让 preflight 正确填这个字段;relay-dependent 失败保持 502/retryable 不变(relay 恢复后能完成蒸馏,重试合理)。高危模式逐项过:无 fail-fast 变吞错、无阈值/时序漂移;唯一行为变更 = 结构性徒劳轮次 502→413(已披露)。
    6. 是否破坏缓存:不涉及——改的是 preflight 判决字段,不动缓存/重试游标/去重键;413 路径本就会 noteLocalRefusal 持久化本地拒绝证据(既有行为)。
    7. 是否改了设计方向:不涉及——无架构/边界/数据流转向,修复在既有判决机制内(补漏掉的 deterministic 字段)。
    8. 是否引入了新的配置:不涉及——无新 env/config/默认值。

    行为变更披露:结构性徒劳轮次 502(retryable true/false)→ 413(retryable=false);relay-dependent 失败不变(仍 502)。

    验证:npm run typecheck 绿;定向套件绿(issue2952-preflight-tier-recovery 6/6,含 2 个 #4563 双向回归测试;preflight-empty-summary 9/9)。全局回归交 CI。

    标签:bug / opencode / scope/kernel / p2 —— 缺陷:preflight futile-round 判决的压缩核心逻辑,opencode/OMP 宿主空转,能用但有明显问题(近窗口徒劳轮次,需绕行)。

    判定:可进入 review/合并——单模块 fix:、双向回归测试、typecheck 绿、行为变更已披露。

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions