Skip to content

[PR] fix: split header-less claude code subagents onto their own session lane (#4352) - #4409

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-23_claude-anthropic-subagent-split
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-23_claude-anthropic-subagent-split

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4352

What / why

Claude Code builds that stamp no agent-id headers (VS Code extension, entrypoint claude-vscode) send subagent model requests under the PARENT session id. Their short, unrelated histories ride the parent session and destroy its fold substrate: fold-reconcile sees covered ids missing, confirms epoch destruction, and the model's compress calls die as substrate-destruction with refs recorded DEAD forever. The parent conversation is intact — no compaction ever happened.

The #975 two-signal gate cannot see these subagents: in the live transcripts (issue comment) the parent and ALL 14 subagents send the SAME first system block verbatim ("You are Claude Code, Anthropic's official CLI for Claude, running within the Claude Agent SDK."), so the main-prefix negative check fails even when the agent-id headers ARE present. Separation must come from order+tag evidence, not prefix heuristics.

Fix

Route claude anthropic-wire traffic through the continuity-aware order resolver (#2944/#2241 — the same one dsh / codex / claude-over-Responses already use) whenever the #975 gate misses:

Behavior change (old → new)

  • Before: any claude request on the anthropic wire that missed the fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 two-signal gate keyed VERBATIM under the parent session id — including subagent rides. That is what destroyed the fold substrate.
  • After: those requests resolve through the order resolver. For a normal single-persona conversation the resolved id is IDENTICAL to before (raw id) — observable behavior unchanged. Only history-disjoint rides under a DIFFERENT system text move, onto their own |sub:<fp> lane.
  • Consequences: the system prompt changed (11170 → 3044) → drop → epoch → substrate-destruction chain stops firing during subagent runs; the model's compress on parent ranges stays anchorable; refs are no longer recorded DEAD. The ~40 [storage] unified shadow DIGEST DRIFT lines in the report (subagent messages written under the parent id into unified storage) are expected to disappear with the same cause — not reproducible hermetically, to be confirmed on the reporter's next subagent run.
  • claude sessions now also get an order-skeleton record (persisted, Compression fails in long sessions while new sessions work fine | 压缩失败.新会话反而没事 #3397 mechanism) — a small per-session storage addition, identical to every other resolver-routed lane today.

Config surface

NO new field. The existing subagentSplit (BILI_SUBAGENT_SPLIT) semantics are EXTENDED: false now also disables the header-less order-resolver fallback (previously it only disabled the #975 header-pair split). Default stays ON. Rationale for not inventing a second knob: the two paths are one mechanism family ("keep claude subagent traffic off the parent session"), one escape hatch is enough. Docs updated in CONFIGURATION.md + CONFIGURATION.zh-CN.md.

Both-modes reasoning

Session-keying only — no wire rewrite, no tool/nudge/summary-carrier change. Plugin mode (any x-bili-plugin host) is untouched: the new branch fires only when the winning conversation source IS the claude header, which plugin lanes never are (they stamp x-bili-plugin-conversation, first in the source precedence). Proxy-mode claude native traffic (the affected one) runs the standard server-side compression pipeline; the forked subagent lanes simply run it under their own session state.

Regression review (existing behaviors walked)

  1. fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 header-pair split (CLI builds) — untouched: first branch of the anthropic identity ternary, identical behavior; pinned by tests/claude-subagent-split.test.ts (green).
  2. Non-claude anthropic clients (generic x-acp-session etc.) — verbatim identity preserved; negative e2e row in the new suite (two disjoint conversations under one id accumulate on ONE session, no fork minted).
  3. dsh persona lane — separate ternary branch, unchanged; dsh-persona-fingerprint + dsh-persona-continuity green.
  4. Order-resolver corpus — the resolver itself is UNCHANGED, one call site added; issue2944-neutral-skeleton, issue3397-persona-restart-stability, issue2601-persona-fork-lineage, issue2817-crosswire-persona-fold all green.
  5. Lane-decisions registry discipline — lane-decisions-matrix + lane-decisions-b-class green; the new flag rides the EXISTING claude entry, no new name-literal comparison outside the registry.
  6. sideRequestLike passthrough (标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388/dsh 0.2.1 Alpha.2更新了检查适配情况 #2503) — exemption row in the new suite: side calls ride the raw key and stay uncounted.
  7. Wire fidelity — no payload rewrite anywhere in this diff (identity computation only).
  8. Prefix cache — parent outbound bytes are byte-identical; forked subagent lanes start their own cache lineage (intended — they were previously corrupting the parent's).

Tests

Targeted local runs (full-suite verdict = remote CI on the pushed head):

  • NEW tests/issue4352-claude-anthropic-subagent-split.test.ts: 8/8 — gate allowlist rows (positive+negative), resolver rows incl. the LIVE VS Code shared-first-block field shape captured in the issue comment, e2e through a real server (fork + parent object untouched + opt-out + side/empty-system exemptions).
  • Combined targeted suites (claude-subagent-split, dsh-persona-fingerprint, dsh-persona-continuity, issue2944-neutral-skeleton, issue3397-persona-restart-stability, lane-decisions-matrix, lane-decisions-b-class, issue2601-persona-fork-lineage, issue2817-crosswire-persona-fold): 121/121.
  • npm run typecheck clean.

No kernel/ changes. No config-schema or persistence-format change. Touches identity/session-binding logic → human review per §7.4.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-23_claude-anthropic-subagent-split (82e05b1)

Latest build — install this exact version

npm install -g billion-context@0.0.5309-pr.4409.550211f

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
82e05b1 billion-context@0.0.5309-pr.4409.550211f build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4409.tgz
npm install -g package

Install instructions are refreshed on each push.

…ane (#4352)

Claude Code builds that stamp no agent-id headers (VS Code extension) send
subagent model requests under the parent session id. Their short, unrelated
histories ride the parent session and destroy its fold substrate:
fold-reconcile sees covered ids missing, confirms epoch destruction, and the
model's compress calls die as substrate-destruction with refs recorded DEAD.

The #975 two-signal gate cannot see these subagents: VS Code builds share the
parent's first system block verbatim, so the main-prefix negative check fails
even when the agent-id headers are present.

Route claude anthropic-wire traffic (x-claude-code-session-id source, evidence
allowlist in the lane-decisions registry) through the continuity-aware order
resolver when the #975 gate misses: a continuing main conversation keeps the
raw id on order+content evidence; a history-disjoint ride forks onto its own
|sub:<fp> lane (own lock chain, own compression state); a byte-drifted system
on continuing history still keeps the raw id (#1106). Gated by the existing
subagentSplit knob (no new config surface); side calls and empty-system
requests stay verbatim.

Docs: CONFIGURATION.md/.zh-CN.md subagentSplit rows describe both paths.
Tests: tests/issue4352-claude-anthropic-subagent-split.test.ts — both gate
directions plus the live VS Code field shape captured in the issue comment.
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):issue [4352] 已由已合并 PR [4337] 修复。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

ranxianglei pushed a commit to Mako-L/billion-context that referenced this pull request Oct 28, 2026
…ane (ranxianglei#4352)

Claude Code builds that stamp no agent-id headers (VS Code extension) send
subagent model requests under the parent session id. Their short, unrelated
histories ride the parent session and destroy its fold substrate: fold-reconcile
sees covered ids missing, confirms epoch destruction, and the model's compress
calls die as substrate-destruction with refs recorded DEAD.

The ranxianglei#975 two-signal gate cannot see these subagents: VS Code builds share the
parent's first system block verbatim, so the main-prefix negative check fails
even when the agent-id headers are present.

Route claude anthropic-wire traffic (x-claude-code-session-id source, evidence
allowlist in the lane-decisions registry) through the continuity-aware order
resolver when the ranxianglei#975 gate misses: a continuing main conversation keeps the raw
id on order+content evidence; a history-disjoint ride forks onto its own |sub:<fp>
lane (own lock chain, own compression state); a byte-drifted system on continuing
history still keeps the raw id (ranxianglei#1106). Gated by the existing subagentSplit knob
(no new config surface); side calls and empty-system requests stay verbatim.

Re-applies the fix from unmerged PR ranxianglei#4409 (closed by a stale-ticket bot that
misattributed the closure to ranxianglei#4337, which does not touch this path) onto current
master. Closes ranxianglei#4769 (re-report of ranxianglei#4352).

Tests: tests/issue4352-claude-anthropic-subagent-split.test.ts — both gate
directions plus the live VS Code field shape captured in the issue comment.
Docs: CONFIGURATION.md/.zh-CN.md subagentSplit rows describe both paths.
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.

Subagent requests share the parent session id and trip fold-reconcile

1 participant