Skip to content

[PR] fix: post-compress tail — subtract folded spans, backfill plugin offer, honest no-offer clause - #6815

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-15_fix-compress-tail-residuals
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-15_fix-compress-tail-residuals

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

The compress success receipt's remaining-ranges logic had three defects in the post-compress tail (postCompressTail, src/stream.ts), all in the post-fold path:

A. Plugin lane never backfilled the prepare-time offer. LoopCtx had no lastNudge field, so the plugin lane's tool call fell back to a post-fold live recompute in postCompressTail. After a successful fold that recompute returns shouldInject=false → base=[] → the receipt falsely claimed every offered range was folded while ~42K tokens stayed compressible. rememberPluginMessages already stores the prepare-time nudge in transient.pluginMessages; the wire lane (src/server/relay.ts) and preflight lanes pass it, the plugin lane did not. LoopCtx now carries lastNudge and the plugin lane passes mem?.nudge.

B. Boolean overlap dropped the whole range. spansOverlap was a boolean intersection: any overlap between a submitted span and an offered range dropped the entire offered range, so folding the head of a range silently hid its tail. Replaced with span subtraction (subtractSpans + makeResidual): the folded span is cut out and the residual sub-ranges are advertised, re-gated by the viability floor + submit gate. Only message-ref submitted spans (refToIndex !== null) count as cuts, so block refs (bN) never conflate with message indices.

C. False offer-exhaustion clause. The uncovered-history branch said "all offered ranges are folded" even when no offer existed (ctx.lastNudge === undefined). That clause is now conditional: a no-offer lane says "no ranges were offered in this call".

Behavior change (old → new)

  • No-offer lane receipt: "Uncovered history remains — all offered ranges are folded, but …" → "Uncovered history remains — no ranges were offered in this call, but …" (the old wording was a false statement when no offer existed).
  • Partial fold of an offered range: the receipt now lists the residual sub-range (the part not folded) instead of dropping the whole range and firing the stop signal. This is the intended "offered 3, folded 2, show the 1" contract extended to partial folds of a single range.
  • Plugin lane: the receipt is now based on the pre-fold offer (consistent with the wire/preflight lanes) instead of a post-fold recompute — no more false "all folded" after a plugin-lane compress.

Folding itself is unchanged; only the receipt's remaining-ranges computation and wording are corrected.

Tests

Two cases added to tests/compress-success-tail.test.ts:

  • (a) folding only the head of an offered range advertises the residual tail (regression for B — the boolean drop made the whole range vanish and the stop signal fire);
  • (b) a no-offer (plugin-style) ctx never claims the offer was exhausted (regression for A/C — verified the uncovered branch fires with the honest clause).

All 12 tests in the file pass. Typecheck + build green. (4 pre-existing loop-compress.test.ts failures are unrelated — identical on base.)

Scope

Host-side only (src/stream.ts, src/loop/core.ts, src/plugin.ts, tests/). No kernel/ change, no config schema change, no wire-protocol change.

Fixes #6809

…r, honest no-offer clause

The compress success receipt's "remaining ranges" logic had three defects in
the post-compress tail (postCompressTail, src/stream.ts):

A. The plugin lane never passed lastNudge to the tool ctx (LoopCtx had no such
   field), so postCompressTail fell back to a post-fold live recompute. After a
   successful fold the recompute returns shouldInject=false → base=[] → the
   receipt falsely claimed every offered range was folded. rememberPluginMessages
   already stores the prepare-time nudge in transient.pluginMessages; the wire
   and preflight lanes pass it, the plugin lane did not. LoopCtx now carries
   lastNudge and the plugin lane passes mem?.nudge.

B. spansOverlap was a boolean intersection: ANY overlap between a submitted span
   and an offered range dropped the ENTIRE offered range, so folding the head of
   a range silently hid its tail. Replaced with span subtraction (subtractSpans +
   makeResidual): the folded span is cut out and the residual sub-ranges are
   advertised, re-gated by the viability floor + submit gate. Only message-ref
   submitted spans (refToIndex !== null) count as cuts, so block refs (bN) never
   conflate with message indices.

C. The uncovered-history branch said "all offered ranges are folded" even when no
   offer existed (ctx.lastNudge undefined). That clause is now conditional: a
   no-offer lane says "no ranges were offered in this call".

Tests: two cases added to tests/compress-success-tail.test.ts — (a) folding only
the head of an offered range advertises the residual tail; (b) a no-offer
(plugin-style) ctx never claims the offer was exhausted.

Fixes #6809
@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/kernel labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-15_fix-compress-tail-residuals (55f57b9)

Latest build — install this exact version

npm install -g billion-context@0.0.10157-pr.6815.487f56d

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
55f57b9 billion-context@0.0.10157-pr.6815.487f56d build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6815.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: post-compress tail — subtract folded spans, backfill plugin offer, honest no-offer clause [PR] fix: post-compress tail — subtract folded spans, backfill plugin offer, honest no-offer clause Nov 15, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: opencode/qwen3.8-27b)

Dedupe check: no duplicate. No other open issue or PR targets the post-compress tail remaining-ranges logic or #6809 — this is the only fix in flight for that thread (checked open [PR] rows; nearest neighbors #6812 / #6807 are different receipts/paths).

Labels: bug, p2, dsh, scope/kernel — already set on the PR, left untouched (source-PR relabel is off-limits; note scope/kernel looks generous since the diff is host-side only, but I'm not changing it).

Review in progress: pulled the branch (2026-11-15_fix-compress-tail-residuals @ 55f57b9), verifying the three defects (A/B/C) against #6809, running the targeted test file, and checking CI. Full review (8-question format) to follow in this thread.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: opencode/qwen3.8-27b)

Review complete — verdict: mergeable, pending CI green. I pulled the branch (2026-11-15_fix-compress-tail-residuals @ 55f57b9), read the diff against #6809, and verified the claims with targeted local runs (full-suite verdict = CI, still running).

① Direction (source issue): the PR implements #6809's proposed fix 1:1 — (1) lastNudge on LoopCtx + mem?.nudge in the plugin lane, (2) boolean drop → span subtraction with re-gating of residuals, (3) honest no-offer clause, (4) the two missing tests. It fixes the producer (the receipt's remaining-ranges computation), not a downstream symptom — consistent with the issue's positioning upstream of #5872's footer-softening proposal.

② Regression review (existing behavior walked):

  • All 10 pre-existing tests/compress-success-tail.test.ts cases pass unchanged on the PR head (local: 12/12). The no-offer recompute path is byte-untouched (remaining = base passthrough when ctx.lastNudge is undefined); wire/preflight assignment sites (src/server/relay.ts:2627, src/preflight.ts:2136/2530) are untouched.
  • tests/loop-compress.test.ts: 4 failures on head (tests 5/10/11/13) — identical 4 on base, so the PR's "pre-existing, unrelated" claim is verified, not taken on faith.
  • One edge I checked deliberately: the lastNudge branch does not re-check shouldInject, so a stored shouldInject=false decision struct still feeds base. That is the pre-existing post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 design — the wire lane already passes prepared.nudge unconditionally (same nudge = turn.nudge capture at src/server/prepare-openai.ts:355-356), so the plugin lane is now consistent with the wire lane, not newly exposed. Not a regression; noted for the record.
  • refToIndex (kernel/src/refs.ts:28) only matches m0*(\d{1,7}) → block refs (bN) return null and are correctly skipped as cuts; indexToRef cannot throw in makeResidual (inputs are refToIndex-validated). Residuals are re-gated by viableRanges (200-token floor) + submitGate — a shrunken residual below them is not advertised, matching the 出现持续压缩失败,无法自动恢复 #847 contract.
  • Contention: [PR] fix: name the session-binding inconsistency in the beyond-frontier compress receipt (#5151) #6812 also edits src/stream.ts but only beyondFrontierNote (~line 431, wording) — different function, no semantic interaction.

④ Test validity: both new tests have teeth — I ran the PR's test file against base: 10/12 pass, and the two #6809 cases fail with exactly the bug symptoms (B: stop signal fires instead of advertising the residual tail; C: receipt literally says "all offered ranges are folded, but 16 msg(s) … ~20K tok" on a no-offer lane). Test (b)'s conditional assertion is not vacuous — the uncovered branch demonstrably fires in that construction (16 msgs ≈ 20K tok ≥ the 10K floor).

⑤/⑤b Diff & code cleanliness: 4 files, every line related to the fix; spanNum/spansOverlap removed (no dead code); naming intent-carrying; comments carry issue refs and rationale; style matches the file. Clean.

Local evidence: typecheck green, build green, compress-success-tail 12/12 on head. CI: no failures so far — main test shards (ubuntu/windows × node 22/24) + guard lanes were still queued at my check (26 e2e lanes skipped by file-trigger, expected for this file set).

One hygiene note (not a blocker): the head is 92 commits behind current master (tip 26d9bcc). I checked master-side churn on the three touched files — all in disjoint regions (core.ts ~1787 splice micro-opt, plugin.ts ~1800 forkRefs Set, stream.ts ~525 covered-Map), so a rebase is mechanical. I did not rebase: the branch is checked out in the #6809 session's worktree, so I left it to that session or you before merge.


八问(中文结论)

  1. 是什么问题:dsh 插件车道 compress 成功后,回执谎报「所有已提议范围都已折叠」,而实际还有 ~42K token 可压;且只折一个提议范围的头部时,剩余部分从回执里整个消失。
  2. 什么原因导致的:三个独立缺陷——A) 插件车道从不把 prepare 期的 nudge 提议传进 LoopCtx(无 lastNudge 字段),回执走折叠后实时重算,而任何一次折叠后重算必返回 shouldInject=false → base=[] → 谎报耗尽;B) spansOverlap 是布尔相交,提交跨度与提议有任何交集就整段剔除提议,折头藏尾;C) 未覆盖历史分支在无提议时也照说「all offered ranges are folded」。
  3. 影响范围与严重程度:插件车道(dsh 为主)+ 任何无钉住提议的车道的回执准确性;模型可能提前停止压缩([Bug] post-compress "not at its minimum" footer drives single-message compress retries (18/19 streaks; 83% of retried ranges are the model's own pending-reply notes) #5872 已记录下游伤害:19 段连续失败、83% 单条消息 compress 尝试)。可用但回执失真 → p2,与 PR 标签一致。
  4. 怎么修复的:A) LoopCtx 加 lastNudge,插件车道传 mem?.nudge(值本就被 rememberPluginMessages 存着,只是没读出来);B) 布尔剔除换成跨度相减(subtractSpans+makeResidual 按索引比例缩放估算值),残余重跑 viability floor + submit gate;C) 耗尽措辞改为条件句,无提议车道说「no ranges were offered in this call」。
  5. 是否有回归问题:无。既有 10 个回执用例在 PR head 全部原样通过(本地 12/12);无提议的重算路径字节级未动;wire/preflight 赋值点未动;loop-compress 4 个失败 base/head 完全相同(既有问题)。已披露的三处行为变更即修复本身。边界情形(lastNudge 分支不复查 shouldInject)是 post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 既有设计,wire 车道本就如此,插件车道本次是向它对齐而非新增暴露。
  6. 是否破坏缓存:否。回执是 tool-result 字符串,不触碰缓存/重试/游标/去重;修复反而降低零增长链式折叠(post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 的 prefix-cache thrash 风险)。
  7. 是否改了设计方向:否。把既有 post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 钉住机制扩展到真正发起 compress 的插件车道,正是 issue 指定的方向。
  8. 是否引入了新的配置:否。

判定:可合(等 CI 绿;合并前建议先 rebase 到当前 master——机械操作,无重叠区域)。PR 标签 bug/p2/dsh/scope/kernel 已就位,未改动(scope/kernel 对纯 host 侧 diff 偏宽,但按规则不动源 PR 标签)。

This branch has not been deployed

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

Labels

bug Something isn't working dsh p2 scope/kernel

Projects

None yet

1 participant