Skip to content

[PR] fix: follow the live persona fork when a host-stamped dsh id hits a frozen anchor (#2241) - #2244

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-06_dsh-persona-fork-tool-routing
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-06_dsh-persona-fork-tool-routing

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

#2241: in dsh native mode a mid-session /model switch changes the main lane's system text, so the persona fingerprint (KDD #9) forks that lane onto <id>|sub:<fp> — while the host keeps stamping the bare id on every tool call (src/agent/dsh-native.ts reads its own session id; it cannot know the proxy-invented suffix). Tool routing then honored the native caller over the outbound witness (#2024) and executed every compress against the frozen pre-switch parent anchor ("husk") — every ref is unknown, 9/9 refused over 38 minutes in the field incident. Not covered by #2157 (side requests stealing the anchor): here the flocking party is the main lane itself.

Fix

In handlePluginTool, BEFORE honoring the native caller, resolve the conflicting id against known namespaces (new personaForkTarget, src/plugin.ts):

  1. witness variant — an outbound-witness session bound to <conversationId>|sub:* is the same conversation's persona fork (the exact emitter of this call): follow it.
  2. registry variant — with no witness (the ring is process memory and dies with a proxy restart), a persisted conversations entry keyed <conversationId>|sub:* that is STRICTLY fresher than the parent's entry wins. Strictly-fresher keeps the parent authoritative when the model switched back and re-anchored on the raw key.

Both variants are gated by personaForkLaneApplies(parent.metadata.pluginAgent) (src/session-id.ts — mirrors the dsh allowlist of dshPersonaFingerprintApplies): Claude Code subagents produce the same |sub: key shape for UNRELATED splits (#970), so an ungated reroute would misroute claude main-lane tool calls onto subagent sessions whenever a short-arg witness collides. If the fork target fails to resolve, the existing verbatim-id fallback re-degrades to the stamped session (legacy behavior).

Behavior change (old → new)

Case Old New
dsh-lane host-stamped id + conflicting witness bound to <id>|sub:* honor stamped session (executed on the husk) follow the fork (new log value routedBy="persona")
dsh-lane host-stamped id + no witness + registered child strictly fresher than parent execute on stamped session follow the child
non-dsh lanes / non-child witnesses / non-native callers / stale or absent children unchanged unchanged (409 fail-closed, #2024 warn path, parent execution)

The response body still echoes the host's own conversation id; no wire-format change for any client.

Config surface

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

kernel-change

None — no files under kernel/ touched.

Verification

  • New regression suite tests/issue2241-persona-fork-tool-routing.test.ts — 5 cases: witness incident repro, restart registry variant, stale-child no-reroute, lane gate (non-dsh keeps Codex Code Mode 压缩失败:MCP shim 忽略每次调用的 _meta.threadId,错误使用过期 env ID #2024 semantics), unchanged 409 fail-closed. Upstreams are SSE-framed chat.completion.chunk streams (real dsh traffic shape; the only wire whose tool_calls deltas feed the witness ring). 5/5 pass.
  • Adjacent suites green: dsh-persona-fingerprint, e2e-plugin-tool-routing, host-native-caller, issue2072-native-caller-stamping (12/12).
  • npm run typecheck clean; npm run build OK. Full suite + e2e left to CI per local-test discipline.

Residual (out of scope, already noted in the #2156 triage): persistent anchoring of the first-system-owns-the-raw-key invariant across proxy restarts is a kernel-boundary design decision; the registry variant above bounds its blast radius for tool routing meanwhile.

Closes #2241

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。这是 agent 已完成的 PR(#2241 的修复),按 [PR] 处理规范走审查流程:核对分支代码、定向验证测试、按七问体例给结论。审查中,稍后回完整结论。

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-06_dsh-persona-fork-tool-routing (bdf9ab3)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2808-pr.2244.ca38aa7

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

[bot] 🏷 ## PR #2244 审查结论(七问体例)

审查动作:核对分支代码 → 发现分支落后 master 177 个提交(base 5e43209 vs 当前 c23f365,期间 #1875 ProxyToolResult 重构、#2157/#2156 persona-anchor 修复都落在同一函数上)→ rebase 到当前 master(干净应用,零冲突,diff 与原 PR 逐字节一致)→ 在 rebase 后的 head 上跑定向验证 → 已 force-push 回 PR 分支(df8ffed45,lease 保护)。全量回归按本地测试纪律留给 CI,新 head 的 CI 正在跑。

七问

  1. 是什么问题:dsh native 模式会话中 /model 切换会改变主 lane 的 system 文本,persona 指纹(KDD#9)把主 lane 本身分叉到代理自造的 <id>|sub:<fp>;而宿主每次工具调用仍盖裸 id(dsh-native 读自己的 session id,不知道后缀)。工具路由按 Codex Code Mode 压缩失败:MCP shim 忽略每次调用的 _meta.threadId,错误使用过期 env ID #2024「native caller 优先于 outbound witness」把每次 compress 执行在切换前的冻结父锚点("husk")上——现场 9/9 全部 every ref is unknown 拒绝,压缩瘫痪 38 分钟。

  2. 什么原因导致的:路由层把 <id>|sub:<fp> 当成另一个会话,但它就是同一个会话(后缀是代理发明的,宿主无从知道)。Codex Code Mode 压缩失败:MCP shim 忽略每次调用的 _meta.threadId,错误使用过期 env ID #2024 的「native caller 权威」是为真·跨会话冲突设计的,在这里被过度应用。注意与 fix: side requests must not claim the persona namespace anchor (#2156) #2157 的区别:那边抢锚点的是侧请求,这边 flock 的是主 lane 自己,不在 fix: side requests must not claim the persona namespace anchor (#2156) #2157 覆盖内。

  3. 怎么修复的:在执行点上游(尊重 native caller 之前)把冲突 id 对照已知命名空间解析(personaForkTarget)——信任度排序:① outbound witness 环里绑定 <id>|sub:* 的会话(它点名了本次调用的确切发出方);② 无 witness 时(proxy 重启清空内存环)持久化 conversations 表中同前缀且严格更新于父条目的子条目(模型切回重新锚定裸 key 时父仍权威)。两路都过 personaForkLaneApplies 门(dsh 白名单,镜像 dshPersonaFingerprintApplies 的证据许可制)——Claude Code subagent 复用 |sub: key 形状做无关分裂(Subagent first token stalls 1-2min: withSessionLock covers full forward + slow flash upstream first byte #970),无门限重路由会把 claude 主 lane 的工具调用错投到 subagent 会话。解析失败则退回原有 verbatim 路径(行为不变)。

  4. 是否有回归问题:无。逐项审了触碰路径的既有行为:

  5. 是否破坏缓存:不涉及。不动身份哈希、前缀字节、重试/去重键;改变的只是工具调用落在哪个会话的状态上(这正是修复目的)。

  6. 是否改了设计方向:不涉及。仍在 KDD#9 证据许可制框架内——新增门控函数镜像既有指纹白名单,不是整体放开;未来其他宿主复用 id 跨 persona 需带流量证据逐个加入。

  7. 是否引入了新的配置:不涉及。无新 env/config/CLI(代码核实:personaForkLaneApplies 为硬编码 dsh 判定)。

测试有效性(质量关)

新套件是真测试:完整 server + SSE-framed mock upstream(喂 witness 环的唯一线上形状),oracle 是块落点(fork vs husk)+ 仅存在于 fork 的 ref(m00013–m00015 在 husk 上必然 unknown)——这个 bug 回归时抓得住。我做了 red-run 验证:把 src/plugin.ts 单独还原到 master 版本重跑,恰好 2/5 失败(witness 变体 + restart registry 变体,即事故本体),另 3 个语义钉(stale-child 不重路由、lane gate、409 fail-closed)通过——证明测的是机制不是实现细节。

定向结果(rebased head):新套件 5/5 + dsh-persona-fingerprint 7/7(含 #2156 锚点抢占钉)+ e2e-plugin-tool-routing 2/2 + host-native-caller/issue2072-native-caller-stamping 5/5 = 19/19;npm run typecheck 干净、npm run build OK。旧 head 的 CI 有 18/22 绿(余 4 个 test 矩阵 job 当时还在跑),已被 rebase 后的新 CI 取代。

diff 整洁度

单提交、3 文件、+376/-4,每一行都属于本修复;无锁文件/生成物连带变更(本地 install 产生的 lockfile 扰动已在推送前还原)。

判定:可合并——等 rebase 后 head(df8ffed45)的 CI 转绿即可由人合并。残余项(PR 已如实标注,同意不扩大范围):first-system-owns-the-raw-key 锚定的跨重启持久化属 kernel 边界设计决策,#2156 triage 已记录;registry 变体在工具路由层面限制了其爆炸半径。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 补充:rebase 后 head df8ffed45 的 CI 全绿(22/22,含 ubuntu/windows test 矩阵与 registry e2e)。上条七问结论维持——可合并,请人工合并:#2244

antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 6, 2026
…se history continues the raw key's chain keeps the raw key

The dsh persona fingerprint (db21309) forked on ANY system-text change
under the id, on the assumption that dsh composes its main system once
per session. /model breaks that assumption: dsh rebuilds the main system
per model, so every model switch forked the MAIN lane off the raw key
while the host kept stamping the bare id — compression then hit the
frozen husk forever (ranxianglei#2241: 266,966 pendingT1 tokens, 0 folds).

Swap the fork trigger for prefix-affinity identity semantics
(ranxianglei#1106/ranxianglei#1148: content is identity, system drift is evolution):

- src/prefix-affinity.ts: chainContinues(messages, sessionId) — the
  stored chain is a byte-exact head-anchored prefix of the incoming
  list (equal-depth byte-exact replay counts too).
- src/persona-anchor.ts (new): resolvePersonaKey — first-seen claims,
  same-system matches, and on system change: history continues the raw
  key's chain → MIGRATE the anchor (compression state stays); history
  discontinuous (auto-review flattened blob) → fork onto
  <id>|sub:<fp> exactly as before. Empty system stays non-anchoring.
  Fork id format unchanged (ranxianglei#2244 personaForkTarget compatible).
- src/server.ts: both dsh persona call sites (anthropic + openai) now
  route through dshPersonaNamespace; migrations log one info line.
- Restart race self-heals: chains are permanent (ranxianglei#1724), so even if a
  review claims the raw anchor after a restart, the next main turn's
  continuity check runs against the persisted chain and migrates back.

Tests: dsh-persona-continuity (unit state machine + openai e2e: switch/
switch-back/review-forks/diverged-forks; anthropic e2e); fingerprint
suite unchanged (review isolation, side-request verbatim, allowlist);
side-lane-invariants (D) now uses the realistic flattened review blob
(a history-replaying different-system request is the same conversation
evolving post-fix, not a persona fork).
ework-agent added 2 commits October 10, 2026 13:11
…rozen anchor (#2241)

A mid-session model switch in dsh changes the main lane's system text, so the
persona fingerprint forks THAT lane onto <id>|sub:<fp> while the host keeps
stamping the bare id on every tool call (dsh-native reads its own session id,
it cannot know the proxy-invented suffix). Tool routing then honored the
native caller over the outbound witness (#2024) and executed every compress
against the frozen pre-switch parent anchor: 'every ref is unknown', 9/9
refused in the field.

handlePluginTool now resolves the conflict against known namespaces before
honoring the native caller (personaForkTarget): an outbound witness bound to
<conversationId>|sub:* is the same conversation's persona fork and is
followed; with no witness (proxy restart empties the ring), a persisted
conversations entry under that prefix that is STRICTLY fresher than the
parent's entry wins. Both paths are lane-gated to dsh
(personaForkLaneApplies) because Claude Code subagents reuse the |sub: key
shape for unrelated splits (#970). Non-dsh lanes, non-child witnesses,
non-native callers and stale/absent children keep their exact prior
semantics; a fork target that fails to resolve degrades to the legacy path.

Regression suite: tests/issue2241-persona-fork-tool-routing.test.ts
(witness incident repro, restart registry variant, stale-child no-reroute,
lane gate, unchanged 409 fail-closed) on SSE-framed upstreams — the wire
that feeds the witness ring.

Fixes #2241
…semantics (#2601)

The fixture's switch turn was a byte-exact extension of the anchor turn, so
on master (with #2247's continuity-aware migration, which postdates this
branch's base) it MIGRATES the anchor instead of forking — all five routing
tests died in setup. The field incident (#2601) proves the real switch breaks
the chain (history rewrite or cross-lane normalization), so the switch turn
now drifts the first historical message to reproduce a genuine fork. Adds one
test pinning the boundary: a byte-stable same-lane switch migrates (no fork),
and bare-id native calls stay on the raw key with nothing to reroute to.
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):目标 issue #2241 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

@ranxianglei ranxianglei changed the title fix: follow the live persona fork when a host-stamped dsh id hits a frozen anchor (#2241) [PR] fix: follow the live persona fork when a host-stamped dsh id hits a frozen anchor (#2241) Oct 24, 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

1 participant