Skip to content

fix: retry transient empty summaries in preflight before failing the turn (#1767) - #1769

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-30_preflight-transient-empty-retry
Sep 30, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-30_preflight-transient-empty-retry

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What changed

src/preflight.ts: preflight now classifies each empty/too-short summary diagnosis as size-driven or transient, and retries transient ones on the same span a bounded number of times before falling through to the existing #726 halving cascade.

  • emptySummaryIsSizeDriven(diagnosis) — a single regex over the test-pinned diagnosis strings. Only explicit SIZE signals (context_length_exceeded, too long, finish_reason=length, stop_reason=max_tokens) count as size-driven; everything else (content_filter, empty body, truncated stream, in-stream error) is a summarizer/gateway blip.
  • SummaryOutcome.unusable gains transient?: boolean, set from that classifier in requestSummary.
  • The chunk walk wraps each summarizeRange draw in a retry loop: up to TRANSIENT_EMPTY_SUMMARY_RETRIES (2) extra same-span draws with replayBackoffMs backoff, capped by a per-protection-regime TRANSIENT_EMPTY_RETRY_BUDGET (4, reset alongside summaryCalls when soft protection relaxes) and the existing MAX_SUMMARY_CALLS_PER_PREFLIGHT (16) ceiling. Aborts honor deps.signal.
  • After retries are exhausted the code falls through to the unchanged [Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726 halving/skip/fail-fast path.

Why (root cause)

#1767: a flash summarizer behind a gateway answered the preflight summary call with HTTP 200 plain JSON whose content was EMPTY (finish_reason=content_filter). Preflight treated every empty answer as size-driven (halving cascade), but a single-message span cannot be halved — so the only range that could fit the payload got exactly one doomed draw, the turn fail-fasted 502 in-band, and the user had to send 继续 to re-trigger preflight ~90s later when the filter cleared. Re-drawing the same span a bounded number of times recovers the blip; the size-driven paths are untouched.

Behavior change (old → new)

  • Old: any empty/too-short summary → treated as deterministic for the span → single-message span dies after ONE draw → if it was the only foldable content, preflight fails fast 502 and kills the turn.
  • New: an empty summary classified as transient gets up to 2 extra same-span draws (backoff 1500ms/3000ms) before the existing halving/skip logic runs. If any draw succeeds the turn recovers with no client retry; if all fail, behavior is byte-identical to before.
  • Why: content_filter/empty-body/truncated-stream empties are gateway blips, not span-size problems; halving a single-message span is impossible, so without re-drawing the flaky summarizer the turn dies.
  • Bounded worst case: ≤4 extra summary calls per protection regime (≤8 per preflight) on a systemic persistent failure, degrading to today's behavior; size-driven failures spend zero extra calls. Quota impact is intentionally small.

Config surface

None. No config field, env var, or CLI flag added/renamed/re-semantics'd. (Reuses existing BILI_REPLAY_RETRY_* backoff seams.)

Tests

  • New tests/preflight-transient-empty-retry.test.ts:
    • regression repro of bili会突然暂停发继续又可用 #1767 geometry (one giant tool output outside the recent zone): two scripted content_filter draws then success → turn recovers 200 with no client retry, exactly 2 failed draws, dead-end marker NOT left behind;
    • systemic persistent content_filter → 502 preflight_compress_failed, diagnosis surfaced, summary calls bounded (≤32), dead-end arms, cooldown spends ZERO calls, nothing forwarded;
    • classifier unit test pinning transient-vs-size-driven across every diagnosis shape.
  • tests/preflight-empty-summary.test.ts: zero-backoff env for speed; #780 truncation bound raised 9→32 (truncation is now transient-classified, so each span gets up to two extra draws).

Pre-flight

  • npm run typecheck ✅
  • npm test ✅ 3235 pass / 0 fail / 12 skipped (gated e2e)
  • npm run build ✅

Closes #1767

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_preflight-transient-empty-retry (2fca116)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1716-pr.1769.f86b0ed

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-pr1769.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。正在按 PR Review 规范审查本 PR(方向核对 #1767 → 回归清点 → 代码/测试/diff)。先拉分支核对代码与 CI,完整结论稍后给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成 — 可以合并(附一个与本 PR 无关的既有 flaky 测试发现,已单独立项 #1770)。

① 原 issue 方向核对(#1767)

  • 根因链已复核成立:gateway 对 preflight summary call 返回 HTTP 200 plain JSON 空内容(finish_reason=content_filter)→ preflight 把所有空摘要当 size-driven → 单消息 span 无法 halve → 唯一可折叠 range 只得到一次注定失败的 draw → 502 fail-fast 杀掉整个 turn → 用户 ~90s 后手动发「继续」才在 filter 清除后恢复。
  • 层次判断:根因是「单次 doomed draw 无恢复路径」这个机制,不是 summarizer 本身(那是 gateway 侧,bili 修不了)。bounded same-span re-draw 移除的正是「一次 draw = 死刑」机制;全部 draw 失败后行为与旧路径 byte-identical。不是治标:size-driven 路径完全不动,classifier 只决定「值不值得重画」,不改变 halving/skip/fail-fast 的任何决策。
  • 方案评估:content_filter 以 200 到达,status-code 检测不可行;diagnosis-string 分类是唯一可用 seam,且字符串已有测试 pin(新测试第 3 项逐形状钉死),kernel 改措辞会被测试抓住。方向正确。

② 回归审查(既有行为清点,逐项结论)

  • MAX_SUMMARY_CALLS_PER_PREFLIGHT=16 per-regime 上限:保持。重试计入 summaryCalls,ceiling 检查在自增之前(src/preflight.ts:1103),总量 ≤16/regime 不变。
  • [Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726 halving cascade / skip / fail-fast:不变,重试耗尽直接落入原路径。
  • fix: preflight tries all viable ranges before declaring exhaustion #575-merge per-regime budget reset:transientRetryBudget 在两处 relaxation 点(src/preflight.ts:951、:1203)随 summaryCalls=0; budgetHit=false 一起重置;两处都受 !relaxed 守卫 → 至多 2 个 regime → ≤8 次额外 draw/preflight,与 PR 描述一致。
  • Dead-end marker/cooldown:逻辑未动;恢复场景不留 marker(systemic 场景 arm、cooldown 零调用)均有测试钉住。
  • Abort:while 条件检查 deps.signal?.aborted;sleep(ms, signal) abort 时提前 resolve,下一次 draw 在 requestSummaryBody 顶部 throwIfAborted() 立即抛出 → ABORTED_FAILURE。两条路都安全。
  • 两种压缩模式:preflight 是 server-side window backstop,本变更只影响 proxy 自己 side-call 的重画次数,主请求 wire shape 与注入/抑制逻辑未触碰,mode-neutral。
  • Config surface:确认为无——复用 BILI_REPLAY_RETRY_*(默认 backoff 1500/3000ms,replayBackoffMs(attempt)=base*2^(attempt-1)),与 PR 声明一致。
  • 行为变更确认(有意,已披露):transient 空摘要现在最多追加 2 次同 span 重画(+~4.5s 最坏延迟/span)后才走旧路径;size-driven 失败零额外调用。PR body 已按规范披露 old→new。

③ 代码审查

  • classifier /context_length_exceeded|too long|finish_reason=length\b|stop_reason=max_tokens\b/i 覆盖 diagnoseEmptySummary 全部输出形状;嵌入的上游错误文本(如 "prompt is too long")仍判 size-driven;误报只朝保守方向(少一次重试机会,不改变结果)。✔
  • summarizeRange 全文件仅一个 draw 调用点(chunk walk,src/preflight.ts:1094),retry 覆盖完整,无遗漏路径。✔
  • assembled-summary-exceeds-maxSummaryLength 的 outcome 是确定性 size 问题,正确地不进入重试。✔
  • 小观察(非阻塞):[Bug] preflight 摘要抽取层:被截断的 SSE 会被当成完整摘要,delta-less 终端会被当成空摘要(#726 的恢复链路仍未闭环) #780 测试 bound 9→32 是理论硬上限(2 regime × 16),比旧经验值牙口略松,但仍能抓 runaway loop;鉴于截断类现在 transient 化是有意的,可接受。

④ 测试有效性

  • 测试 1(bili会突然暂停发继续又可用 #1767 几何:recent zone 外一个大 tool output):revert 本修复即 200→502,真回归牙。✔
  • 测试 2(systemic):502 + preflight_compress_failed + diagnosis、调用有界、dead-end arm、cooldown 零上游调用、nothing forwarded。✔
  • 测试 3:classifier 8 种形状逐一钉死(content_filter/empty body/truncation/in-stream error/incomplete → transient;length/max_tokens/context_length_exceeded → size-driven)。✔
  • 小缺口(非阻塞):per-regime budget 在 relaxation 时的重置、精确 backoff 值无直接断言;有其他上限兜底,风险低。

⑤ diff 整洁度:3 文件(src/preflight.ts +48/-3、tests/preflight-empty-summary.test.ts +5/-1、新增 tests/preflight-transient-empty-retry.test.ts +267),无 version/lock/generated churn,每行都在题内。✔

验证证据

  • 本地(pr-1769 @ 2fca116,基于当前 master 8d3d1bf,base 新鲜):typecheck ✅、build ✅、preflight 相关 12/12 ✅(含 3 个新测试)、full suite 3234 pass / 1 fail / 12 skipped。
  • 那 1 个 fail = tests/issue1452-socket-hardening.test.ts 的 stall-guard 时序测试(missing chunk-6 …,test:435)。A/B 验证:同一命令在 pristine master 上 3/3 同样失败,PR diff 不触碰任何 stream/stall 代码,CI 四个矩阵 job 全绿 → 既有环境相关 flake,与本 PR 无关。已立项 test: issue1452-socket-hardening stall-guard test is timing-flaky on loaded hosts (fails on pristine master) #1770(带来源标记,建议把 stall budget/pacing 做成可注入 seam)。
  • CI:head sha 全部 12 个 check run 绿色(含 ubuntu/windows × node 22/24 test 矩阵、e2e lane、hermetic registry)。
  • §7.4 auto-merge gate:逐项满足(单模块纯 fix:、回归测试在位、rebased head 绿、无 config/wire/persistence/cross-repo/update.ts/ref-id 变更、clean diff、Closes bili会突然暂停发继续又可用 #1767)。

中文一句话总结:审了 PR #1769(preflight 对瞬时空摘要做 bounded 同 span 重试)——根因成立(content_filter 200 空响应 + 单消息 span 不可 halve = 一次 draw 定生死),方案打的是机制而非症状,回归清点全部保持或有意披露,测试有牙、diff 干净、CI 全绿,可以合并。

@ranxianglei
ranxianglei merged commit d460766 into master Sep 30, 2026
12 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-30_preflight-transient-empty-retry branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bili会突然暂停发继续又可用

1 participant