Repository navigation
fix: side requests must not claim the persona namespace anchor (#2156) - #2157
Conversation
subagentNamespace anchors the raw key to the FIRST system seen under an identity, but identity resolution ran BEFORE the #388 side-passthrough short-circuit — so a dsh side request arriving first stole the anchor and forked every real main turn onto |sub:<fp>, leaving the host-stamped bare id with zero refs and compress failing permanently. Side requests now resolve verbatim: they neither read nor write the anchor (they never touch kernel state). Covers both facets of one mechanism: side-first anchor theft, and post-anchor side requests riding junk |sub:<fp(side)> sessions instead of the main key. Same fix lands on the proxy-mode Responses side shape (instructions-fingerprint branch) which had the identical race.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2210-pr.2157.59f3c91This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2157.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到 — 这是本 PR(#2157 → Closes #2156)的镜像 issue。当前状态:PR open、head |
[bot] 🏷 [PR] 核对结论 —— 本 PR 是我在 #2156 上的工作产物(07:12Z 开出)。按 [PR] 流程不重做:拉分支逐行核对代码、独立复现测试、确认 CI、报告结论。 ① 审原 issue(方向关):方向正确。对照原始 bug 的日志时间线(side request ② 回归审查(既有行为逐项):
③ 代码审查:镜像等价性逐项核对通过(wsLaneEnvelope ≡ x-bili-ws-lane 头检查;requestAgent ≡ sideAgent 同函数;demotion 支与 demotedSide 除 publicForkPrefix 外条件相同,该省略已证安全);detectAcpArtifacts 保持链尾,proxy 流量因 plugin-header 门先行失败而永不付重编码代价——与既有门同短路纪律。穷尽性:src/ 下 subagentNamespace 调用点恰好 3 处,全部被 ④ 测试有效性:不只是看 CI——我在本地做了 A/B 复现(定向单文件,非全量):当前 master(bb41405)+ PR 测试文件 = 5/7,两个新 case 均 ERR_ASSERTION 失败;PR 代码 + 同测试 = 7/7。断言打的是真实 session key / ref 计数 / request 计数(phase 1:side-first 后 raw key 零 refs 且无垃圾会话;phase 2:anchor-steal 复现,主 turn refs 落在裸 id 而非 ⑤ diff 整洁度:1 commit、3 文件(+168/-10),每行与本修复相关;无 version bump、无 config surface、无 kernel/、无 lockfile churn。分支包含当前 master(0 behind),mergeable,无需 rebase。 结构化七问:
行为变更披露(old → new):
残留(超范围,已记录):proxy 重启后若 classifyRisk/review 先到,冷锚点表问题仍在(src/session-id.ts 已记录的 worst case,#1956 接受);彻底解决需持久化锚定,属独立设计决定。用户已损坏的会话不可恢复(状态孤立在带后缀 key 下)——开新会话即恢复,此修复保证不再复发。 CI:head commit 5890a1e 20/20 全绿(ubuntu/windows × node 22/24 测试、hermetic registry e2e、全部 native 真实客户端 lane、kernel-guard、build-artifact 等)。 判定:可合(合并权限在你,我不代合)。本地 A/B 证据 + CI 全绿 + base 最新,建议直接合并。 |
[bot] 🏷 Review 结论(独立验证完成,含本地 teeth 复现) —— 本 PR 同时修复了今天新报的重复 issue #2160(@Dog 的 dsh desktop 日志,签名逐行吻合,已作重复关闭并指向本线程)。 ① 原 issue 审核(方向关):方向正确。报告的症状是「compress 永远失败」,修的是产生它的机制(side 请求偷走 persona 锚点 → host-stamped 管理调用路由进 ghost session),属 producer-site 修复而非症状掩盖。保留 #2024 stamp-wins(拒绝 witness)的判断也对:review 调用与主回合交错,放宽 witness 会让 witness ring 在主回合合法 compress 到达时经常持有 sibling persona,引入新的误路由风险——stamp 权威是对的。 ② 回归审查(逐项既有行为):
③ 代码审查:镜像保真度已对照 :2751-2754 / :2805 逐行核验; ④ 测试有效性:teeth 本地独立复现 —— ⑤ diff 整洁度:3 files +168/-10,每行都与本修复相关,无跑题/空白 churn。干净。我补了一个 docs-only 提交 结构化七问:
观察项(checklist,不另立项 —— 同一机制族,循证许可清单文化):修复后若某个被 fork 的 persona 将来携带 bili tools 且调用 compress,stamp 会把它路由进 MAIN 的 ref space(跨 persona 污染)。今日证据:多日全量日志中 sub-key 会话发起的管理调用为零;已知 aux 形状(title-gen、classifyRisk)均无 tools。不建投机防御,出现流量证据再议。 判定:可合,待人工合并。 远程 CI 在 5890a1e 上 20/20 全绿(test ubuntu/windows × node 22/24、e2e 含 real dsh headless profile lane、kernel-guard、version-guard、docs-sync、build-artifact),mergeable=true。合并入口:#2157 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.39-master.8b62bd7 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…passthrough (ranxianglei#2157 follow-up) ranxianglei#2157 keyed side requests verbatim (sideRequestLike) but kept the lane's !publicForkPrefix veto, so a full-history-replaying side call (dsh title-gen under a forked conversation: the host resends the ENTIRE current history plus the title instruction, so the inherited-prefix receipt always matches) ran the FULL pipeline on the fork child's MAIN session — junk turns into the snapshot, usage-baseline pollution (ranxianglei#1916 class), stats inflation. Pre-ranxianglei#2157 the same request forked onto an isolated |sub:<fp> junk session (ugly but clean). The receipt's first-request 409 discipline has already accepted the request, and side requests read none of the kernel state fork adoption maintains, so the veto had nothing to defend — drop it for intent-certain side identification. demotedSide keeps its own veto (leak-shape heuristic can false-positive a fork child's early mainline turns).
Closes #2156
Root cause
subagentNamespace(kernel wire layer) anchors an identity's RAW session key to the first non-empty system it sees — mutable in-memory process state, no delete API. Insrc/server.tsthe persona identity resolution ran before the #388 side-passthrough short-circuit (~line 2807), so a dsh side request (title-gen / classifyRisk-shaped, kernel-no-touch status) arriving first under the conversation id claimed the raw key with its utility system. Every subsequent real main turn then forked onto|sub:<fp(mainSystem)>; the host keeps stamping the bare id oncompress, whose session holds zero refs →compress FAILED … every ref is unknown to this sessionpermanently.Second facet of the same mechanism: even when a main turn anchored first, side requests rode junk
|sub:<fp(side)>sessions instead of sharing the main key, contradicting the #388 contract comment ("side requests share the main session key") and fragmenting guard state / polluting the sessions dir.Fix (mechanism-level, not symptom-level)
Side requests never touch kernel state, so they must neither read nor write the persona anchor. Before identity resolution,
handle()now computessideRequestLike— the exact mirror of the #388 lane condition below (isSideRequest shape OR all-bili-tools demotion shape with the starved-budget veto and ACP-artifact check) minuspublicForkPrefix, which needs the session resolved later; public-fork children arrive under a FRESH child id where first-seen anchoring returns the raw key anyway, so omitting it cannot move any key. WhensideRequestLike, all threesubagentNamespacesites (anthropic/openai dshPersona branches, responses instructions-fingerprint branch) fall through to the VERBATIM identity.detectAcpArtifacts(re-encodes history) stays last in the chain so proxy-mode traffic never pays for it — same short-circuit discipline as the existingdemotedSidegate.Supporting:
hasLeakedBiliToolsOnly()insrc/server/side-request.ts— read-only structural twin ofstripLeakedBiliTools(same verdict incl. the #546 starved-budget veto);stripLeakedBiliToolsnow delegates to it (behavior-identical).No kernel changes. No config surface changes. No wire/persistence format changes.
Behavior change disclosure (old → new)
|sub:<fp(side)>sessions. New = always the verbatim conversation key; the anchor is untouched by side traffic.Prefix cache unaffected: affinity token / client label already consume the raw identity value.
Tests
tests/dsh-persona-fingerprint.test.ts: two new e2e regression tests (openai lane + anthropic lane) reproducing the issue's exact sequence — side request FIRST, then main turns: assert refs land under the RAW key (bare-id compress works), main does NOT fork, no junk|sub:<fp(side)>session appears, and the review persona STILL forks correctly (并发同 session-id 流互相覆盖 lastInputTokens 基线:#388 侧请求分类漏掉「整段上下文单消息」形态,#1595 re-anchor 放大覆盖 #1916 mechanism undisturbed). Verified both FAIL on unpatched server.ts and pass with the fix (5/7 → 7/7).ACP_TEST_E2E=1): cannot run in this sandbox (suite needs the real Responses upstream behind repo secrets; local run fails at warmup identically on clean master — A/B verified environmental, not a regression)..github/workflows/ci-e2e.ymlauto-runs on this diff's hot files and will cover it.Residual (out of scope)
The proxy-RESTART race — a classifyRisk/review request arriving first after a restart would still see a cold anchor map — remains as documented at
src/session-id.ts:151-153(PR #1956 accepted that worst case). Fixing it needs persistent anchoring, a separate design decision.