Skip to content

fix: side requests must not claim the persona namespace anchor (#2156) - #2157

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-05_side-request-persona-anchor
Oct 5, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-05_side-request-persona-anchor

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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. In src/server.ts the 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 on compress, whose session holds zero refs → compress FAILED … every ref is unknown to this session permanently.

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 computes sideRequestLike — 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) minus publicForkPrefix, 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. When sideRequestLike, all three subagentNamespace sites (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 existing demotedSide gate.

Supporting: hasLeakedBiliToolsOnly() in src/server/side-request.ts — read-only structural twin of stripLeakedBiliTools (same verdict incl. the #546 starved-budget veto); stripLeakedBiliTools now delegates to it (behavior-identical).

No kernel changes. No config surface changes. No wire/persistence format changes.

Behavior change disclosure (old → new)

  1. dsh plugin-lane side requests: old = anchor-dependent — first-seen system could STEAL the raw key if the side request arrived first; after anchoring, side requests rode junk |sub:<fp(side)> sessions. New = always the verbatim conversation key; the anchor is untouched by side traffic.
  2. Proxy-mode Responses requests in side shape (max_tokens ≤ 200, no tools, no agent header): old = instructions-fingerprint keying (same race existed — such a request first would have poisoned the codex-lane anchor). New = verbatim keying. These ride the 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 passthrough and never touch kernel state, so fingerprinting them only ever poisoned the anchor.

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).
  • Existing suites green: dsh-persona-fingerprint 7/7, fix-1897-leaked-tools-side + side-request-isolation 33/33, responses-instructions-drift + subagent-namespace 13/13.
  • Pre-flight: typecheck clean, build OK.
  • codex e2e (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.yml auto-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.

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.
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-05_side-request-persona-anchor (ab65aa0)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2210-pr.2157.59f3c91

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-pr2157.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(#2157 → Closes #2156)的镜像 issue。当前状态:PR open、head 2026-10-05_side-request-persona-anchor @ 5890a1e4,mergeable;CI 中已完成的所有 lane(e2e、real-client native lanes、kernel-guard、version-guard、docs、build-artifact)全绿,全套 test (ubuntu/windows 22/24) 与 hermetic registry e2e 仍在跑。我先核对分支代码与描述一致性 + 等 CI 收尾,随后按结构化七问给出 review 结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

[PR] 核对结论 —— 本 PR 是我在 #2156 上的工作产物(07:12Z 开出)。按 [PR] 流程不重做:拉分支逐行核对代码、独立复现测试、确认 CI、报告结论。

① 审原 issue(方向关):方向正确。对照原始 bug 的日志时间线(side request 05:46:30.555 裸 id → 14ms 后 processTurn 落 |sub:d1bdbce…)+ 代码路径 + kernel 源码三重验证:createSubagentNamespaces(kernel/src/wire/responses.ts)把「首个非空 system」锚为 raw key——可变进程内状态、无删除 API;而 bili 的 persona 身份解析跑在 #388 side-passthrough 短路之前,使从不触碰 kernel 状态的 side request 也参与锚点写入。修在决策点(身份解析处),不是下游 mask:litmus test 通过——同一根因明天换一种 side-request 形态出现,仍会被同一个前置预判挡住。

② 回归审查(既有行为逐项):

③ 代码审查:镜像等价性逐项核对通过(wsLaneEnvelope ≡ x-bili-ws-lane 头检查;requestAgent ≡ sideAgent 同函数;demotion 支与 demotedSide 除 publicForkPrefix 外条件相同,该省略已证安全);detectAcpArtifacts 保持链尾,proxy 流量因 plugin-header 门先行失败而永不付重编码代价——与既有门同短路纪律。穷尽性:src/ 下 subagentNamespace 调用点恰好 3 处,全部被 !sideRequestLike 门控,无其他 caller。responses hunk 嵌套三元稍深,与文件既有风格一致,纯观感。

④ 测试有效性:不只是看 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 而非 |sub:<fp(main)>;phase 3:锚定后 side 不再铸垃圾会话;phase 4:#1916 fork 不受扰动),anthropic lane 覆盖用户实际命中的 wire(/anthropic/v1/messages)。不是恒真断言,bug 回归时抓得住。小残留观察:demotion 形态(全-bili-tools)× persona-anchor 组合无独立 case,但该支与 demotedSide 条件可证等价、共享原语已被既有 demotion-lane 测试钉住,不构成阻塞。

⑤ diff 整洁度:1 commit、3 文件(+168/-10),每行与本修复相关;无 version bump、无 config surface、无 kernel/、无 lockfile churn。分支包含当前 master(0 behind),mergeable,无需 rebase。

结构化七问:

  1. 是什么问题:dsh 对主 turn 与辅助请求复用同一 conversation id;side request 先到会抢走 persona 锚点,整个主会话被改名到 |sub:<fp>,宿主戳裸 id 的原生 compress 永久失败("every ref is unknown to this session")。
  2. 什么原因导致的:kernel 锚点语义「首见 system 占 raw key」(可变进程内存、无删除 API)+ bili 身份解析先于 side-passthrough 短路执行,让无状态 side request 写入锚点——先到者决定一切且不可恢复。第二切面:主 turn 先锚定后,side request 骑垃圾 |sub:<fp(side)> 会话,违背 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388「side requests share the main session key」契约。
  3. 怎么修复的:身份解析前新增 sideRequestLike 预判,完整镜像 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 lane 条件(budget≤200/无工具形态,或全-bili-tools demotion 形态,含 [bug] bili dsh 长会话中 max_output_tokens 被压到 ≤200,主请求被误判为 side request 并绕过压缩 #546 否决与 ACP-artifact 检查);side request 一律解析为 verbatim 原 key——既不读也不写锚点,与其「永不触碰 kernel 状态」地位一致。顺带抽出 hasLeakedBiliToolsOnly(只读孪生,行为不变)。
  4. 是否有回归问题:无。② 所列既有行为逐项「保持」,唯一有意变更已披露;本地 A/B 证明 5 个既有 case 修复前后同样绿。
  5. 是否破坏缓存:否。prefix-cache 的 affinity token / client label 本就消费 raw identity 值;side request 落到指纹化 key 本身就是缺陷,修复反而消除一处潜在的缓存分裂。
  6. 是否改了设计方向:无架构转向。只把一个决策(该请求是否会走 side passthrough)提前到身份解析之前,使身份解析与既有 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 契约对齐。
  7. 是否引入了新的配置:无。没有新 env / config / CLI 字段。

行为变更披露(old → new):

  • dsh plugin-lane side request 的会话 key:旧值 = side 先到时抢走 raw key(主会话被 fork),或锚定后骑垃圾 |sub:<fp(side)> 会话;新值 = 恒为 verbatim conversation key,永不触碰锚点。
  • proxy-mode Responses side 形态请求(max_tokens≤200、无工具):由 instructions-fingerprint keying 改为 verbatim——同一机制的同一修法,理由同上(这些请求从不触碰 kernel state)。

残留(超范围,已记录):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 最新,建议直接合并。

PR: #2157 · Closes #2156

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[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 逐行核验;stripLeakedBiliTools 内 cast 安全(guard 保证 parsed 为对象);hasLeakedBiliToolsOnly 放置保留 detectAcpArtifacts 的成本纪律(链尾)。逻辑/不变量/错误处理/安全面均无问题。不涉及 kernel/(纯 host 侧)。

④ 测试有效性:teeth 本地独立复现 —— git checkout master -- src/server.ts src/server/side-request.ts(保留 PR 的新测试)后恰好两个新测试失败(5 pass/2 fail),打补丁后全过;作者「5/7→7/7」声明属实。断言有牙(refs===0、stats.requests===0、main-not-forked refs>=12、review fork 存在性),此 bug 回归时抓得住。

⑤ diff 整洁度:3 files +168/-10,每行都与本修复相关,无跑题/空白 churn。干净。我补了一个 docs-only 提交 ab65aa0a:AGENTS.md KDD#9 原文「FIRST system seen … main turns never fork」在修后已过时,补上「SIDE REQUESTS never claim the anchor(#2156/#2160)」不变量一句(注释/文档措辞与代码事实不符类小修,按规则直接修)。CI 会在 ab65aa0 上重跑(docs-only)。

结构化七问:

  1. 是什么问题:dsh 标题 sidecar 先到偷走 persona 锚点,整个主会话 fork 进幽灵 sub-session,host-stamped 的 compress/decompress/acp_status 全部打到空壳上永远失败 → 上下文完全不压缩。
  2. 什么原因导致的:锚点规则「id 下第一个出现的 system 占 raw key」假设先到者是主回合,dsh desktop 的 sidecar 打穿了该假设(锚点反转);Codex Code Mode 压缩失败:MCP shim 忽略每次调用的 _meta.threadId,错误使用过期 env ID #2024 stamp-wins(正确行为)使管理调用无法纠偏。因果两层,修的是第一层。
  3. 怎么修复的:side 请求(isSideRequest 或 leaked-bili-tools 形状)不认领锚点、不 fork,按 raw key 原样通行;gate 置于身份解析之前,覆盖全部三个 subagentNamespace 位点(anthropic/openai dshPersona + responses instructions-fingerprint)。
  4. 是否有回归问题:无(逐项清单见上)。
  5. 是否破坏缓存:不涉及。
  6. 是否改了设计方向:不涉及 —— 恢复 db21309 的原设计意图;残留的 proxy-restart 冷锚竞态已在 PR body 文档化(需持久化锚定,超本 PR 范围,feat: dsh persona fingerprint — session id + system hash split for id-sharing hosts (#1916/#1307/#1314) #1956 接受的 worst case)。
  7. 是否引入新配置:不涉及。

观察项(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

@ranxianglei
ranxianglei merged commit 8b62bd7 into master Oct 5, 2026
21 checks passed
@ranxianglei ranxianglei mentioned this pull request Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.39-master.8b62bd7 (rolling master tag).

npm install -g billion-context@0.0.39-master.8b62bd7  # 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 added a commit that referenced this pull request Oct 5, 2026
fix: side requests under public-fork children ride the #388 passthrough (#2157 follow-up)
antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 6, 2026
…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).
@ranxianglei
ranxianglei deleted the 2026-10-05_side-request-persona-anchor branch October 15, 2026 05:32
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:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败

1 participant