Skip to content

fix+test(#2676): dsh durable-guard lane keeps fork adoption usable - #2686

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-10_dsh-guard-fork-adoption
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-10_dsh-guard-fork-adoption

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Stacked on #2625 (same mechanism family: kernel BLOCKED sentinel vs forkSnapshot invariant). Two commits:

  1. fix(#2676): the forkSnapshot invariant error now names the offending message — raw/ref mapping inconsistent (msg i/N role=… tool=… ref=… rawId=…). The bare string gave no clue which of hundreds of snapshot entries broke the mapping (root-causing [bug]dsh 在191版本上或者说之前版本,分支(带上下文窗口)以及带上下文的子智能体会一直静默没反应 #2676 locally took hours to identify "msg 2/7").
  2. test(#2676): regression test for the dsh durable-guard lane path — a session bound to x-bili-plugin: dsh whose history contains an Instructions from: workspace-instructions carrier gets the kernel BLOCKED sentinel via the host-level isMessageProtected hook (dsh 车道:AGENTS.md(workspace instructions,user 消息形态)被折叠后从 wire 消失 —— 与 #2419 同类,但 #2428 白名单只覆盖 <available_skills> #2447), and snapshot/fork/child-parity must all stay usable.

Why (evidence)

Local repro of #2676 (dsh 0.2.0-rc.2 headless, two-phase --session-id resume + subagent_fork, deterministic fake upstream, bili built from v0.1.191 content): every run failed fork adoption with 409 SNAPSHOT_UNAVAILABLE: raw/ref mapping inconsistent. Chain: dsh durable-message-guards pin carrier user-messages from folding → kernel assigns BLOCKED refs (byRef never holds them) → pre-#2625 forkSnapshot() required a byRaw/byRef roundtrip for EVERY snapshot entry → threw → client degraded to raw replay without inherited compression state. With large parent histories that replay hits the preflight/overflow path (#2383 shape) — the "silently unresponsive" symptom reported for 分支/fork subagents on ≤v0.1.191.

#2625's tests cover only the protectedTools trigger (ask_user_question pairs); the guard path (plain user messages protected by the host hook) was untested. New test: fails on unfixed master (verified against 7c993f9: 409 SNAPSHOT_UNAVAILABLE), passes here. Targeted tests/plugin-fork.test.ts: 46/46 green; typecheck clean.

Behavior change (flagged)

forkSnapshot error text: raw/ref mapping inconsistent → raw/ref mapping inconsistent (msg …) — prefix preserved (existing regex assertions still match); consumers are the 409 response body and the client-side degraded warn line. Reason: diagnosability, no semantic change.

Merge order

Base = #2625's head branch. If #2625 merges first, I'll rebase onto master so the diff is exactly these two commits. Closes #2676 once both land.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始按 PR Review 规范审查 #2686(stacked on #2625,同机制族:kernel BLOCKED sentinel vs forkSnapshot 不变量)。先审方向与既有行为,再本地跑定向测试(tests/plugin-fork.test.ts)+ typecheck,最后给结构化八问结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论(结构化八问)

  1. 是什么问题:[bug]dsh 在191版本上或者说之前版本,分支(带上下文窗口)以及带上下文的子智能体会一直静默没反应 #2676 —— dsh durable-guard lane(x-bili-plugin: dsh,历史含 Instructions from: 工作区指令载体)做 fork adoption 时每次都 409 SNAPSHOT_UNAVAILABLE: raw/ref mapping inconsistent,客户端降级为裸重放、丢失继承的压缩状态;大父会话历史下进一步撞上 preflight/overflow(DSH 分叉会话后触发大量 preflight overflow compress #2383 形态),表现为分支/fork 子 agent「静默无响应」(≤v0.1.191)。本 PR 补两块:错误信息点名肇事消息 + guard 路径的回归测试。
  2. 什么原因导致的:分层——根因在 fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 修的机制层:kernel 对受保护消息按设计分配 BLOCKED 哨兵 ref,而 byRef 永不持有它;旧代码对每个 snapshot 条目都要求 byRaw/byRef 数字 ref 往返,遇到哨兵必炸。本 PR 的两个 commit 不碰该机制:①不变量报错从裸字符串升级为带 msg i/N role/tool/ref/rawId前16位 的定位信息(本地定位 [bug]dsh 在191版本上或者说之前版本,分支(带上下文窗口)以及带上下文的子智能体会一直静默没反应 #2676 花了数小时找「msg 2/7」的直接动机);②fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 的测试只覆盖 protectedTools 触发器(ask_user_question 对),host hook(isMessageProtected,dsh 车道:AGENTS.md(workspace instructions,user 消息形态)被折叠后从 wire 消失 —— 与 #2419 同类,但 #2428 白名单只覆盖 <available_skills> #2447)保护普通用户消息这条路径此前无测试。
  3. 影响范围与严重程度:受影响面 = dsh lane 中含持久载体(skill catalog / AGENTS.md 基线 / runtime-context / MCP catalog 四种 marker 任一)且走 fork/subagent_fork 的会话;≤v0.1.191 上该类 fork 完全不可用并静默降级(严重)。本 PR 本身不改运行时行为(仅错误文案 + 测试),无独立用户面影响。
  4. 怎么修复的:机制修复在 fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625(把「所有条目都有数字 ref」这个错误假设从 forkSnapshot/publicForkInputMatches/parseForkRequest/handlePluginFork/planForkAdoption/applyForkAdoption 六处移除,byRef 一律不写哨兵)——是修生产者而非在传输层过滤症状。本 PR:错误文案加定位后缀(前缀保留);新增 dsh lane 全链路回归(snapshot→BLOCKED 断言→fork 201→子代 parity deepEqual→byRef/byRaw 不变量→fork 后继续对话)。
  5. 是否有回归问题:审过的既有行为逐项——(a) forkSnapshot 错误文本:消费方仅 409 响应体 + fork-adopt.ts 客户端降级 warn 行,前缀保留,fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 的负向测试 regex /raw\/ref mapping inconsistent/ 仍命中(我本地跑过,绿);PR 已按要求披露 old→new。(b) sendIntentModel 新增尾参默认 "ekko-agent",既有 45 个调用点零变化。(c) fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 base 随本 PR 一起落地:含保护消息的会话从「恒 409 / byRef 写脏 BLOCKED 键」变为可正常 snapshot/fork/adopt——即 [Bug][plugin] protectedTools 的 BLOCKED 映射导致纯文本 snapshot 返回 409 #2620/[bug]dsh 在191版本上或者说之前版本,分支(带上下文窗口)以及带上下文的子智能体会一直静默没反应 #2676 的预期修复本身;parseForkRequest 放宽接受 "BLOCKED" 常量后,handlePluginFork 用父会话服务端自身 snapshot 派生 prefix 并要求 stableJson(prefix) === stableJson(request.orderedMessages) + orderHash 双重比对(src/plugin.ts:1113-1114),客户端无法注入任意 (rawId, BLOCKED) 对,末了还有 forkSnapshot(child) 复验——已逐行核过,安全。(d) fail-fast 语义未变:真损坏仍 409(负向测试钉住)。结论:无无意回归。
  6. 是否破坏缓存:不涉及。ref 游标/去重键逻辑本 PR 未触碰;fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 仅把哨兵排除出 byRef/tokenSnapshot/maxIndex 写入(Number("".replace)=0 本也不会推进 maxIndex,属防御性),ref 命名空间保留逻辑(structuredClone + reserved loop)不变。
  7. 是否改了设计方向:不涉及。方向 = fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 已定下的「BLOCKED 哨兵是合法 snapshot ref,byRef 永不持有」,本 PR 是其诊断性与测试补齐,同机制族内收口。
  8. 是否引入了新的配置:不涉及。

验证证据(本地,head de65fcf):typecheck 干净;定向 tests/plugin-fork.test.ts + tests/fork-adoption-plan.test.ts 49/49 绿;新测试在未修 master(b8efa0490 + 本 PR 测试文件)上实测失败,失败形态与 PR 声明一致:expected: 200, actual: 409,body {"code":"SNAPSHOT_UNAVAILABLE","error":"Error: raw/ref mapping inconsistent"}——测试有牙,机制链描述属实。CI:head 上 8 条 e2e workflow 全绿;主 CI(typecheck+全量+kernel/pi-subagents 套件+build)未跑——因为 base 是 #2625 分支而非 master,stacked PR 的正常现象,不是缺陷。diff 整洁:2 文件 +36/−4,每行都与目的相关,无顺手杂项。

合并判定:代码与行为均通过审查,可合,但按 PR 自述顺序执行——先合 #2625,再把本 PR rebase 到 master(届时主 CI 会在最终 diff 上跑全量门禁);若直接以 stacked 形态合并,两个 PR 会进同一个 merge commit,master push CI 同样兜底,二选一由你定。无需改动,等 #2625 落地即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 上游冲突已解决(结构化八问)

  1. 是什么问题:系统转发 merge_conflict —— 本 PR 与 base 分支 2026-10-10_protected-tools-snapshot 冲突。实际原因不是普通分叉,而是 fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 分支被 force-push 重写(b663386fa→708217538):按你的 review 意见新增第三笔提交「refactor: express kernel-protected messages as null refs on the fork wire」——我上轮 review 时指出「六处接受哨兵是打补丁」,重构后协议改为 ref 可选、哨兵在单一边界映射为 null、字面量 "BLOCKED" 不再出现在任何 wire 字节里。
  2. 什么原因导致的:我的 dsh 回归测试断言的是旧 wire 形态 assert.equal(refs[1], "BLOCKED");新 base 上 snapshot 的 orderedMessages 该位置渲染为 null。fix 提交本身(forkSnapshot 错误文案)与新 base 零冲突——不变量那一行在新 base 原样保留,只在 map 末尾多了一步 sentinel→null 映射。
  3. 影响范围与严重程度:仅本 PR 的可合并性(dirty → clean);无用户面影响。新 base 的 null-ref 契约对旧客户端的兼容性已在 fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 分支内论证(受保护会话修复前本来就全 409/400,无存活消费者)。
  4. 怎么修复的:rebase = cherry-pick 两笔提交到新 base(均干净落地),随后把 dsh 测试断言适配为 assert.equal(refs[1], null) + assert.ok(!refs.includes("BLOCKED"))(与 fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 兄弟测试同款风格),并加一行注释说明 null 的来源(否则裸 null 断言会被误读成缺 ref bug)。内部 session-state 断言保持不动且仍然正确:byRaw 仍含哨兵(handlePluginFork 写 ref ?? BLOCKED_REF)、byRef["BLOCKED"] 仍必须为 undefined——内核不变量未变,变的只是 wire 表示。
  5. 是否有回归问题:rebase 后 head 本地实测 typecheck 干净、定向 tests/plugin-fork.test.ts + tests/fork-adoption-plan.test.ts 49/49 绿。消费方核对:src/agent/fork-adopt.ts 的 snapshotOf 已接受 identity.ref === null;PLUGIN.md en/zh 已文档化 null;parseForkRequest 现在只收 mNNNNN 或 null(对垃圾输入比旧版更严)。diff vs 新 base 仍是 2 文件(src/plugin.ts +6/−2,tests +36/−2),每行都与本 PR 目的相关。
  6. 是否破坏缓存:不涉及(ref 命名空间/去重键逻辑两笔提交均未触碰)。
  7. 是否改了设计方向:本 PR 侧没有改方向——完全对齐你在 fix: accept the kernel BLOCKED sentinel in plugin snapshot/fork validation (#2620) #2625 上定的 null-ref 方向;我的两笔提交定位不变:错误诊断信息 + guard 路径回归覆盖。
  8. 是否引入了新的配置:不涉及。

状态:force-push de65fcfc9 → da57464c8(仅 PR 分支,--force-with-lease);API 复核 mergeable: True,冲突已清。CI:新 head 上的 workflow 刚在排队,主 CI 依旧要等 #2625 合入 master 后 rebase(或 stacked 直合走 master push CI)才跑全量。判定:可合,顺序仍建议 #2625 先行。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Heads-up for the rebase once #2625 lands: this PR branched from 9136c63, BEFORE the "express kernel-protected messages as null refs on the fork wire" refactor (b663386, now 7082175 on the rebased #2625). The dsh-guard test added here asserts refs[1] === "BLOCKED", but the final contract renders protected messages as null on the wire (refs[1] === null, !refs.includes("BLOCKED") — same shape as the #2620 test in plugin-fork.test.ts). The internal-sentinel asserts (byRef["BLOCKED"] === undefined, byRaw values include BLOCKED) stay valid. Happy to do the rebase + assertion update after #2625 merges.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 这个 rebase 已经做完了,不用你再动手:

现在只剩 #2625 合入 master(它目前 mergeable,base 略落后于 master,合并时顺手 rebase 即可);之后本 PR 可直接合,或按你习惯先对 master 再 rebase 一次让主 CI 跑全量——两者都可以走。

@ranxianglei
ranxianglei force-pushed the 2026-10-10_dsh-guard-fork-adoption branch from da57464 to 85d8c37 Compare October 11, 2026 04:37
@ranxianglei
ranxianglei changed the base branch from 2026-10-10_protected-tools-snapshot to master October 11, 2026 04:37
@ranxianglei
ranxianglei merged commit d5bee77 into master Oct 11, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.258-master.d5bee77 (rolling master tag).

npm install -g billion-context@0.0.258-master.d5bee77  # 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.

@ranxianglei
ranxianglei deleted the 2026-10-10_dsh-guard-fork-adoption branch October 15, 2026 05:33
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]dsh 在191版本上或者说之前版本,分支(带上下文窗口)以及带上下文的子智能体会一直静默没反应

1 participant