Skip to content

[PR] fix: unknown dsh one-shot sidecars steal the raw-key anchor and kill compression (context-explosion root cause) - #5687

Merged
ranxianglei merged 1 commit into
masterfrom
2026-11-05_single-shot-sidecar
Nov 5, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-11-05_single-shot-sidecar

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #5656
Fixes #5582
References #5630 (research), #5671 (terminal deaths fed by this)

什么东西坏了(一句话)

dsh 每出一个新的「一次性」辅助功能(#5656 的提示词增强:把用户输入重写一遍再发主请求),这个辅助请求会抢先把主会话的 key 占为己有;真正的对话从此被赶到 会话id|sub:指纹 的幽灵分身上,压缩管理调用(compress / acp_status)永远查不到摘要 ref,3 次失败后熔断,压缩从此彻底失效,上下文无限增长直到 413 爆掉——这就是 session 漂移系列(#5656/#5584/#5671/#5630)里上下文爆炸的根因。

根因链(代码级)

  1. dsh 的一次性辅助请求(title 之外的新功能,如提示词增强)与主请求共用同一个 conversation id,带自己的 system、无 tools、单条 user 消息、host 级输出预算。
  2. 现有识别全是逐功能钉死的前缀/预算 pin(src/server/side-request.ts:title dsh 0.2.1 Alpha.2更新了检查适配情况 #2503、auto-review [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、预算≤200 [bug] bili dsh 长会话中 max_output_tokens 被压到 ≤200,主请求被误判为 side request 并绕过压缩 #546、server-tool [bug] Claude Code 的 WebSearch 子请求被当成主对话:nudge 基准被搜索的 usage 重锚,导致提前折叠;每次搜索还被注入 bili 工具 #2500、claude-code title [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) #5135)——新 sidecar 一个都匹配不上,sideRequestLike=false,走进主管道。
  3. resolveSessionOrder(src/session-resolve.ts)的 virgin-id 分支里 mainShaped(≥3 格且含 assistant)不成立、但带非空 tag 的 shallow 请求认领 raw key(codex turn-1 例外同款语义)。辅助请求抢在首个主回合之前到达(用户在会话开始点了「增强」),锚被 sidecar 的指纹占走。
  4. 首个主回合到达,system 不同、内容与 sidecar 的 1 条幽灵不构成链延续 → fork 到 <id>|sub:<fp>,永久。
  5. dsh 宿主盖 id 的管理调用(compress/acp_status)解析裸 id → 看到 1 条消息的幽灵 → 永远匹配不到 ref → 连续失败 → 熔断 → 压缩死透 → 上下文只增不减 → Repeated compression just won't squeeze it down any further — the model itself says there's no more space. | 重复压缩压不下去 模型自己说没空间了 #5671 的 7.3× 窗口 413 终局。

已在 #5656 报告者的 DB 里逐字节复现(base 行 1 条消息 / sub 行 249 条消息)。本 PR 附带 e2e 复现测试(fix 前 fail / fix 后 pass,openai + anthropic 两条 wire)。

修法(结构性,不追着功能打补丁)

一个一次性辅助调用永远伪装不出来的两件事(#546「非空 tools = 主回合」、#4438 回放否决):

新增 isDshSingleShotSidecar(protocol, parsed)(src/server/side-request.ts),system 文本刻意不钉——下一个新 sidecar 不许重开这个洞。挂进 sideRequestLike 和 sideIntent(src/server/handle.ts,dsh 车道门控 + sideAgent!=="main",粘性绑定腿镜像 #4438),sidecar 走 #388 直通车道:内核零接触、零状态、不认领锚。原有逐功能 pin 保留作双保险。

诚实边界(已钉进测试):无工具主对话的第 1 回合恰好也是单发形状,会被降级直通一轮(那一轮无任何可压缩内容,无害);第 2 回合起回放历史即回主pipelines认领 raw key,对话无损(tests/issue5656 负例钉死)。响应线上带 reasoning/function_call 等 typed item 的真模型回放一律否决。

两模式推演(§6)

纯插件车道变更:所有新分支都以 pluginAgentHeader==="dsh" 为门。代理模式(无 x-bili-plugin 头)永远不进新分支,逐字节不变。

config surface

无新增/改名/改义配置。零 env、零 flag、零文档面变化。

测试

  • 新 tests/issue5656-single-shot-sidecar.test.ts:unit 全正/负表(三条 wire 的单发形状×主回合/辅助回放/仅 bili 工具/双 user/typed item/空 system 等)+ e2e 事故复现(openai + anthropic 两条线:sidecar 先到→不再认领锚,主对话留在 raw key、≥12 refs、零 fork;后续第二种未知 sidecar 依旧无状态)+ 负例(无工具多消息主回合走完整管道)。
  • tests/side-lane-invariants.test.ts 更新 4 处旧 pin(语义冲突即本 PR 修复对象):(D)/(E)/(E2) 原「单消息 persona 仍 fork」的期望就是 DSH: If the first request of a session originates from a bypass call, compression for the entire session is permanently | DSH: If the first request of a session originates from a bypass call, compress for the entire session is permanently inv | DSH:会话首个… #5656 的 bug 形状,fork 腿改为带自有往返历史的 persona(多消息、链不相交——设计 fork 车道仍被钉住,canary/锚契约不变);(G) 导入白名单 + 注释补 isDshSingleShotSidecar。另给测试主回合补上 tools 面(真实 dsh 主流量形状)。
  • 全量邻近套件 91/91 绿(dsh-persona-fingerprint、issue4438、dsh-title-*、issue5135、side-lane-truth-table、side-request-isolation、fix-1897、websearch-side-request、side-lane-invariants、新文件);npm run typecheck + npm run build 干净。全量回归以远端 CI test lanes 为准。

自动合并判定(§7.4)

不满足自动合并条件(触碰 lane 决策语义,等价 wire 消息形状判断),按需人审。纯 fix:,单模块,无 kernel/、无 update.ts、无持久化格式、无配置面。

…m stealing the raw-key anchor (#5656/#5584)

Every NEW one-shot dsh sidecar (prompt-enhance in #5656) arrives under the
main conversation id with its own system prompt, no tools, one user blob —
and misses every pinned sidecar prefix. Arriving before the first main turn
it CLAIMS the raw-key anchor; the real conversation is then exiled onto
<id>|sub:<fp> for the session lifetime: the host-stamped management calls
(compress / acp_status) resolve the bare id, see the 1-message ghost, never
match a ref, trip the circuit breaker — compression is permanently dead and
the context grows unbounded (the session-drift explosion family; 11 of 13
sessions on the #5656 reporter's machine, feeding #5671's terminal 7.3×
window deaths).

isDshSingleShotSidecar closes the hole structurally: no action surface
(tools absent/empty — dsh's own request builder emits no tools key only
when the resolved tool set is empty) + single-shot body (exactly one
non-system message with content, no assistant/tool turn anywhere), any
system text. Gated on the dsh lane; joins sideRequestLike and sideIntent
so the sidecar rides the #388 verbatim passthrough (kernel no-touch).
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-05_single-shot-sidecar (01fcc5d)

Latest build — install this exact version

npm install -g billion-context@0.0.8162-pr.5687.9329fc8

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
01fcc5d billion-context@0.0.8162-pr.5687.9329fc8 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: unknown dsh one-shot sidecars steal the raw-key anchor and kill compression (context-explosion root cause) [PR] fix: unknown dsh one-shot sidecars steal the raw-key anchor and kill compression (context-explosion root cause) Nov 4, 2026
@ranxianglei ranxianglei added bug Something isn't working dsh p1 scope/wiring labels Nov 4, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。本 PR(#5687)是「生产者侧」修复(sidecar 不再认领锚点),与在途 PR #5590(消费侧证据路由,修 mirror#5584/GH#5582)同症状族、不同机制、互补且无合入顺序依赖——两个各自闭环,都该合。#5656 无其他并行修复 PR(GH 检索仅本 PR 引用它)。相邻家族:#5135(claude-code title,已修)、#3149(dsh title anthropic wire,已修)、#4438(auto-review,已修)均为逐功能 pin,正是本 PR 要终结的打地鼠模式;#3442/#4686/#5456 为同族其他面,机制不同。

标签: bug / dsh / scope/wiring / p1(核心压缩能力对整类 dsh 会话永久停摆 + 上下文无界增长,按 p1 口径)。

审核结论:可合(CI test lanes 转绿后),附一条需作者确认的行为变更精化

方向关(①):根因链我按代码独立核过——识别门全是逐功能钉死(title #2503/#3149、auto-review #4438、预算≤200 #546、server-tool #2500、cc-title #5135),未知单发 sidecar 一个都匹配不上,落进主管道后由 first-seen-instructions 锚定语义(resolveSessionOrder virgin-id 分支)把 raw key 让给 sidecar,主对话随后因 system 不同 + 链不相交永久 fork 进 |sub:<fp>。报告者 DB 证据(base 行 1 条 / sub 行 249 条、11/13 会话首请求为提示词增强)与该机制逐字节吻合。修在生产侧决策点(形状判定 → 永不认领锚点 + 走 #388 直通),不是症状层拦截;system 文本刻意不钉,下一个新 sidecar 无法重开这个洞——结构性关闭成立。

回归清点(②),逐项过 diff 触碰路径的既有行为:

发现一(已顺手修):PR 正文 Fixes #5584 写的是 e-work 镜像号——GitHub 上的 #5584 是一个无关的 Codex launcher marketplace .tmp 符号链接 bug(open),合并会被误自动关闭。已直接 PATCH 正文改为 Fixes #5582(即 mirror#5584 的上游号,2026-11-04T17:00Z)。

发现二(需作者/owner 确认,唯一实质保留项):PR 正文「诚实边界」称无工具主对话第 1 回合被降级直通一轮「无任何可压缩内容,无害」——这只对窗口内载荷成立。超窗口载荷(estimate ≥ 窗口×1.15 且窗口已知)的行为变化是:旧 = 全管道 + preflight 有救援尝试;新 = sideRequestGuard 本地确定性 413(side_request_payload_too_large, retryable:false)。触发面窄(dsh 空工具集 profile + 首条消息独大;小窗口模型更易触到),但方向是可用性损失,且这正是 #5590 线程当年否决「放宽识别面」候选的理由。推荐:在调用点加一个 fits-window 否决(超窗口的单发形状回退主管道,旧行为精确恢复,对锚点修复零代价,几行改动);若 owner 倾向保持门的纯粹性,至少把 PR 正文的「无害」表述修正为上述精确边界。我未擅自动语义,留给作者定夺。

代码关(③):谓词完全遵循家族风格(self-contained + 溯源注释 + systemCarrierTexts 全 wire carrier + 分 wire entries + typed-item 否决镜像 #4438);两道门分工正确(sideRequestLike=锚保护/verbatim 解析,#2156 契约;sideIntent=车道路由,sticky 腿覆盖未盖戳扩展客户端);resolveSideLane 补了 sideLabel。无 as any、无 console.error、无死代码;遍历循环与 isDshAutoReviewRequest 重复一次(2 处,抽公共可选,家族惯例是谓词自包含,不算缺陷)。

测试关(④):双向断言齐(#3617)——正表 4 wire×形状变体、负表(tools/assistant 回放/双 user/typed item/无 system/空白 system/空 content/null)、e2e 事故复现(openai+anthropic 两条线,phase 顺序钉死「sidecar 先到→不认领→主对话留 raw key≥12 refs→零 fork→后续第二种未知 sidecar 依旧无状态」)、负例 e2e 诚实钉住接受的残留(refs=0/requests=0)。测试有牙:fix 前必红(fork 出现/ref 缺失)。本地定向实测:12 个邻近套件 212/212 全绿(issue5656 新文件、side-lane-invariants/truth-table、dsh-persona-fingerprint、dsh-title×2、issue4438、issue5135、side-request-isolation、fix-1897、websearch-side-request、lane-decisions-matrix);git merge-tree 对当前 master(c9ba485)干净无冲突;CI static-gates 双 OS 绿,test lanes 在跑(以远端为准)。

八问

  1. 是什么问题:dsh 每出一个新的一站式辅助功能(本次是提示词增强),它的请求抢在主对话之前占掉会话的 raw-key 锚点,真对话被赶进幽灵分身,压缩管理调用永远查不到 ref,压缩永久失效、上下文无限增长直到 413。
  2. 什么原因导致的:识别靠逐功能钉死的系统文本前缀/预算,新 sidecar 全漏;漏网请求进主管道后按「首次见到的 instructions 锚定」规则认领了 raw key,主对话因 system 不同+链不相交被永久 fork。
  3. 影响范围与严重程度:p1。凡「会话首个模型请求来自未被识别 sidecar」的 dsh 会话全部中招(报告者机器 11/13 会话,下游喂了 Repeated compression just won't squeeze it down any further — the model itself says there's no more space. | 重复压缩压不下去 模型自己说没空间了 #5671 的终局死亡);其他客户端/车道不受影响。
  4. 怎么修复的:结构性形状门 isDshSingleShotSidecar(无动作面 + 单发体 + 自有非空 system,文本刻意不钉)挂进锚保护与车道路由两道门,dsh 车道门控,sidecar 走 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 无状态直通。
  5. 是否有回归问题:既有行为逐项清点如上,全部保持或有意改进;一处有意变更(无工具主回合第 1 轮走直通一轮)+ 一处需精化的披露(超窗口载荷从「preflight 尝试救援」变「本地 413」,见发现二)。
  6. 是否破坏缓存:否——side 车道逐字转发,plugin 模式零注入,主回合字节与 fold 状态、账本键均不变。
  7. 是否改了设计方向:否——沿用 标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388/[bug] dsh:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败 #2156/[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 的证据许可清单纪律,同架构扩展。
  8. 是否引入了新的配置:无——零 env、零 flag、零文档面。

收工判定:可合——待 CI test lanes 转绿 + 发现二由作者二选一处理(推荐加 fits-window 否决)。另注:本 PR 只防新增分裂,存量已坏的幽灵行不修,那部分由互补的 PR #5590(消费侧路由)在升级重启后接管,两者应先后都合入。

@ranxianglei
ranxianglei merged commit 8de4c37 into master Nov 5, 2026
81 of 136 checks passed
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1032-master.8de4c37 (rolling master tag).

npm install -g billion-context@0.0.1032-master.8de4c37  # 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 pushed a commit that referenced this pull request Nov 5, 2026
…ual (#4599)

01fcc5d (#5656/#5584, merged via #5687) diverts tool-less dsh single-shot
requests onto the verbatim side lane (kernel no-touch); the residual for main
turn 1 is documented in the commit's own comment. Five pre-existing pins
assumed turn 1 rides the full pipeline and went born-red at merge (master red
since; every PR head inherits it).

Test-only realignment codifying the documented behavior:
- issue2419/2446/2447/2481 guard-stamp subtests: two turns; the BLOCKED ref
  is witnessed on the first FULL-PIPELINE turn (turn 2). No fold can happen
  before turn 2 (nothing compressible, no action surface), so protection
  against every possible fold is unchanged.
- issue2817: stats.requests off by one (turn 1 uncounted); the persona-fold
  teeth are intact, assertions shifted -1.
- issue5403 A/B golden: turn 0 rides the side lane in BOTH phases (the gate
  ignores the rollout env), so rb[0] is unstamped by design; stamps resume at
  turn 1. Byte equality holds at i=0 (both phases forward verbatim).

No src/, kernel/, config, or version changes. Locally green: all six files +
side-lane-invariants + issue5656-single-shot-sidecar + dsh-persona-fingerprint.
ranxianglei added a commit that referenced this pull request Nov 13, 2026
…ed residual (#5687 follow-up)

The batch's #5709 (PR by Louie0806) narrowed the accepted residual ride of a
tool-less turn 1 onto the verbatim side lane: it now ALSO requires the small
pinned one-shot output budget (utility sidecars pin 4096; agent main turns
omit the field). The fixture's turn 1 omitted max_tokens, so it now correctly
rides the MAIN lane and stats.requests counts from turn 1 — 9 instead of 8.

Turn 1 now carries max_tokens: 4096 so the fixture keeps exercising the
residual path the count pins; the cross-wire persona/fold assertions are
untouched. CI: issue2817-crosswire-persona-fold '9 !== 8' on batch4.
ranxianglei pushed a commit to Louie0806/billion-context that referenced this pull request Nov 14, 2026
… a dsh sidecar

The generic single-shot gate added in ranxianglei#5687 matches "no tools + one user
message + any system text", and both of its call sites opened on
`agent !== "main"`. dsh's native client never stamps `x-bili-plugin-agent`,
so that header reads `undefined`, and `undefined !== "main"` is always
true: the FIRST unstyled main turn of a conversation matched the sidecar
shape and rode the ranxianglei#388 verbatim side lane. The kernel never saw it, so the
durable-state carriers (skills, workspace instructions, MCP catalog,
runtime context) never received their BLOCKED refs (ranxianglei#2419/ranxianglei#2446/ranxianglei#2447/ranxianglei#2481),
and the wire-byte contracts of ranxianglei#2817/ranxianglei#5418 reset.

A genuine utility sidecar is distinguishable from that turn in two ways, and
this patch requires both:

- it pins a TINY fixed output budget (prompt-enhance sends 4096), whereas a
  main main turn either omits the field (openai wire) or sizes it from the
  conversation (ranxianglei#5656's own residual turn sends 64000) -- hasSingleShotBudget;
- it never carries a dsh durable-state marker -- carriesDurableState, the
  same marker table fold-reconcile.ts already screens with.

The ranxianglei#5656 e2e residual that pinned "tool-less turn 1 rides the side lane" is
revoked and re-pinned to the corrected contract; the side-lane boundary test
allowlists the new predicate like every other pure shape predicate.

Tests: issue2419/2446/2447/2481 (4/0 each), issue2817 (1/0), issue5418
watermark (1/0), issue5656 (5/0), side-lane-invariants (15/0), issue5658
(2/0). Negative control: reverting only the two source files re-reds 2446
(3/1), 2817 (0/1), 5418 (0/1).

(cherry picked from commit 427778b)
ranxianglei added a commit that referenced this pull request Nov 14, 2026
…mark fastpath (#5403/#5418 regression)

The #4753 input-release (bodyText = undefined before streaming) made the
fastpath gate in prepare-openai (bodyText !== undefined && ...) unreachable:
the watermark fastpath silently never fired, and plugin wire sessions paid
the full reparse+rehash on every turn. Release the text only on the slice
where the fastpath cannot fire (non-openai wire or flag off); the strict
gate (pluginMode + !titleGen) in prepare-openai stays authoritative.

Also update the A/B pin: #5687 moved the dsh single-shot sidecar distinction
from "tool-less" to the sidecar budget (hasSingleShotBudget, <=8192), so the
test's 64K tool-less turn-0 is now (correctly) a main turn — model the real
sidecar with a 4K budget to keep pinning "side lane never stamps".
ranxianglei added a commit that referenced this pull request Nov 14, 2026
…mark fastpath (#5403/#5418 regression)

The #4753 input-release (bodyText = undefined before streaming) made the
fastpath gate in prepare-openai (bodyText !== undefined && ...) unreachable:
the watermark fastpath silently never fired, and plugin wire sessions paid
the full reparse+rehash on every turn. Release the text only on the slice
where the fastpath cannot fire (non-openai wire or flag off); the strict
gate (pluginMode + !titleGen) in prepare-openai stays authoritative.

Also update the A/B pin: #5687 moved the dsh single-shot sidecar distinction
from "tool-less" to the sidecar budget (hasSingleShotBudget, <=8192), so the
test's 64K tool-less turn-0 is now (correctly) a main turn — model the real
sidecar with a 4K budget to keep pinning "side lane never stamps".

(cherry picked from commit 09577a2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment