Repository navigation
[PR] fix: unknown dsh one-shot sidecars steal the raw-key anchor and kill compression (context-explosion root cause) - #5687
Conversation
…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).
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8162-pr.5687.9329fc8This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5687.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(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 锚定语义( 回归清点(②),逐项过 diff 触碰路径的既有行为:
发现一(已顺手修):PR 正文 发现二(需作者/owner 确认,唯一实质保留项):PR 正文「诚实边界」称无工具主对话第 1 回合被降级直通一轮「无任何可压缩内容,无害」——这只对窗口内载荷成立。超窗口载荷(estimate ≥ 窗口×1.15 且窗口已知)的行为变化是:旧 = 全管道 + preflight 有救援尝试;新 = 代码关(③):谓词完全遵循家族风格(self-contained + 溯源注释 + 测试关(④):双向断言齐(#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); 八问
收工判定:可合——待 CI test lanes 转绿 + 发现二由作者二选一处理(推荐加 fits-window 否决)。另注:本 PR 只防新增分裂,存量已坏的幽灵行不修,那部分由互补的 PR #5590(消费侧路由)在升级重启后接管,两者应先后都合入。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1032-master.8de4c37 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…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.
…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.
… 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)
…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".
…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)
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)里上下文爆炸的根因。根因链(代码级)
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,走进主管道。resolveSessionOrder(src/session-resolve.ts)的 virgin-id 分支里 mainShaped(≥3 格且含 assistant)不成立、但带非空 tag 的 shallow 请求认领 raw key(codex turn-1 例外同款语义)。辅助请求抢在首个主回合之前到达(用户在会话开始点了「增强」),锚被 sidecar 的指纹占走。<id>|sub:<fp>,永久。已在 #5656 报告者的 DB 里逐字节复现(base 行 1 条消息 / sub 行 249 条消息)。本 PR 附带 e2e 复现测试(fix 前 fail / fix 后 pass,openai + anthropic 两条 wire)。
修法(结构性,不追着功能打补丁)
一个一次性辅助调用永远伪装不出来的两件事(#546「非空 tools = 主回合」、#4438 回放否决):
tools缺失或为空(dsh 自己的请求构造器只有解析出的工具集为空时才不发 tools 键,agent-loop/src/agent.ts:669);新增
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 主流量形状)。npm run typecheck+npm run build干净。全量回归以远端 CItestlanes 为准。自动合并判定(§7.4)
不满足自动合并条件(触碰 lane 决策语义,等价 wire 消息形状判断),按需人审。纯
fix:,单模块,无 kernel/、无 update.ts、无持久化格式、无配置面。