Skip to content

fix(#3126): refuse empty-view compress up front instead of poisoning refs - #3136

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-14_fix-3126-no-visible-context
Oct 14, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-14_fix-3126-no-visible-context

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Closes #3126

Problem

Large-session compress calls fail repeatedly with ctx has 0 message(s) while the refs table stays intact (state has N ref(s) mapped). With an empty message list, the kernel judges every requested ref dangling and marks them DEAD in deadRefs — and because applyRanges commits the kernel state clone even on total failure, those tombstones get persisted. Receipts blame content-changed ("the messages behind those refs changed"), acp_status shows "N ref(s) can NEVER compress", and three such calls arm the loop breaker with a false cause. None of it is true: nothing changed — the proxy simply held no live message view at that moment (the in-memory copy is dropped between model requests by resident-pool eviction or restart), and the next model request restores the view and clears the tombstones anyway.

Fix (host-side only; no kernel changes)

  1. New gate in applyRanges (plus the external-summary lane): when the view is empty AND refs are mapped AND no requested range overlaps an active compression block → refuse up front with machine reason gate:no-visible-context and an honest receipt: refs intact, nothing recorded as dead, do-not-retry-until-the-next-model-request. No deadRefs written; the breaker is fed the true cause.
  2. noteCompressLoopFailure gains a forcedCause parameter so the breaker records the honest cause without re-running failure-cause inference (behavior-equivalent for all existing callers).
  3. Observability: resident-pool evictions are now logged ([session] evicted <id> … weight … budget) — previously silent, which made the empty-view window invisible in triage.

Behavior-change disclosure (required)

Before After
Empty-view compress call (refs mapped, no block overlap) kernel run → total failure → every ref marked DEAD + persisted; receipt blames content-changed / substrate-destruction; breaker arms with a false cause refused up front; reason=gate:no-visible-context; zero deadRefs written; receipt states what actually happened and when retrying becomes possible
Resident-pool eviction silent one info log line per eviction

No change to successful folds, refold (#398/#403), fresh-session diagnostics, breaker thresholds/timing, the config surface, the persistence format, or any wire shape. Already-polluted sessions need no migration: the kernel's tombstone-with-clear lifts DEAD refs automatically once their raw ids return in a resent view.

In-passing fix (already landed on master)

Found while verifying: two PRE-EXISTING failures on master — tests/compress-success-tail.test.ts #1387 fixtures assume the old kernel default preserveRecentMessages: 5; kernel commit ca93ef4 (#3058) moved it to 3 without updating them, leaving master's full suite red (masked by recently skipped test lanes). That fix landed on master independently (bd5e1ec66, #3061 fallout), so this PR's duplicate pin commit was dropped when rebasing onto current master. The new default stays pinned by tests/golden/wire-contract/kernel.json.

Deferred (tracked separately)

Verification

  • npm run typecheck clean on the rebased head.
  • Targeted local suites (21 files around applyRanges / loop-breaker / acp_status / external-summary / refold / preflight): 167/167 pass. Full-suite verdict = remote CI on the pushed head.
  • New regression suite tests/issue3126-no-visible-context.test.ts: gate fires / fresh-session passthrough / normal fold unaffected / breaker + repeat-guard honesty / block-overlap yield (refold intact) / external lane refuses before any network call.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收到,开始独立审核本 PR(不照抄 #3126 侧结论,按 PR Review 规范逐项重做):① 原 issue 方向 → ② 回归清点 → ③ 代码审查 → ④ 测试有效性 → ⑤ diff 整洁度。先核对分支与 master 的冲突状态和 CI,随后给结构化八问结论。

…refs

When the proxy holds no live message view of a session (in-memory copy
dropped between model requests by resident-pool eviction or restart) but
the refs table is intact, applyRanges fed an empty message list into the
kernel: every requested ref was judged dangling, marked DEAD in deadRefs
(committed + persisted even on total failure), and receipts blamed
content-changed / substrate-destruction while the breaker armed with a
false cause. The refs were never actually changed — the next model
request restores the view and clears the tombstones anyway.

- new gate in applyRanges (+ external-summary lane): refuse with reason
  gate:no-visible-context and an honest receipt (refs intact, nothing
  recorded as dead, do-not-retry-until-next-model-request); writes no
  deadRefs; feeds the loop breaker the true cause
- the gate YIELDS when any requested range overlaps an active
  compression block (#398/#403 refold works from state alone under a
  proxy-shaped empty view) and for fresh ref-less sessions (unchanged
  kernel diagnostics)
- noteCompressLoopFailure gains forcedCause so the breaker records the
  honest cause without re-running failure-cause inference
- resident-pool evictions are now logged (session id, weight, budget) so
  the empty-view window is observable instead of silent
@ranxianglei
ranxianglei force-pushed the 2026-10-14_fix-3126-no-visible-context branch from 850ff3d to 3b5d606 Compare October 14, 2026 06:19
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_fix-3126-no-visible-context (3b5d606)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3578-pr.3136.ed11918

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-pr3136.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

(ai: vllm-qween/qwen3.8-27b)

Review 完成。结论先行:可合并 —— 方向正确、打在了根因上、未发现回归、CI 全绿(head 3b5d6064a,30/30 checks 通过,含 ubuntu/windows × node 22/24 四个 test lane)。

审核过程(独立重做,非复读 issue 结论):

  1. 把 PR rebase 到最新 master(审核期间 master 前进过一次:fix: migrate google dsh-persona lane to personaConversationOrder (v2 everywhere) #3139 合入,与本 PR 零文件交集)。原 PR 的第二个 commit(compress 成功输出缺剩余范围快照与停止提示(pi 侧 #420/#521 对齐) #1387 fixture 钉死)作为重复移除:master 已独立落地 bd5e1ec66(compress.preserveRecentMessages default 5 → 3 (#3058) #3061 fallout)修了同样两个测试。等价性我验证过——kernel computeProtectedRefs(kernel/src/recommend.ts:69-139)里 last-N-messages 与 last-N-tokens 是并集保护,只钉 preserveRecentMessages: 5 在该 fixture 上产生相同保护集,rebase 后实测 10/10 通过。PR 描述相应段落已更新。
  2. 本地定向测试:新回归套件 6/6、compress-success-tail 10/10、applyRanges/breaker/refold/preflight/persist 周边 15 个文件 168/170。失败的 2 个(proxy-persist debounce)在干净 master 上同样失败 = 本沙箱共享 state 目录的环境产物,非本 PR 引入。
  3. 逐入口审代码路径(清单见第 5 问)+ 写了独立 kernel 探针验证一个测试未覆盖的边缘(见「额外发现」)。

结构化八问:

  1. 是什么问题:会话消息视图被清掉(resident pool 驱逐或进程重启)、但 refs 表还在时,每次 compress 调用整体失败,且代理把 kernel 标出的 DEAD refs 原样持久化 → acp_status 显示 "can NEVER compress"、receipt 甩锅 content-changed、三次调用用假原因武装 loop breaker。实际什么都没变。
  2. 什么原因导致的:生产者(host 侧根因)是 applyRanges 的提交逻辑——kernel 返回的 state clone 无条件提交,哪怕整体失败;叠加 kernel「无视图 ⇒ 所有请求 ref 判 dangling ⇒ 标 DEAD」的语义,瞬时状态(视图缺失)被写成了持久状态(tombstone)。receipt 误导与 breaker 假因是这个错误的次生后果。修法在决策点前置拒绝、不动任何 payload——root-cause 试金石通过:同一根因换形状出现时(compress 的其他入口),gate 覆盖全部入口。
  3. 影响范围与严重程度:大会话在「视图为空窗口」内调 compress 即触发(resident pool 驱逐/重启后、下一个 model request 之前)。严重度中高:压缩功能不可用 + refs 被误标 dead(下一次 model request 可自愈)+ breaker 拿假因武装可能误拦后续合法 compress。无数据丢失(raw 内容在客户端重发历史里,tombstone-with-clear 会摘掉误标)。
  4. 怎么修复的:决策点前置而非事后补救:applyRanges(+ external-summary lane)在「视图空 ∧ refs 存在 ∧ 请求范围不重叠任何 active block」时直接拒,机器原因 gate:no-visible-context,诚实 receipt(refs 完好、未标任何 dead、下个 model request 前别重试),deadRefs 零写入,breaker 拿到真实原因。重叠 active block 时让位给 kernel(fix: isolate side requests (title-gen) from main session kernel state #398/ACP_PASSTHROUGH one-click silent kill of all compression: no logs / no banners / panel invisible and non-clearable, all sibling env knobs take effect in silence | ACP_PASSTHROUGH 一键静默关死全部压缩:无日志/无横幅/面板不可见且不可清除,同族 env 旋钮全部生效于无声 #403 refold 在空视图下合法可用);无 refs 的新会话走原诊断路径不变。附带把 resident pool 驱逐从静默变成一条 info 日志(排查可见性)。
  5. 是否有回归问题:无。逐路径结论:
  6. 是否破坏缓存:不涉及。未触碰 prefix cache、重试策略、增量游标、去重键。副作用是诚实 receipt 替代误导 receipt,减少模型盲目重试的浪费请求——这是减少请求,不是缓存语义变化。
  7. 是否改了设计方向:设计方向不变,host 侧防御性修复。kernel 侧加固(input.messages.length===0 时不写 deadRefs)留作 defense-in-depth 已在 follow-up issue kernel: when the session view is empty, compress still marks all request refs as DEAD (defense-in-depth hardening for dangling-ref detection on empty views) | kernel:会话视图为空时 compress 仍会把全部请求 ref 记成 DEAD(空视图判悬空的纵深加固) #3137 立项;plugin snapshot 持久化归 Memory plane (R3): stop keeping compressed originals, CCR and snapshots fully in RAM now that the unified store has them — measure first, then lazy-load #3050,均未塞进本 PR。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值;gate:no-visible-context 只是 receipt/日志里的机器原因码,不是配置项。

额外发现(独立探针): 空视图下的 bN..bM tier-distillation 请求:refNum("b3")=3 与 m 编号 span 做数值比较,理论上可能误 yield。单独探针实测:kernel 自己在空视图下根本执行不了 block merge(有视图时 b1+b2→b3 成功;messages=[] 同一调用静默 no-op)。所以该形状旧行为本来就是静默 no-op,gate 现在的拒绝是严格改进而非回归——无需改代码;测试也未钉该形状(kernel 本身不支持,钉了等于测不存在的能力),可接受。

收工判定:可合并。 完整 CI 绿、typecheck/build 干净、diff 收敛为单 commit 且每行都与 issue 目的相关。PR 合并是 human-only,请自行合并:#3136

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

上一条首行的模型自报打错了一个字母,更正:(ai: vllm-qwen/qwen3.8-27b)。结论不变。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收到「上游 PR 冲突」转发——核实后:没有真实冲突,未做任何操作。按「不重复 rebase、不硬救」原则处理。

核实依据(实时 GitHub API,非缓存):

  • mergeable: true(无冲突);
  • base = master @ 322f9d219 —— 与本次审核 rebase 所用的 base 完全相同,master 自上次 rebase 后零前进;
  • head = 3b5d6064a(已推送的 rebase 后单 commit)。
  • 通知里的 "dirty" 是 force-push 后 GitHub 异步重算 mergeability 的窗口期状态(或把 blocked 误读为 dirty)。此刻真实的 mergeable_state: blocked 含义是必需检查未完成,不是冲突。

CI 现状(同一 head): 30 个检查中 26 个 success;4 个 test lane(ubuntu/windows × node 22/24)在重跑——原因是我此前更新 PR 描述正文(修正过期的 in-passing-fix 段落)触发了 pull_request 的 edited 事件重跑工作流。代码与上一轮 30/30 全绿的完全一致,无新变量;若重跑出现红项我会立即跟进。

八问(本次为误报核实,多数不涉及):

  1. 是什么问题:系统报 PR 与 base 冲突(merge state: dirty)。
  2. 什么原因导致的:通知基于 force-push 后的过期中间态;实际 master 未移动、PR 可合并。
  3. 影响范围与严重程度:无影响——误报;分支与代码状态正确。
  4. 怎么修复的:无需修复。核实实时状态后确认无冲突,不执行无意义的第三次 rebase(同 base rebase 只会换 head SHA、白白重启全套 CI)。
  5. 是否有回归问题:不涉及(零变更)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

收工判定:维持原结论——可合并(待 4 个重跑检查回绿后即可);合并是 human-only,请自行操作:#3136

@ranxianglei
ranxianglei merged commit 1d5a420 into master Oct 14, 2026
34 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.426-master.1d5a420 (rolling master tag).

npm install -g billion-context@0.0.426-master.1d5a420  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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] 大会话 compress 持续失败:ctx has 0 message(s) 时所有 ref 被判悬空(cannot-anchor),报错归因误导

1 participant