Skip to content

[PR] fix(#4305): standing generation-boundary note so the model stops compressing dead refs after a model switch - #4308

Closed
ranxianglei wants to merge 4 commits into
masterfrom
wt-4305-ework-daemon
Closed

ranxianglei wants to merge 4 commits into
masterfrom
wt-4305-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4305

Problem

After a mid-conversation model/upstream switch the conversation's ref ledger restarts at m00001 while the client-persisted history keeps citing previous-generation refs — old compress receipts, acp_status outputs, block summaries, the model's own earlier replies. Those citations look exactly like live refs, so the model keeps aiming compress at dead ranges until the circuit breaker fires (incident session 01a15993: five gates rejected in a row, breaker armed, [acp-drift] noise on every subsequent request). The reactive receipts already name the frontier (#1029 snapshot, #2146 beyond-frontier note, #4252 clamp note) — but the incident shows the model flails through them anyway, so the fix has to be a STANDING part of the context.

Fix (issue proposal 1 of 3)

New host-side module src/generation-boundary.ts:

  • One-shot evidence-based detection at prepare time: scan the visible core history for message-ref citations STRICTLY ABOVE the session's highest mapped ref (the provably-dead class — a session allocates no future refs). Requires ≥2 DISTINCT such refs (prose false-positive guard); early-exits once evidence is sufficient.
  • Verdict persisted in session metadata (generationBoundary) → survives restarts, renders deterministically for the session's lifetime.
  • A static, number-free note is appended to the ACP standing system block on every wire (openai / google / responses developer message / anthropic injectSystem) and mirrored in the round-2 fold rebuild (relay.ts) in the exact steady-path order (prompt → note → absorb) so the prefix-cache seam holds.
  • Display-only: no storage rewrite, no ref-space surgery, no gate/breaker changes. No numbers in the text by design (the frontier advances as the session allocates; concrete ceilings stay with the reactive notes, which always quote live values).

Behavior change (disclosed per policy)

  • OLD: after a generation reset, nothing in the rendered context told the model that visible old-generation refs were inert.
  • NEW: sessions whose visible history contains ≥2 distinct above-frontier ref citations carry one static paragraph (~640 chars) in the ACP standing system block, from the first request that sees the residue onward.
  • Cache impact: in the incident shape the residue is present from request fix: keep system prompt byte-stable for prefix cache #1 of the new generation, so the note rides from the start and there is NO mid-session prefix flip; worst case is one one-time append if residue appears later. Unaffected sessions: zero bytes added.

Both compression modes

  • Proxy mode: note rides the full compress-prompt slot.
  • Plugin/dsh mode (compressSurfaceOff): rides the tags-only slot — the lane that produced the incident.
  • Title-gen and renderNone views: excluded (no ACP surface → nothing stale visible).
  • Responses compaction-trigger passthrough: excluded.

Tests

tests/generation-boundary.test.ts (10 tests): detection positive / below-frontier negative / distinctness guard / fresh-session (empty ledger) / tag-shaped residue / prose single-stray guard / idempotent short-circuit / malformed-record rejection / note contract / injectSystem append + ordering vs attribution line. Targeted local runs green: this file plus ptc-runcode-tools, prompt-pack-tool-prompts, plugin-nudge-injection, issue2432-breaker-awareness (42 tests total); typecheck + build green; full suite via CI.

Boundaries

…ef residue

After a mid-conversation model/upstream switch the ref ledger restarts at
m00001 while the client-persisted history keeps citing previous-generation
refs, which look exactly like live ones — the model keeps aiming compress at
dead ranges until the circuit breaker fires. The reactive receipts (#1029,
#2146, #4252) already name the frontier but the incident shows the model
flails through them, so the fix is a STANDING part of the context.

One-shot evidence-based detection (>=2 distinct above-frontier citations in
visible history), verdict persisted in session metadata, static number-free
note appended to the ACP standing system block on every wire plus the
round-2 fold rebuild in exact steady-path order. Display-only: no storage,
ref-space, gate or breaker changes.
@ranxianglei ranxianglei changed the title fix(#4305): standing generation-boundary note so the model stops compressing dead refs after a model switch [PR] fix(#4305): standing generation-boundary note so the model stops compressing dead refs after a model switch Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-4305-ework-daemon (24ca4e6)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.5118-pr.4308.105e0e7

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-pr4308.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] 镜像,不重做工作——进入 PR review 流程(方向关 → 回归 → 代码 → CI)。

查重: 不重复。 open+closed 全量检索无同机制在途项:

标签: bug dsh scope/wiring p2(缺陷修复;事故车道 dsh;改动面是请求管道 wire 注入层而非 kernel;严重度随原 issue #4305:p2,能用但有明显问题)。

CI 初查(head ae1f0f0):多数门禁绿,unused-exports 红——正在本地复现并修;随后按八问体例给完整 review 结论。

@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/wiring labels Oct 22, 2026
awork added 3 commits October 22, 2026 21:38
…2 spaces)

Review nit from #4308 review: the new relay.ts lines were indented one space
deeper than the surrounding block. Whitespace-only, no behavior change.
… tags-only surface

Two coverage gaps found in #4308 review:
- The compress-loop round-2 rebuild recomposes the ACP standing system by
  hand; nothing pinned that a boundary-ACTIVE session keeps byte-identical
  system bytes between the steady request and the post-fold re-request
  (the same seam class #3298/#2499 fixed for attribution/cache marks). New
  tests/issue4305-round2-seam.test.ts drives one real fold through the
  anthropic wire with previous-generation residue seeded in the early turns
  and asserts round-2 system === round-1 system byte-for-byte.
- The tags-only ACP surface (plugin/dsh lane, compressSurfaceOff — the lane
  that produced the #4305 incident) had no injection assertion; added a
  positive+negative pair to tests/generation-boundary.test.ts.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Review 结论:可合(head 24ca4e649 全 CI 车道绿;合并动作由人执行)

结构化八问

  1. 是什么问题:会话中途切换模型/上游后,新世代的 ref 账本从 m00001 重新开始,但客户端持久化历史里的旧世代引用(旧 compress 回执、acp_status 输出、块摘要、模型自己的回复)仍然可见——模型把它们当活引用,持续对死区间发起 compress,直到连续被门拒绝并触发熔断(事故会话 01a15993:五连拒 + 每请求 [acp-drift] 噪音)。
  2. 什么原因导致的:ref 按会话世代独立分配(ACP 状态标记被拼接进用户消息文本块;跨会话代际 stale refs 压缩整批失败 #1029/模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001),而渲染出的 transcript 没有任何常设信号告诉模型「上一世代的引用已失效」。既有反应式提示(ACP 状态标记被拼接进用户消息文本块;跨会话代际 stale refs 压缩整批失败 #1029 snapshot、dsh内部问题 出现这个错误后,重启dsh可以发消息 但陷入无限压缩失败 #2146 beyond-frontier、compress calls rejected when the summary text rides in content next to top-level startId/endId — plus U+2212 dash silently folds the wrong range #4252 clamp)只在误调用之后才出现,事故表明模型看到它们仍在乱撞——所以提示必须是常设驻留的上下文部分。
  3. 影响范围与严重程度:仅影响「中途发生过模型/上游切换、且可见历史含 ≥2 个不同超界 ref 引用」的会话——即事故形状本身;其余会话零字节增量。严重度 p2:能力可用,受影响会话有浪费的 compress 调用、熔断武装与每请求噪音,不损数据与可用性。
  4. 怎么修复的:prepare 时一次性证据化检测(扫可见历史中严格高于本会话最高已映射 ref 的引用,要求 ≥2 个不同值防散文误报),verdict 持久化进 session metadata(重启存活、此后确定性渲染),并在 ACP 常驻 system 块追加一段无数字静态说明(~640 字符)。纯展示:不改存储、不动 ref 空间、不改门/熔断。无数字是刻意的——frontier 随分配前进,具体上限继续留在反应式注释里。
  5. 是否有回归问题:逐项审过既有行为(清单见下),未发现无意回归。高危模式逐一过:无语义漂移(detect=false 时输出逐字节不变)、fail-fast 未变、无阈值/时序漂移、输出格式变化仅披露的那段追加文本。
  6. 是否破坏缓存:不破坏。note 只骑在 ACP 自有领地(常驻 system 块),客户端字节未动;事故形状下 residue 自新世代第一个请求就存在,note 随前缀一起上线,无 mid-session flip;最坏情况是 residue 后现时的一次性追加。round-2 折叠重建与稳态保持字节一致——本次 review 补了测试钉住(此前该接缝无人钉)。
  7. 是否改了设计方向:没有。这是 Switching model mid-conversation restarts the ref ledger, but the rendered transcript still shows the old refs — the model keeps aiming compress at dead ranges until the circuit breaker fires | 切模型后消息编号整体换账本,但渲染历史仍显示旧编号,模型对着死区间反复压缩直至熔断 #4305 三个提案中的提案 1(display-only 边界标记),不碰提案 2/3(stale stamp 清理 / acp_status 暴露账本跨度)的方向;架构/边界/数据流不变。
  8. 是否引入了新的配置:没有。零新字段/env/flag;硬编码常量沿用 dsh内部问题 出现这个错误后,重启dsh可以发消息 但陷入无限压缩失败 #2146/[Bug][preflight] range selector re-nominates a fully-folded span every turn — permanent "no new compressible messages" rejection loop + nudge churn #2638 先例。

审过的既有行为清单(逐项结论)

  • 四个 prepare* 车道(anthropic/google/openai/responses)的 sysParts/devParts 组装:detect=false 时逐字节一致 → 保持 ✓
  • 稳态顺序 prompt→NOTE→absorb 与 relay round-2 重建顺序:逐行读 relay.ts:1848/1865 验证 join 等价 → 保持 ✓
  • title-gen / render-none / compaction-trigger passthrough 排除:分支级核对,这些视图不带 ACP surface 也不带 note(responses 车道 detect 会执行但从不渲染,verdict 记录无害且单调)→ 保持 ✓
  • injectSystem 签名:第 8 参可选默认 false,全仓唯一调用方 prepare-anthropic → 无波及 ✓
  • session metadata:新 key generationBoundary 每会话至多写一次,走既有 markDirty 持久化,不动既有 key → 保持 ✓
  • 日志:新增每会话一条 [acp-gen-boundary] info(仅首检时)→ 有意变更,已披露 ✓
  • config/env/wire 协议/kernel/version:均未触碰 ✓

Review 期间补入的修复(additive commits,已推 PR 分支)

残留(不阻塞)

  • google/openai/responses 三车道没有逐车道直接注入测试(均为已钉住的 anthropic 路径的单行镜像,风险低——记录在案,不单开 issue);
  • note 首句把 reset 归因于「model/upstream switch」——fork/派生会话的行承 residue 也可能触发检测,措辞略过指,但操作指引(「以 acp_status 为准」)依然成立;
  • 事故提到的每请求 [acp-drift] 日志噪音本 PR 未处理(本 PR 范围是展示提示,噪音属既有观测面)。

行为变更披露(按政策)

OLD:世代重置后,渲染上下文中没有任何东西告诉模型旧世代引用已失效。NEW:满足上述条件的会话从首个看见 residue 的请求起,ACP 常驻 system 块内多一段静态段落(~640 字符);不受影响的会话零字节。缓存影响见第 6 问。

判定:可合。 head 24ca4e649 全部 CI 车道绿(6 个 test shard + 双平台 static-gates + unused-exports/config-surface/version/kernel/lane/lock-sync/docs 各门禁);PR 分叉后 master 多一个合并(#4188,preflight 相关,与本 PR 触碰文件无重叠,GitHub 显示 mergeable)。请人工合并:#4308

ranxianglei added a commit that referenced this pull request Oct 24, 2026
…#4308 follow-up) + register BILI_CODEX_STATE_MODE in LIFECYCLE.md (#3321 follow-up, also red on master)
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4551(master 合并,merge commit 保留原作者署名)。本 PR 关单收尾;回滚点为 #4551 单提交 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 dsh p2 scope/wiring

Projects

None yet

1 participant