Skip to content

[PR] fix: recognize the claude code title sidecar so it never claims the raw session id (#5136) - #5137

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-29_claude-title-sidecar
Oct 31, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-29_claude-title-sidecar

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes the v0.1.209 regression introduced by #4774: Claude Code CLI fires its session-title call ~1ms ahead of the first main turn under the SAME x-claude-code-session-id. Since #4774 routes that header-less anthropic traffic through the persona order resolver, the title call — own system prompt, single <session>-wrapped user blob, no tools, output budget past the ≤200 heuristic — claimed the raw session id as kernel anchor on the virgin id; the real conversation then arrived tagChanged and history-disjoint and forked onto |sub:<fp> for the session lifetime. This is the #2156 violation form: side requests must never claim the anchor.

What changed

Negative control: with only the handle.ts wiring reverted to pre-fix, the two race tests fail with the reported shape (title counted on the raw id, main conversation forked); with the fix, all green.

Behavior change (old → new)

Config surface

None. No new config field, env var, or CLI flag.

Relations

Closes #5135

八问

  1. 是什么问题:0.1.209 起 Claude Code CLI 的会话标题请求(与首个主回合共用同一 x-claude-code-session-id、早到约 1ms)把原始会话 id 认领成了压缩锚点,主对话整会话被挤到 |sub: 旁路车道。
  2. 什么原因导致的:[PR] fix: split header-less claude code subagents onto their own session lane (#4352) #4774 让无插件 header 的 CC anthropic 流量走顺序解析器;标题请求自带 system、单条 包裹消息、无工具、输出预算超 ≤200 启发式——在 virgin id 上 first-sight 即认领原始 id;主回合随后 system 不同且历史不相交、无可续证据 → fork 永久化(违反 [bug] dsh:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败 #2156「侧车不得认领锚点」)。
  3. 影响范围与严重程度:所有走 bili 代理模式 + CC CLI 的新会话(报告者 3 台机器复现)。主对话仍可用但落在错误车道——按 id 过滤的 /__bili/sessions 与日志行都命中近空标题车道,主车道标题错乱;p2(能用但明显错位,有绕行)。
  4. 怎么修复的:新增形状谓词(无工具 + 恰一条以 开头的 user 消息),在「会话源 = x-claude-code-session-id」证据门控下同时接入两个车道闸:sideRequestLike(逐字按 id,不认领锚点)+ sideIntent(标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 直通,kernel 状态零触碰)。先例 dsh 0.2.1 Alpha.2更新了检查适配情况 #2503/[Bug][dsh] 0.1.204: auto-review side request collides with the main session → false native-compaction rebase → aux usage skips #453 clamp → permanent upstream 400 #4438。
  5. 是否回归问题:无。审过既有行为:Subagent requests share the parent session id and trip fold-reconcile #4352 subagent fork 路径不变(issue4352 套件 11/11 绿)、dsh 标题/review 侧车不变(side-lane-invariants (A)–(L) 全绿)、非 CC 客户端同形状行为不变(负例钉住)、带工具/无包裹/多消息形状仍走全管道(负例钉住)。合并 master(Running the test suite locally writes test sessions into the production sessions directory. | 本地跑测试套件会把测试会话写进生产 sessions 目录 #5107 测试基建)后定向复跑 27/27 + typecheck 绿。
  6. 是否破坏缓存:不涉及——直通路径不触碰任何缓存/快照/增量游标;主对话出站前缀字节不变。
  7. 是否改设计方向:不改。只是把 [bug] dsh:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败 #2156 契约(侧车不认领锚点)补到一个新发现的侧车形状上,机制全部复用现有车道引擎(resolveSideLane/passthrough)。
  8. 是否引入新配置:无。

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-29_claude-title-sidecar (3153398)

Latest build — install this exact version

npm install -g billion-context@0.0.7426-pr.5137.8b19ae9

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
3153398 billion-context@0.0.7426-pr.5137.8b19ae9 build
0675eae billion-context@0.0.7370-pr.5137.e2b37fa build
00cdce2 billion-context@0.0.7301-pr.5137.19df353 build
fb94a00 billion-context@0.0.7019-pr.5137.f681df6 build
49878b9 billion-context@0.0.6782-pr.5137.fe79826 build
9c7f54f billion-context@0.0.6772-pr.5137.4db186e build
f690e09 billion-context@0.0.6768-pr.5137.7769bdc build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: recognize the claude code title sidecar so it never claims the raw session id (#5136) [PR] fix: recognize the claude code title sidecar so it never claims the raw session id (#5136) Oct 29, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复。本 PR 即 #5136 的修复 PR(Closes #5136);在途 PR 中无其他触碰同一机制(CC title sidecar 认领原始 id 锚点)的条目。相关但分开处理:#4840/#4843(Claude Desktop 通知分类器,同机制家族但客户端与症状不同——usage 污染、无 fork,且其 system 文本非 <session> 包裹,本修复不覆盖)、#4974/#5005(side request 钉住会话 meter,机制不同)。#4774 是回归来源(已并入 0.1.209),#4352 是其原始 subagent 分叉报告。

标签:bug / claude-code / scope/wiring / p2 —— 缺陷类;主会话压缩状态本身没丢(|sub 车道折叠正常),问题是按 id 查会话命中近空标题车道、主车道标题错乱;能用但有明显错位且有绕行,不升 p1。

CI 现状(head f690e09):静态门禁全绿(static-gates/kernel-guard/lane-guard/unused-exports/config-surface-guard/lock-sync/docs-* 等);test 分片 1 红(windows-latest, node 22, shard 1)+ 10 片运行中。master 当前自身为红(#4599:hermetic data-root 集群 #5107/#5115/#5120,ci-fixes@cf99d93 已 49/49 全绿,载体 PR #5133 等人工合并)。我会核对那一片红的签名是否为继承性失败,若是则把 ci-fixes 并入本分支重跑。

代码审查进行中,结论随后补。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Review 结论:可合(需人工合并——触碰身份/会话绑定逻辑,§7.4 human-only)。diff 已独立通读(4 文件,+383/-5),关键路径逐段核过,未照抄 issue 侧描述。

我做的验证动作:

八问:

  1. 是什么问题:CC CLI(proxy 模式)在首个主回合前 ~1ms 发出的标题生成 sidecar(同 x-claude-code-session-id)被当主请求处理,在 virgin id 上抢走原始 id 的 kernel 锚点,真实主会话因此永久分叉到 |sub: 车道——按 id 查会话命中近空标题车道、主车道标题错乱。
  2. 什么原因导致的:[PR] fix: split header-less claude code subagents onto their own session lane (#4352) #4774(v0.1.209)把无 header 的 CC 流量路由进 persona order resolver,而既有 side-request 识别只靠 max_tokens≤200 启发式;CC 标题调用的预算超过 200,逃过全部识别,进入 resolver 首见分支抢锚(KDD release v0.1.2 #9/[bug] dsh:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败 #2156 的违规形式:side request 不得认领锚点)。
  3. 影响范围与严重程度:CC 终端 CLI proxy 模式所有新会话,跨机必现;主会话压缩状态本身没丢(|sub 车道折叠正常),但按 id 查询命中错车道 + 标题错乱——能用但有明显错位,p2。
  4. 怎么修复的:形状识别 + 客户端证据双门(isClaudeCodeTitleRequest:无 tools + 恰好一条 user 条目 + 文本以 <session> 包裹开头,wire-generic;∧ claudeAnthropicPersonaOrderApplies 会话源证据 ∧ 非 main agent)。识别后走既有两条 side 车道:sideRequestLike 使其按字面 id 解析(不进 resolver、不认领锚点)、sideIntent 进 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 passthrough(kernel 状态逐字节不动)。机制同先例 dsh 0.2.1 Alpha.2更新了检查适配情况 #2503/[Bug][dsh] 0.1.204: auto-review side request collides with the main session → false native-compaction rebase → aux usage skips #453 clamp → permanent upstream 400 #4438;order resolver 路径本身零改动。
  5. 是否有回归问题:逐条清点触碰路径的既有行为——sideRequestLike 其余 OR 项不变;resolveSideLane 纯函数与其真值表套件重跑绿;anthropic keying 三元链零 diff;dsh 两个谓词不变;dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170 泄漏 canary 不变;Subagent requests share the parent session id and trip fold-reconcile #4352 subagent 分叉行为保留(套件绿)。无语义漂移、无吞错、无阈值/时序漂移。一个诚实边界:若某 CC 主回合恰好无 tools 且首条消息以 <session> 开头,会被误判为标题 sidecar 走 passthrough(该回合不压缩)——CC CLI 主回合恒带 tools 面,实际不可达,与形状谓词先例的风险档一致。
  6. 是否破坏缓存:不涉及——passthrough 原样转发客户端字节流,不碰前缀缓存键、重试或增量游标。
  7. 是否改了设计方向:否——给既有 side-request 车道机制增加一个被识别人群,无架构转向。
  8. 是否引入新配置:无。

行为变更披露(独立核对,与 PR 正文一致):旧(v0.1.209)标题调用在 raw id 下走完整管道——计入请求统计、认领锚点、导致主会话永久分叉;新:识别为 side request → 字面 id 解析 + passthrough,kernel 状态不变、不计入会话统计。受影响人群仅限「CC 会话源证据 ∧ 精确一次性标题形状」的字节,其余流量逐字节不变(负向行已钉死)。

测试有效性:断言有牙——预修形态 raw key requests=1/会话数=2,修后 0/1,负向对照(仅回退 handle.ts 接线即红)作者已验证;真值表正反双向(#3617 纪律);live race 测试走真实 server + mock SSE、hermetic 状态 + randomUUID + port 0,deterministic。小缺口(不拦):responses/google wire 的标题形状只有单测级钉住、无 live e2e(CC CLI 只走 anthropic wire,可接受)。

CI:静态门禁全绿;test 分片红为继承性(master 自身红,#5133 载体等待人工合并期间),已并 ci-fixes 重跑,等新 head 全绿即可合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

Off-by-one issue reference found while fixing the sibling PR #5136 (its reporter @kuviki flagged the same class of mistake there):

This PR's body says Closes #5136, but #5136 is PR #5136 itself (GitHub shares one number space for issues and PRs) — closing keywords do not act on PRs, so this closes nothing. The Claude Code title-sidecar regression this PR fixes is reported in issue #5135 ("Claude Code CLI main conversation forks onto <id>|sub:<fp>; the session-title call claims the raw key").

Suggested correction: Closes #5135 in the PR body (and the title's (#5136) if the sync pipeline allows). Same root cause as #5136's mis-citation: the working session cited the mirror-side number instead of the upstream GitHub number.

Not editing this PR myself — that lane owns it; flagging so the merge doesn't leave #5135 unclosed.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

已核实并修掉。先查证(只读 API):上游 #5135 = 本 PR 修的原 bug([Bug] 0.1.209: Claude Code CLI main conversation forks onto <id>|sub:<fp>…, open, MohammadErfan-Jabbari);上游 #5136 = 另一个无关 PR(post-fold nudge sizing)。所以原 body 的 Closes #5136 确实关不到任何东西——closing keyword 不作用于 PR——按原样合并会让原 issue 悬空。感谢 @kuviki 一线在 #5136 里点出同类错误。

已做两处修正:

  1. PR body(API PATCH,HTTP 200,回读验证):Closes #5136 → Closes #5135;body 内测试文件名引用同步改为 tests/issue5135-claude-title-sidecar.test.ts。全文再无 [PR] fix(#5135): post-fold nudge sizing must ride the credited baseline, not the stale pre-fold usage #5136 残留。
  2. 分支上一个标注清晰的独立 commit(49878b9d3):把代码里所有「原 issue」引用从镜像编号改到上游编号——src/server/handle.ts(3 处注释 + sideLabel 日志串)、src/server/side-request.ts(1 处注释)、两个测试文件的测试名与头注、回归测试文件改名 tests/issue5136-* → tests/issue5135-claude-title-sidecar.test.ts。纯引用修正、零逻辑改动;受影响套件本地重跑 19/19 绿。这样合并后代码里的引用 grep 得到真实 issue,不会指向无关 PR。

刻意不动的三处:

  • PR 标题:标题归属系统管道,agent 禁改——标题里的 (#5136) 留给管道/owner 处理;
  • 原 fix commit 的 subject line (#5136):为装饰性引用改写历史不值得,auto-close 只认 PR body;
  • 测试 fixture id(cc5136*):不透明数据,不是 issue 引用。

新 head 49878b9d3 会触发新一轮 CI;全绿即可合(合并权归 owner)。本轮修正不改变上一轮审核结论(可合,human-only gate)。顺带更正我首条回复里的措辞:「#5136」是镜像侧编号,上游原 issue 是 #5136 对应镜像…准确说:上游 #5135 ↔ 镜像 #5136,本 PR 上游 #5137 ↔ 镜像 #5138。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

上一条最后一句措辞写乱了,更正如下(以这句为准):原 bug 上游编号 = #5135,其在镜像侧的编号 = #5136;本 PR 上游编号 = #5137,镜像侧 = #5138。PR body 现引用的是上游编号 Closes #5135,合并后将正确关闭原 issue。其余内容不变。

ci-check added 2 commits October 31, 2026 13:37
…aw session id (#5136)

Claude Code CLI fires its session-title call ~1ms ahead of the first main
turn under the SAME x-claude-code-session-id. Since #4774 (v0.1.209) that
header-less traffic rides the persona order resolver, and the title call —
own system prompt, single <session>-wrapped user blob, no tools, budget
past the <=200 heuristic — claimed the raw id as kernel anchor on the
virgin id; the main turn then arrived tagChanged and history-disjoint and
forked onto a |sub:<fp> lane for the session lifetime (#2156 form: side
requests must never claim the anchor).

New shape predicate isClaudeCodeTitleRequest in src/server/side-request.ts
(no-tools veto + exactly one user entry whose text starts with the
<session> wrapper), wired into both lane gates in handle.ts behind the
claude-code conversation-source evidence gate: sideRequestLike keeps it off
the resolver (verbatim iding) and sideIntent routes it through the #388
passthrough (kernel state untouched). Precedents: #2503 dsh title, #4438
dsh auto-review.

Tests: tests/issue5136-claude-title-sidecar.test.ts (predicate truth table
+ live race in both arrival orders + client-evidence negative; verified to
fail against the pre-fix wiring) and row (M) in tests/side-lane-invariants.test.ts
(#2170 lane-guard pairing).
…r was #5136)

The bug report's upstream GitHub number is #5135; the working session had
cited the mirror-side number (#5136, which upstream is an unrelated PR) in
source comments, test names and the regression-test file name. Renumber all
citations so post-merge references resolve to the real issue. Fixture ids
(cc5136*) are opaque data and stay untouched.
@ranxianglei
ranxianglei force-pushed the 2026-10-29_claude-title-sidecar branch from 0675eae to 3153398 Compare October 31, 2026 05:37
@ranxianglei
ranxianglei merged commit e2d7079 into master Oct 31, 2026
35 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 0.1.209: Claude Code CLI main conversation forks onto <id>|sub:<fp>; the session-title call claims the raw key (regression from #4774)

1 participant