Skip to content

[PR] fix: refuse unservable compress ranges on an empty view instead of tombstoning live refs - #3863

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-19_fix-no-visible-context-dead-refs
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-19_fix-no-visible-context-dead-refs

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Rebased 2026-10-21 onto current master (56a0f5a) — master moved twice during review (#3918 among others); the final rebase preserves upstream's new refusal-tail wording verbatim and drops the two incidental gate-fix commits below, which landed upstream independently in the meantime.

Closes #3859

What

The #3126 no-visible-context gate had a span-overlap exemption: any requested range overlapping an active block span handed the whole batch to the kernel even when the message view was fully empty. The kernel's dead-ref pass (#2362) tombstones per BOUNDARY ref not point-covered by an active block — span overlap ≠ per-ref coverage — so the reporter's ranges (overlapping some of 15 active blocks, boundary refs in the gaps between them) escaped the gate, failed to anchor (nothing anchors on an empty view), and their uncovered boundary refs were permanently recorded as DEAD. The host commits the cloned state even when zero blocks land, so the tombstones persisted.

Fix (host-side, src/stream.ts only)

On an empty view with mapped refs, the gate now yields to the kernel ONLY when every message-ref boundary of every range is point-covered by some active block's effectiveMessageIds — exactly the shapes the kernel can serve from state alone without writing anything new: the #403/#2748 in-place refolds and their "already compressed" / gate:no-net-shrink diagnostics. Block-ref boundaries are never examined by the kernel's dead-ref pass, so pure bN..bM distillation calls stay vouchable. Anything else is refused as a whole batch up front — zero state writes — keeping the existing retry-after-next-model-request receipt wording.

The predicate mirrors danglingMessageRefs (kernel/src/compress.ts) line-for-line, so host and kernel cannot drift apart again over which refs would get tombstoned.

Behavior change (old → new)

Shape (empty view + mapped refs) Old New
Range(s) with a boundary ref covered by NO block (the reported shape) passed to the kernel → "cannot be anchored" failure + uncovered boundary refs recorded DEAD (persisted) refused up front as gate:no-visible-context, zero state writes; retry after the next model request restores the view
Batch mixing a vouchable range with an uncovered one the vouchable half could land while the other half was tombstoned whole batch refused, nothing written
Covered-boundary shapes (#403/#2748 refold, net-shrink, already-compressed diagnostics, pure bN..bM calls) reached the kernel unchanged — still reach the kernel
Non-empty views / ref-less sessions gate short-circuits unchanged

Why not a fully unconditional refusal (the issue's first proposal): it regresses the pinned #403/#2748 behavior — after a full-block inline restore, a later same-span re-compress must still land from state alone (tests/refold-wiring.test.ts pins all three variants, including proxy-shaped empty views). The coverage-vouch rule closes exactly the corruption door without touching those paths.

The kernel-side alternative (distinguishing unavailable input messages from genuinely dead refs before writing tombstones) was considered and rejected: the kernel treats input.messages as the authoritative client view by contract and cannot know the host evicted its transient copy; the disambiguating signal exists only host-side, where #3126 already placed the guard. No changes under kernel/.

Config surface

None — no config fields, env vars, or CLI flags added or changed.

Tests

顺手修复的既有 master 红(独立标注 commit,与 #3859 无关)

CI 验证本 PR 时发现两个门禁在 master 上已红(查重:open/closed issue 与 PR 均无对应条目):

  1. docs-sync — 已提交的 CONFIGURATION.md / CONFIGURATION.zh-CN.md 含两行被取代的重复行(storage.unified 的 pre-Storage wrap-up: 6 fixes + switch default mode to full (single PR) | 存储收尾六修 + 缺省模式翻 full(一个 PR 统一处理) #3818-flip 默认值行、storage.sqliteAutoDownload 的 pre-SQLite unified storage degraded to legacy-only (bili v0.1.201, node v20.19.5, win32-x64) #3788 冷却文案行),与生成器输出不符。已在 master 独立合入(原 commit 81f6654ba):从 website/config-reference/*.yaml 重新生成,删除陈旧行(纯删 4 行,无语义变化)。
  2. unused-exports — src/log-mask.ts 的 maskUrlForPublish([security][web] Diagnostics blob prints private relay hosts verbatim in the config section — the "secrets masked" header only masks values, not hosts | 诊断包 config 段原样输出内网中转地址:标题说"密钥已遮蔽",但只遮值不遮主机 #3811)无任何模块 import(仅同文件 maskUrlsForPublish 调用),export 属死面。已在 master 独立合入(原 commit 26465c656):去掉 export 关键字转模块私有,零行为变更。

两者均为各 guard 规定的机械修复。最终 rebase 到 56a0f5a 后这两个修复已随上游存在,本 PR 收敛为单一 fix commit(573ae42),不再重复携带。

@ranxianglei ranxianglei changed the title fix: refuse unservable compress ranges on an empty view instead of tombstoning live refs [PR] fix: refuse unservable compress ranges on an empty view instead of tombstoning live refs Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-19_fix-no-visible-context-dead-refs (4af1753)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4909-pr.3863.d9905f9

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-pr3863.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-qwen/qwen3.8-27b)

查重: 不重复。 本 PR 是 #3859(空视图 compress 把活引用永久记成 DEAD)的唯一修复 PR。同家族条目:#3126(已关,原 gate 出处)、#2362(kernel dead-ref pass 机制来源)。本 PR 的 CI 红与内容无关——是继承自 master 的两处静态门禁红,在途 PR #3871 已在修同一根因,不另立项、不并列开修。

标签: bug / pi / scope/kernel / p2(缺陷类;Pi 插件车道触发;上下文管理核心逻辑;p2——tombstone 在下次模型请求后自愈,窗口期内只有误导性 DEAD 状态与回执,非数据丢失)。

独立审核结论(不复述 issue 侧分析)

机制核实——报告里的损坏链是真的,且闭合是精确的:

本地验证(定向,全量留给 CI):

diff 卫生: 3 文件 +183/-25,每一行都在本 PR 目的内;无 kernel/ 改动、无配置面、无版本变更;master 领先 10 提交但未触碰 src/stream.ts 或受影响测试 → 干净合并,无热文件竞争。

CI 现状(唯一一次 run @ head): 全部门禁通过,除 docs-sync 与 unused-exports 两条红——均在 master HEAD 本地复现为既有红(maskUrlForPublish 孤儿导出;CONFIGURATION.md/.zh-CN.md 各残留一行 #3818 翻转前的 storage.unified 陈旧重复行,生成器输出即删掉它们)。随后 #2637 fail-fast 分层因 guard 失败跳过了整个 test matrix,此 head 尚无全量套件信号。在途 PR #3871 的文件与本处定位逐项吻合(log-mask.ts 删导出、两份文档各删 2 行),即修这两条门禁。

结构化八问

  1. 是什么问题:Pi 插件车道里,会话消息视图被宿主清空后的 compress 调用,只要请求范围擦到任一活跃块就整批放行给 kernel;落在块间隙的边界引用锚不上,却被 kernel 永久记成 DEAD,且空落地也照常落盘。
  2. 什么原因导致的:gate 用「span 相交」近似「每个边界引用都被块覆盖」——前者是几何关系,后者是逐引用事实,两者不等价;kernel 又按契约把 input.messages 当权威客户端视图,无法区分「宿主清掉了瞬态副本」和「引用真死了」。判别信号只存在于 host 侧,[bug] 大会话 compress 持续失败:ctx has 0 message(s) 时所有 ref 被判悬空(cannot-anchor),报错归因误导 #3126 的 guard 位置是对的,只是判定式错了。
  3. 影响范围与严重程度:仅 pluginMode + 视图被清空(宿主驱逐/恢复窗口)+ 请求含未被块覆盖的 message-ref 边界的组合;proxy 模式视图每轮重建非空,不受影响。p2:期间回执误导、DEAD 状态错标,但下次模型请求后视图重建、tombstone 自动清除,会话可继续;非数据丢失、非不可用。
  4. 怎么修复的:把放行条件从 span 相交收紧为「所有 message-ref 边界都被某活跃块的 effectiveMessageIds 逐点覆盖」——恰好等于 kernel 能纯靠状态服务、不写任何新东西的形状;其余整批前置拒收,零状态写入,沿用现有重试回执。谓词与 kernel 逐行镜像,杜绝两侧再次漂移。
  5. 是否有回归问题:审过的既有行为——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/手动 compress 仍接受零/负净收益折叠,先改写缓存再提示上下文增长 #2748 状态自足 refold 三变体(pin 测试原样绿)、净收缩/已压缩诊断、纯 bN..bM 蒸馏、非空视图短路、loop-guard 计数与 breaker 路径——全部保持;高危模式逐项无命中(无语义漂移、无吞错、无阈值/时序/格式变化)。行为变更(PR 内 old→new 表)已如实披露并核实成立。
  6. 是否破坏缓存:不涉及。拒收路径零写入,前缀缓存与存储布局不受影响;DEAD 集合反而不再被污染。
  7. 是否改了设计方向:不涉及。仍是 host 侧 gate,位置不变;kernel 侧替代方案(input 不可用 vs 引用真死的区分)按契约拒绝的理由成立——kernel 不知道宿主驱逐了瞬态副本。
  8. 是否引入了新的配置:不涉及。无新 env/config/CLI。

判定

代码审查通过,可合入。当前唯一阻塞是继承自 master 的两处静态门禁红(非本 PR 引入,#3871 在途修复);#3871 合入后本分支需一次 rebase/空推以在此 head 上取得完整 core-matrix 绿,即可由人工合并。

@ranxianglei ranxianglei added bug Something isn't working p2 pi scope/kernel labels Oct 19, 2026
@ranxianglei
ranxianglei force-pushed the 2026-10-19_fix-no-visible-context-dead-refs branch 2 times, most recently from 26465c6 to 573ae42 Compare October 21, 2026 03:20
@ranxianglei
ranxianglei force-pushed the 2026-10-19_fix-no-visible-context-dead-refs branch from 573ae42 to 0100282 Compare October 21, 2026 06:14
…mbstoning live refs (#3859)

The no-visible-context guard (#3126) exempted any request whose range SPAN-OVERLAPPED
an active block span. The kernel's dead-ref test (danglingMessageRefs) judges per
BOUNDARY ref, not per span overlap: a range can overlap one block while its boundary
refs sit in gaps between blocks. On an evicted/restarted session (view=0, refs mapped)
such requests passed the gate, reached applyCompression with an empty message list,
and the kernel recorded those still-live refs as DEAD — committed by the host even
when zero blocks were created.

The gate now mirrors the kernel's own test: on an empty view with mapped refs it
yields to the kernel only when every requested range's message-ref boundaries are
point-covered by some active block's effectiveMessageIds (block-ref boundaries carry
no raw id and can never be tombstoned). That set equals exactly the shapes the kernel
can serve from state alone (#403/#2748 restoredInline refold, already-compressed
warnings); everything else is refused up front with zero state writes, retryable once
the next model request restores the view.

Tests: flipped issue3126 test (e) (block-touching request on empty view is now
refused, no dead refs) and added tests/issue3859-no-visible-context-overlap.test.ts
(multi-range gap-boundary shape refused whole-batch; mixed batch refused; pure b-ref
distillation still yields to the kernel with its honest already-compressed warning;
non-empty-view negative row). refold-wiring suite (state-alone refold landing, #2748
net-shrink, negative control) stays green.
@ranxianglei
ranxianglei force-pushed the 2026-10-19_fix-no-visible-context-dead-refs branch from 0100282 to 4af1753 Compare October 21, 2026 06:18
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决:分支已 rebase 到当前 master(5f3b1e601)之上,新 head 4af175315,GitHub 侧 mergeable(状态 blocked = 仅剩 CI + 人工合并)。PR 内容零变化——单提交原样重放,无文本冲突。

语义组合核查(本次 rebase 的真正风险点):master 期间合入的 #3982 家族(3 个提交)重构了本 PR 改的同一处拒收路径——把 gate 抽成导出函数 noVisibleContextRefusal,并在 gate 之前新增 recoverEvictedView(从统一存储恢复被驱逐会话的视图)。逐调用点确认了组合顺序在两条车道都正确:src/stream.ts:823-824 与 src/external-summary-compress.ts:47-48 均为「先 recover、后 gate」。行为推论:恢复成功 → 视图非空 → gate 短路放行(与 #3982 前行为一致);恢复失败 → 视图仍空 → 本 PR 的逐边界覆盖担保谓词按设计生效。两侧改动无相互抵消或叠加。第二个 rebase 增量(#4114)只动 scripts/release-gate-local.mjs(CI 门禁,+5 行),与本 PR 文件零交集。

结构化八问

  1. 是什么问题:系统转发的上游 PR 冲突——本 PR 分支落后 master 约 40 个提交且与基分支冲突(dirty),无法合并。不是新缺陷。
  2. 什么原因导致的:PR 评审期间 master 快速前进,其中 compress-from-store: evicted sessions compress against the unified-store view instead of refusing forever (#3918 P4 root fix) #3982 家族重写了本 PR 触碰的 src/stream.ts 拒收区域(gate 函数化 + 前置视图恢复),分支停留在旧基上即成 stale-base 冲突——典型的长寿命分支与热文件竞争。
  3. 影响范围与严重程度:仅本 PR 分支的调度阻塞,无任何用户面影响;不 rebase 则 PR 永远不可合。
  4. 怎么修复的:标准 rebase(非 merge commit),期间 master 又前进一次([PR] gate: isolate npm metadata cache per run (Lane U stale-latest false red) #4114,纯 CI),故 rebase 两次收敛到 5f3b1e601;重点不在解冲突(无文本冲突),而在验证 compress-from-store: evicted sessions compress against the unified-store view instead of refusing forever (#3918 P4 root fix) #3982 与本 PR 在同一代码区域的语义组合顺序正确(见上)。
  5. 是否有回归问题:审过的既有行为逐项保持——compress-from-store: evicted sessions compress against the unified-store view instead of refusing forever (#3918 P4 root fix) #3982 恢复车道(tests/compress-from-store.test.ts 4/4)、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/手动 compress 仍接受零/负净收益折叠,先改写缓存再提示上下文增长 #2748 状态自足 refold pin(tests/refold-wiring.test.ts 7/7)、[bug] 大会话 compress 持续失败:ctx has 0 message(s) 时所有 ref 被判悬空(cannot-anchor),报错归因误导 #3126 原 gate pin(6/6)、外部摘要车道三套件(25/25)、本 PR 新 pin(4/4);高危模式逐项无命中(无语义漂移、无阈值/时序/回执格式变化,receipt 文案未动)。本地 typecheck + build 干净;全量套件判定留给 CI 在此 head 上跑。
  6. 是否破坏缓存:不涉及——两侧改动均不触碰前缀缓存/存储布局路径。
  7. 是否改了设计方向:不涉及——两个特性各守原方向,组合顺序(recover→gate)正是 compress-from-store: evicted sessions compress against the unified-store view instead of refusing forever (#3918 P4 root fix) #3982 review 时设计的共享结构。
  8. 是否引入了新的配置:不涉及。

收工判定:冲突已清,PR 处于可合状态,等 CI 绿后由人工合并即可;agent 侧无后续动作。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4525(master 6d7c587,合并方式 merge commit,提交保留原作者署名)。本 PR 关单收尾;若列车中对应提交出问题,回滚点为 #4525 单提交 revert。

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

Labels

bug Something isn't working p2 pi scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] no-visible-context guard is bypassed for ranges overlapping active blocks, marking refs DEAD

1 participant