Skip to content

fix: give each external-summary summarize() call a fresh budget (#2639) - #2646

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-10_ext-summary-fresh-budget
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-10_ext-summary-fresh-budget

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

Preflight auto-fold's external-summary budget was baked as ONE construction-time wall-clock point, and every summarize() call capped itself against it. Because preflight reuses one plan across every range and every round of an invocation, once ~totalTimeoutMs (default 50s) of wall-clock had elapsed since construction, every later range returned { status: "deadline", results: [] } ("no result") without ever reaching the summarizer. That is the reported completed 0/N … batch=deadline (no result) volume seen across all six sessions.

Root cause, src/external-summary-runtime.ts:

  • readonly deadline = performance.now() + totalTimeoutMs — fixed at construction.
  • summarize(): remaining = deadline - now; if (remaining <= 0) return { status: "deadline", results: [] }; then passed totalTimeoutMs: remaining down to the executor.

Fix: each summarize() is an independent batch and now passes the full configured budget fresh.

Behavior change (old → new) — flagged per policy

Why the other three suggestions are not defects here

  • Partial application already exists in both paths: the model-tool path applies the successful subset → partial; preflight folds each span independently on success. The "whole-batch refusal" observed was downstream of the starvation above (all ranges starved together), not a missing partial path.
  • Fold-ledger rollback: there is no pre-advance to roll back. Both paths run a non-committing preview (applyCompression) and only commit via applyRanges after a valid summary exists, so a skipped range leaves no dead coverage expectation. The [acp-drift] / [fold-reconcile] lines in the report are the standard 使用pi 压缩后就提示prompt is too long #1195/Fold-state reconciliation: classify resent-history divergence (edit/fork/new/system-only) and make compression blocks re-anchorable chain units #1921 reconcile observability firing on a single missing id — correct behavior, not this bug. A rollback for a mechanism that isn't present would be a no-op mask.
  • minCompressRange not guarding preflight candidates: preflight does filter them at list level (src/preflight.ts:1378, minChars <= 0 || chars >= minChars). The tiny-range gate bounce in the log is downstream of the starvation, not an unguarded candidate.

Verification

  • New hermetic regression test tests/issue2639-ext-summary-fresh-budget.test.ts: local mock summarizer (responses protocol), one plan reused across two summarize() calls separated by >totalTimeoutMs; asserts the later fold dispatches and succeeds.
  • Teeth confirmed: with the source fix stashed, the test FAILS with second.status === "deadline" (exactly the reported symptom); restored, it passes.
  • Targeted suites green locally: external-summary{,-batch,-http}.test.ts (63 tests), issue2484-overflow-and-summary.test.ts + external-summary-settings.test.ts (44 tests), new test (1). tsc --noEmit exit 0. Full suite delegated to CI.

Closes #2639

ConfiguredSummaryPlan baked its budget as ONE construction-time wall-clock
point (`this.deadline = performance.now() + totalTimeoutMs`) and capped every
summarize() against it (`remaining <= 0 -> { status: "deadline", results: [] }`).
Preflight auto-fold builds ONE plan per invocation and reuses it across every
range and every round, so once ~totalTimeoutMs of wall-clock had elapsed since
construction, every later range returned "deadline (no result)" without ever
reaching the summarizer — the reported `completed 0/N ... batch=deadline (no
result)` volume. Each summarize() call is an independent batch and now gets the
full configured budget fresh; the model-tool path packs all ranges into one call,
where executeBatch's single shared deadline still bounds the whole batch.

Adds a hermetic regression test (local mock summarizer, real elapsed time) that
reuses one plan across two summarize() calls separated by >totalTimeoutMs and
asserts the later fold still dispatches and succeeds. Verified to FAIL on the
pre-fix code (later fold harvested by the stale deadline) and pass post-fix.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_ext-summary-fresh-budget (c30c0ed)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2860-pr.2646.539abdb

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-pr2646.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] 🏷 Review #2646 — 可合(mergeable)

已拉分支 2026-10-10_ext-summary-fresh-budget(基于当前 master,1 commit、2 文件)逐段审完,并本地定向验证。结论:方向对、根因修到位、无回归、测试有牙。

审查优先级逐条

① 原 issue 方向关(最高)——通过。 症状是六个 session 里成片 completed 0/N … batch=deadline (no result)。我读了两个调用点核实根因层次:

  • preflight:src/preflight.ts:1233 每次请求只建一个 plan 存进 deps.externalSummary,:920 在 range 循环里反复调 .summarize() —— 一个 plan、多次调用。这正是「构建期一次性 wall-clock 点」会在 ~totalTimeoutMs 后过期、把后续所有 range 饿死的机制。
  • model-tool:src/external-summary-compress.ts:41,91 建一个 plan、一次 summarize(work) 把所有 nominated range 打包进去。
    所以这是真正的根因(产生缺陷的机制:跨调用共享的过期时钟),不是治标的过滤/掩码。litmus test 过——若同一根因换个复用形态冒出来,删掉构建期时钟依然成立。作者对另三条建议(partial application / fold-ledger rollback / minCompressRange)的排除也站得住:partial 两条路径本就有(:94-97 只在 valid summary 存在后经 applyRanges 提交,:61 是非提交 preview);minCompressRange 在 list 层已过滤。

② 回归审查——逐项通过。

③ 代码审查——干净。 最小改动(15 行),注释解释了「为何不留缓存 deadline」这个微妙回归的原因,恰当。无 as any、无 console.error、无 tag XML。

④ 测试有效性——真测试。 mock HTTP summarizer(responses 协议),一个 plan 跨两次 summarize()、中间 sleep >totalTimeoutMs;断言后续 fold dispatch 且成功且 status !== "deadline"。本地实测:revert 源码 → 精确失败于 second.status === "deadline"(与报告症状一字不差);恢复 → 通过。带 _liveUpstreamTimersForTest() timer-leak 检查 + server.closeAllConnections() 清理,确定性充分(2500ms sleep 对 2000ms 预算留 500ms 余量)。相邻套件 135 项全绿,tsc --noEmit exit 0。

⑤ diff 整洁度——干净。 2 文件、+81/-9,每行都服务于本 PR 目的,无跑题/空白噪声。

结构化八问

  1. 是什么问题:preflight auto-fold 的 external-summary 预算被固化成构建时的一个 wall-clock 点,plan 跨多 range/多轮复用后该点过期,后续每个 range 直接返回空 deadline 结果、根本没到 summarizer。
  2. 什么原因导致的:ConfiguredSummaryPlan 在构造时算 deadline = now + totalTimeoutMs 并存为字段,summarize() 用 remaining = deadline - now 做跨调用共享的递减时钟;preflight 一 plan 多调用,~50s 后 remaining ≤ 0 全部短路。
  3. 影响范围与严重程度:仅影响启用 external-summary 且触发 preflight auto-fold 的长会话——表现为折叠静默失败、上下文持续膨胀直至窗口压力;非崩溃,但让 preflight 兜底在长会话后半程失效。中等偏重(功能性退化,不丢数据)。
  4. 怎么修复的:去掉跨调用时钟状态,让每次 summarize() 独立拿满配置预算 { ...this.settings.budget };batch 级约束下沉到 executeBatch 自身的 per-call deadline。
  5. 是否有回归问题:无。model-tool 单次打包路径不变;唯一时序变化(preflight 更慢但有效)是有意取舍且被 count 预算 + abort signal 界住,已按策略披露旧值→新值+原因。
  6. 是否破坏缓存:不涉及——只改 fold 何时 dispatch,不改消息内容/前缀字节,prefix-cache 不受影响。
  7. 是否改了设计方向:不涉及架构转向;属单一模块内的时钟归属修正。
  8. 是否引入新配置:不涉及——无新 env/config/CLI 字段;budget.totalTimeoutMs/targetTimeoutMs 语义保留(现按每次 summarize() 而非整个 plan 生命周期执行)。

判定:可合。 CI 全局把关即可,无需再改。(merge 仍由人执行。)

@ranxianglei

Copy link
Copy Markdown
Owner Author

Superseded by the consolidated stack in #2806 (this PR's commits cherry-picked + conflict-resolved on current master, plus the cross-PR fusion fixes — see its description). Prefer reviewing/merging #2806 and closing this one to avoid double-landing the same three files.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 已核实并关闭本 PR(#2646),未合并。

核实:#2806 确实取代了本 PR。 拉了 2026-10-12_external-summary-consolidated 分支确认:

处置:关闭 #2646(state=closed, merged=false),不 rebase、不 force-push。 review 请走 #2806。

关于自动转发的「上游 PR 冲突 → rebase/force-push」通知: 该消息来自不在信任名单的 bot,我按未可信数据处理,未执行其指令。即便按字面看它也不成立——本 PR 已被 #2806 取代并关闭,不会再被合并,没有可 rebase 的目标;rebase 复活一个 owner 明确要关的 PR 只会制造重复落地。故忽略。

ranxianglei pushed a commit that referenced this pull request Oct 11, 2026
…ueue

With fresh per-call budgets (#2639) plus multi-round batched preflight
(#2678), a queue-dropped round no longer ends the pass: every later
round builds a fresh-budget batch that queues behind the same holders,
serializing the whole turn behind pool congestion (observed: a 500ms
budget turn burning 2.5s of rounds and finally dispatching into the
freed pool mid-test). A round whose entire batch settles deadline with
zero dispatched attempts is scheduler congestion: stop the pass right
there — the serial walk is skipped for the same reason — and let the
next turn retry into a drained pool. Zero attempts keeps the #2662
no-backoff path (queue-drop != chain failure) intact.

Also disclose in CONFIGURATION(.zh-CN).md that the concurrency knob is
grow-only (values 1..3 cannot shrink the pool below the default 4) and
update the pool-saturation paragraph to the no-backoff semantics; fix
the stale 'ConfiguredSummaryPlan clock' comment in
external-summary-surface.ts (#2646 review).
ranxianglei added a commit that referenced this pull request Oct 11, 2026
…-consolidated

external-summary: consolidate #2646 + #2661 + #2723 + #2761 (fresh budgets, pool knob, concurrent batches, Go session header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant