Skip to content

[PR] fix(#2638): stop preflight re-nominating structurally-dead spans every turn - #2660

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-10_preflight-dead-range-memory
Oct 20, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-10_preflight-dead-range-memory

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2638

What & why

The kernel's range selector keeps advertising spans whose messages are all already covered by active blocks or locked as live checkpoint carriers (summaryOfBlockId); the apply side rejects such spans with the structural "no new compressible messages" verdict (livelock guard). Preflight's skipSet was per-invocation only, so every request re-derived the same candidates from the same kernel recommendation, re-previewed the same dead span, and re-rejected it forever:

Fix (host-side defense)

  • New src/dead-ranges.ts: per-session memory of structural preview verdicts in session.metadata.preflightDeadRanges (persisted, restart-safe). An entry records startRef:endRef, the block ids named by the verdict, and a snapshot of ALL active block ids at record time. While the snapshot is unchanged the span can never fold through plain refs; any block lifecycle change wakes the entries for exactly one re-preview. Cap 64, FIFO-evict.
  • Preflight seeds its per-invocation skipSet from the memory, filters remembered-dead ranges out of candidate lists (main walk + relaxed probe), and records new entries when a preview returns the structural verdict (both wordings: livelock guard naming blocks, unnamed validateCompressionRange). Non-structural verdicts (zone / min-gate / transient) stay retryable.
  • Structural verdicts also add their key to the invocation skipSet (no intra-invocation re-preview).
  • Nudge-advertised compressible ranges are filtered on all four protocol surfaces (prepare-anthropic/google/openai/responses). With dead spans gone, a lean steady state hits the existing "preflight target reached" early return — skipping the whole per-turn preflight run — and emergencyNudge stops firing on ranges that can never fold (压缩出现bug #2104-class loop).
  • Auto-fold no-progress backoff now arms only when foldable candidates actually existed (PreflightResult.hadFoldableCandidates); a lean steady state forwards without backoff instead of cycling backoff → classic nudge → refused compress.

Behavior changes (old → new)

  1. Within one preflight invocation, a structurally-rejected span is no longer re-previewed by later rounds (old: re-previewed every round — the "nominated twice within one request" case). Verdicts are monotonic within an invocation, so this is safe.
  2. Auto-fold no-progress backoff: old = armed whenever growthArmed && 0 folded && payload fits; new = armed only when foldable candidates existed. Lean steady state: old = 10-min backoff → classic nudges → refused-compress loop; new = forwards as-is without backoff, no nudge churn.
  3. Nudge text (all protocols) no longer lists remembered-dead spans. The acp_status panel still shows the raw kernel list until the kernel-side fix lands.

Config surface

None added. The memory lives in internal session state (session.metadata, persisted like every other session field); no config field, env var, or CLI flag.

Root cause stays upstream — kernel follow-up filed separately

The advertise/validate disagreement itself (kernel recommend lacks live-carrier screening while apply carves carriers out of plain-ref spans) is fixed properly in acp-kernel; a kernel issue with the minimal repro geometry (now in tests/preflight-dead-ranges.test.ts) is filed separately with the source marker. This PR makes the host stop paying the cost regardless.

Tests

  • tests/dead-ranges.test.ts: verdict parsing (both wordings, multi-id, truncation, negatives), record/cap/evict, snapshot-subsumption invalidation, exact-key filtering, metadata persistence round-trip.
  • tests/preflight-dead-ranges.test.ts: builds the minimal production geometry (checkpoint carriers adjacent in the pruned view but separated by covered raws in the full-log history) through real preflightCompress: invocation 1 previews+rejects+remembers the dead span exactly once while the foldable tail still folds; later invocations never re-nominate it; carrier text never reaches the summarizer; an all-dead candidate set reports hadFoldableCandidates=false.

Verified on the rebased head: typecheck clean, targeted suites green (16/16), build OK. Full regression left to CI.

ework-agent added 2 commits October 10, 2026 19:30
…y turn

The kernel's range selector keeps advertising spans whose messages are all
already covered by active blocks or locked as live checkpoint carriers;
the apply side rejects them with the structural 'no new compressible
messages' verdict. Preflight's skipSet was per-invocation only, so every
request re-derived the same candidates, re-previewed the same dead span,
and re-rejected it forever -- wasting per-request work, spamming logs,
pinning the auto-fold target above its floor, and (during the 10-minute
backoff) resurrecting classic nudges that pushed the model into compress
calls which were atomically refused.

Remember structural preview verdicts per session (session.metadata,
persisted) keyed by startRef:endRef; while the recorded active-block
snapshot is unchanged the span can never fold through plain refs, so it
is filtered out of candidate lists (preflight walk + relaxed probe) and
of the nudge-advertised ranges on all four protocol surfaces. Any block
lifecycle change wakes the entries for one re-preview. Structural
verdicts are also added to the invocation skipSet (no intra-invocation
re-preview), and the auto-fold no-progress backoff only arms when
foldable candidates actually existed -- a lean steady state now forwards
without backoff instead of cycling backoff -> classic nudge -> refused
compress.
…gression

Unit suite covers verdict parsing (both wordings, multi-id, truncation,
negatives), record/cap/evict, snapshot-subsumption invalidation, exact-key
filtering, and metadata persistence round-trip. The integration test builds
the minimal production geometry (checkpoint carriers adjacent in the pruned
view but separated by covered raws in the full-log history) and asserts:
invocation 1 previews+rejects+remembers the dead span exactly once while
the foldable tail still folds; later invocations never re-nominate it; an
all-dead candidate set reports hadFoldableCandidates=false.
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_preflight-dead-range-memory (5135c67)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2876-pr.2660.c75d458

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

Install instructions are refreshed on each push.

…ate)

CI's unused-exports gate (#1440 P6) flagged buildDeadSpanFixture as
INTERNAL_ONLY — it is exported but every reference sits inside its own
file. Drop the stray `export`; the fixture is consumed only by this file.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2660 reviewed — approve (human merge). Root cause verified against kernel source; one CI blocker found & fixed+pushed.

Pulled 2026-10-10_preflight-dead-range-memory (now head 5135c677, 3 commits, base master, 0 behind) and reviewed against #2638 + the floor-3 root-cause analysis. I did not just read the diff — I checked the load-bearing assumptions against the actual kernel/host source:

Verified (evidence, not assertion):

Regression audit — existing behaviors touched, each conclusion:

  • non-dead candidate walk: unchanged (dead filter only drops remembered structural-empty spans);
  • nudge advertised ranges (prepare-{anthropic,google,openai,responses}.ts): only structurally-dead spans removed, live/foldable ranges pass through — no loss of legitimate candidates;
  • backoff on a genuine chain failure: unchanged (still arms);
  • persistence: new OPTIONAL metadata key preflightDeadRanges — additive, versionless, capped at 64, JSON round-trip tested; follows the existing optional-metadata pattern, not a versioned schema change; old sessions load as empty;
  • no config/env surface added; no wire-shape change beyond the intended nudge-range suppression.

One CI blocker — fixed & pushed. The unused-exports job failed on tests/preflight-dead-ranges.test.ts: buildDeadSpanFixture (exported but every reference sits in-file → INTERNAL_ONLY). Removed the stray export (one-token diff), re-ran the zero-dep gate locally → clean (exit 0), pushed as labeled commit 5135c677. All other jobs were green or still running when I last looked; they re-run on the new head.

Behavior change (flagged per Deliverables #4):

  • auto-fold backoff arming — OLD: always armed the 10-min cooldown on any growth-armed no-progress fold → classic nudges resumed every cycle. NEW: arms ONLY when ≥1 candidate passed the list gates; when nothing foldable remained it forwards quietly with an info log, no backoff. This is precisely what breaks the ~10-min nudge-churn loop in [Bug][preflight] range selector re-nominates a fully-folded span every turn — permanent "no new compressible messages" rejection loop + nudge churn #2638 (arming backoff in lean steady state was the amplifier, not the disease).
  • model-visible nudge content — structurally-dead spans no longer appear in the advertised compressible-ranges list (all four lanes). Intended: stops steering the model into atomically-refused compress calls.

Both deliverables present: host-side defense = this PR; the kernel-side root (recommend not mirroring applySingleRange's live-carrier carve-out) = filed as #2663, compliant (来源 marker, mechanism-scoped, sibling facets mediaExcluded/integrity-withdrawal kept together, Kernel-Boundary gating noted).


结构化八问:

  1. 是什么问题:内核 recommend 侧把「活 checkpoint carrier」当普通可压缩文本广播,apply 侧却按 fix: detect codex compaction requests before preflight; verbatim passthrough when not intercepted (#332) #335 把它们挖掉;当一个位置区间整段被活跃 block 覆盖时预览永远报 "no new compressible messages"。宿主 preflight 的 skipSet 又是每调用即弃,于是每个 turn 重复提名→拒绝,死质量又永远压不住增长目标 → auto-fold 空转 + classic nudge 复活指向同一死区。
  2. 什么原因导致的:根因在内核 advertise/validate 不对称(recommend 未镜像 applySingleRange 的 live-carrier carve-out);本 PR 修的是宿主放大层——无跨请求记忆 + 无差别 backoff + 死区仍被广播给模型。
  3. 影响范围与严重程度:长会话(数百~近千 refs、已有多 fold block、含 checkpoint-carrier 几何)下持续出现;表现为每 turn 的 warn 刷屏、auto-fold 空转日志、nudge churn 拉模型做被拒的 compress 调用。不丢数据、不破会话功能,但浪费算力并让模型陷入压缩记账。属特定条件下的功能性损耗(非完全不可用)。
  4. 怎么修复的:三层宿主防御——① session 级 dead-range 记忆(预览返回结构性空判定时记录,key=精确 startRef:endRef,覆盖 block 生命周期变化才失效、append-only 增长永不失效);② 抑制项从 preflight 候选走查和 nudge 广播两个出口统一剔除(单一 choke point);③ 修正 backoff 误分类——仅「有候选但折叠失败」时武装,纯 lean 稳态不再武装。不改内核。
  5. 是否有回归问题:审过的既有行为均保持——非死候选走查不变、真链失败仍武装 backoff、nudge 只剔结构性死区不伤活候选、持久化仅新增可选 metadata key(向后兼容)、无配置面新增。唯一行为变更见上(backoff 武装条件 + 模型可见 nudge 内容),均为有意且已披露。
  6. 是否破坏缓存:不涉及压缩缓存/前缀缓存失效策略;dead 记忆是独立 session metadata,不影响 prefix-cache 或增量游标。
  7. 是否改了设计方向:不改架构/边界/数据流,是宿主侧防御机制补充。方向性修复(recommend 镜像 apply 的 carve-out)已单列 [kernel][recommend] selector advertises spans the apply side structurally rejects — live-carrier screening missing (permanent advertise/validate disagreement) #2663 走内核 Boundary。
  8. 是否引入了新的配置:无新 env/config/CLI flag;仅内部 session 状态 preflightDeadRanges(capped 64),无需迁移。

判定:可合(人工合并)。 触碰 server.ts(load-bearing infra)且改变模型可见 nudge wire 内容,按 §7.4 必须人工合并、不可 auto-merge;owner 直接 merge 即可。CI 除我修的 unused-exports 外其余 job 在新 head 上重跑中,以 CI 为准。

@ranxianglei
ranxianglei merged commit 06c71ba into master Oct 20, 2026
28 checks passed
ranxianglei added a commit that referenced this pull request Oct 20, 2026
[PR] Batch-B integration: fold budget/eligibility — merge #3353 #3943 #3952 #3867 #2660 #3677 (#3916)
@ranxianglei ranxianglei changed the title fix(#2638): stop preflight re-nominating structurally-dead spans every turn [PR] fix(#2638): stop preflight re-nominating structurally-dead spans every turn Oct 20, 2026
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.

[Bug][preflight] range selector re-nominates a fully-folded span every turn — permanent "no new compressible messages" rejection loop + nudge churn

1 participant