Skip to content

[PR] fix: anthropic lane nudge names the <analysis>/<summary> envelope fai… - #3903

Merged
ranxianglei merged 6 commits into
ranxianglei:masterfrom
huzilin:fix/dsh-compression-protocol
Oct 20, 2026
Merged

ranxianglei merged 6 commits into
ranxianglei:masterfrom
huzilin:fix/dsh-compression-protocol

Conversation

@huzilin

@huzilin huzilin commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

这个 patch 存在的原因(生产事故驱动)

  1. 现象:DSH desktop 上走 Anthropic Messages lane 的会话,到压缩时机后,模型把 <analysis>…</analysis><summary>…</summary> 当回复正文吐出来,而不是放进 compress 工具的 content 参数。裸 </summary> 泄漏进可见转录;且无 tool call 的回复直接结束轮次 → 会话卡死,直到用户手打 "continue"。
  2. 根因:renderNudgeText 没有 protocol 维度——tool 定义、消息包装、SSE 解析都已按协议分发,唯独四个 lane、八处调用点共用同一份 nudge 措辞。而 Anthropic 形态请求(顶层 system、thinking、tool_use 块)会把模型 prime 进 Claude Code 的压缩信封习惯,通用措辞没有点名这个失败形态。
  3. 上游 master(含 0.1.202)目前不含此修复,已核实 git grep origin/master 无命中 → MR 有效。

如何改动(9 文件,+220/−15)

  • kernel/src/nudge-text.ts

    (+25):

    • 新增 export type NudgeProtocol = "anthropic" | "openai" | "responses" | "google";
    • renderNudgeText(decision, prompts, sections, protocol?) 增可选第 4 参(缺省=协议中立,旧行为);
    • 新增 ANTHROPIC_LANE_NOTE:"Write the summary ONLY as the compress tool's content argument. Never emit <analysis> or <summary> tags in your reply text — they are not parsed, and a reply without a tool call ends the turn."
    • 在 全部三种渲染分支(emergency / T2 与 T3 / gentle 提示)末尾追加(append,从不替换)。
  • src/server/prepare-{anthropic,google,openai,responses}.ts(各 2 行):八处调用点补传各自协议字面量——anthropic 两处(含 fallback 路径),其余 lane 显式声明以便逐字节回归断言。

  • kernel/tests/nudge-text.test.ts(+103):注记在三种分支下存在/不存在、非 anthropic 与缺省输出逐字节等于旧版。

  • tests/anthropic-lane-nudge.test.ts(新增 85 行,3 tests):lane 级回归。

  • kernel/package.json / package-lock.json:按 Kernel Boundary 纪律 0.0.136 → 0.0.137(注:本地原始提交是 0.0.130→0.0.131,摘到最新 master 上已顺势改为 0.0.136→0.0.137,commit message 同步)。

兼容性:无配置面改动;非 Anthropic lane 与不传 protocol 的默认路径字节级不变。

kernel-change: adds an optional protocol parameter to renderNudgeText (kernel/src/nudge-text.ts) plus an Anthropic-lane note naming the <analysis>/<summary> envelope failure mode (production incident, DSH desktop / Anthropic wire); non-anthropic and default-caller output is byte-identical; version 0.0.136 → 0.0.137 per Kernel Boundary rule 2.

…lure

Anthropic Messages lanes (top-level `system`, `thinking` blocks, `tool_use`
blocks) prime the model for the Claude-Code compaction envelope: when
compression is due it writes `<analysis>...</analysis><summary>...</summary>`
as its reply text instead of putting the summary in the `compress` tool's
`content` argument. A reply with no tool call ends the turn, so the session
stalls until the user types "continue".

`renderNudgeText` did not take the protocol, so all eight call sites across
the four lanes emitted the same wording — while tool definitions, message
wrapping and SSE parsing were already protocol-dispatched. Add the missing
dimension: an optional `protocol` parameter plus an Anthropic-only note that
names the envelope the model must not emit and the delivery shape it must use.

Every other lane and the protocol-neutral default are byte-identical to
before; the note is appended, never substituted.

kernel: 0.0.136 -> 0.0.137 (Kernel Boundary version discipline)

kernel-change: renderNudgeText gains a protocol parameter so the Anthropic
lane's growth nudge can name the <analysis>/<summary> envelope failure
@ranxianglei ranxianglei changed the title fix: anthropic lane nudge names the <analysis>/<summary> envelope fai… [PR] fix: anthropic lane nudge names the <analysis>/<summary> envelope fai… Oct 20, 2026
The kernel bump 0.0.136 -> 0.0.137 landed in kernel/package.json + kernel/package-lock.json, but the root package-lock.json still records the file: dependency's version under its "kernel" entry. lock-sync (npm install --package-lock-only + git diff) regenerates it to 0.0.137 and fails on the drift.
@ranxianglei ranxianglei added bug Something isn't working dsh p1 scope/kernel labels Oct 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。open+closed issue/PR 按「anthropic nudge 信封」「dsh 压缩卡死」「analysis/summary 泄漏」等多组失败签名检索均无命中;与 #3617(gate 双向断言)、#3401(dsh compress surface 过抑制)同域但机制不同——本条是 nudge 措辞缺协议维度,非 gate 决策问题。
标签:bug / dsh / scope/kernel / p1 —— 生产事故、根因修在 kernel 的 nudge 渲染器;p1 理由:触发时该会话完全停摆直到人工干预,属核心承诺失灵(owner 可降 p2,恢复路径是手打 continue)。

审核结论(结构化八问)

  1. 是什么问题:Anthropic wire 会话到压缩时机,模型把摘要按 Claude Code 的 <analysis>/<summary> 信封当回复正文吐出来,而不是放进 compress 工具的 content 参数;裸 </summary> 泄漏进可见转录,且无 tool call 的回复直接结束轮次 → 会话卡死。
  2. 什么原因导致的:renderNudgeText 没有 protocol 维度——tool 定义、消息包装、SSE 解析都按协议分发,唯独四个 lane、八处调用点共用一份通用措辞;而 Anthropic 形态请求(顶层 system、thinking、tool_use)会把模型 prime 进信封习惯,通用措辞没有点名这个失败形态。作者的层次定位准确:修的是措辞生成点(源头),不是去过滤模型输出(堵)。
  3. 影响范围与严重程度:走 Anthropic lane 的客户端(DSH desktop 为已证实场景)在压缩时机 + 模型出现信封习惯时触发;触发即会话停摆需人工救。特定条件但后果严重 → p1。
  4. 怎么修复的:renderNudgeText 增可选第 4 参 protocol;anthropic 时在全部三种渲染分支(gentle / emergency / T2-T3)末尾追加一条点名失败形态的注记("只写进 compress 的 content 参数、别在正文吐标签、无 tool call 就结束轮次")。append-only 从不替换;八处调用点各传自己的字面量;非 anthropic 与缺省路径字节级不变(有逐字节回归断言钉住)。
  5. 是否有回归问题:逐项审过既有行为——① 非 anthropic lane 与默认路径字节不变(测试钉住,我核过 compact()+join 语义);② nudge 消息本就是声明式易变尾随 user 元素(cache-proof 的 NOTE_MARKERS 载体契约),注记内容确定性生成,不破坏前缀缓存、system 头保持字节稳定;③ golden wire-contract 不受影响(defaultPrompts 未动,注记不是其成员);④ 边界核查:三个分支的基底文本含常量段,不可能为空 → 不会出现"原来不注入、现在凭空注入"的新注入点;⑤ 版本纪律 0.0.136→0.0.137 合规。未发现回归。
  6. 是否破坏缓存:否。nudge 是 ephemeral 尾随消息(不落盘、不进历史),注记确定且仅追加在载体 payload 内。
  7. 是否改了设计方向:否。只在既有 nudge 渲染上加协议维度,管线/身份模型未动。
  8. 是否引入新配置:无。

我在 PR 分支上直接修的三处(均已 push,独立 commit/操作,可单独回退)

  1. lock-sync 红:kernel 版本 bump 进了 kernel/package.json + kernel/package-lock.json,但根 package-lock.json 里 file: 依赖的 "kernel" 条目还停在 0.0.136——CI 重算 lockfile 必然漂移。一行修正(commit 9e7468a95),现在该 job 已转绿。
  2. kernel-guard 红:PR 正文缺 Kernel Boundary 要求的 kernel-change: 声明。已在 PR 描述末尾补上(机械门禁管务,声明内容与本 PR 实际改动一致,全文可见于 PR 页)。
  3. 空提交一次(65eaff0af):kernel-guard 读的是事件快照里的 PR body,补声明晚于 push 触发的 run,需要一次 synchronize 事件让 CI 拿到新 body。无文件变更。

一个质量缺口 → 已立项 #3910

tests/anthropic-lane-nudge.test.ts 名叫 "lane 级回归",实际只直接驱动 renderNudgeText 函数本身——八处接线调用点没有任何端到端测试钉住:日后谁把 prepare-anthropic.ts 里的 , "anthropic" 删掉,TS 不报错、CI 全绿,生产事故静默复发。我评估后没有直接把 harness 用例塞进本 PR:沙箱网络策略不允许从 npm registry 装 node_modules,新写的场景化测试无法本地验证,盲推别人的 PR 只会烧 CI 周期。#3910 里附了具体修法(#2499 式 hermetic server harness + 正/负向断言)。不阻塞本 PR 合入——kernel 契约已被钉住,接线是 8 行显式字面量且我已逐点核对。

验证方式说明

本地定向跑不了(工作区无 node_modules、registry 在沙箱网络边界外),全量裁决以远程 CI 为准:两个原红 job(lock-sync/kernel-guard)已在最新 head 65eaff0af 上重新触发,test/static-gates 矩阵随之解禁运行中。

判定:等新一轮 CI 全绿即可合入(建议现在就合,wiring 测试缺口由 #3910 跟进)。另注:分支落后 master 127 个提交但无分叉,CI 在合并视图上跑,不影响结论;我没有 rebase 作者分支,全部改动都是附加式的。

awork added 3 commits October 20, 2026 12:46
… and cancelled each other (no file changes)
…e nudge test

tests/anthropic-lane-nudge.test.ts built its synthetic NudgeDecision from a breakdown/contextBreakdown shape that predates the kernel's growth of those types (several now-required numeric fields), leaving branch typecheck red. Supply the full required fields from a shared BASE_BREAKDOWN (flat-50K nudge growth constants = kernel defaults) without touching any assertion. In-passing fix surfaced while adding the ranxianglei#3910 lane-level wiring test; keeps this branch's CI green.
…i#3910)

ranxianglei#3903 added the ANTHROPIC_LANE_NOTE by passing the 'anthropic' protocol literal at both prepare-anthropic renderNudgeText call sites, but every test only drove renderNudgeText directly - nothing asserted the note actually reaches the OUTBOUND wire. If the optional ', "anthropic"' argument were later dropped, TS would not complain and CI would stay green while the ranxianglei#3903 production failure (model writes <analysis>/<summary> as reply prose, ends the turn with no tool call, session stalls) silently regresses.

Add tests/issue3910-lane-nudge-wiring.test.ts driving prepareAnthropic through the hermetic server harness (same OVER-LIMIT arming recipe as tests/compaction-trigger-finality.test.ts: local estimate under the band keeps turn 1 clean, upstream-reported usage arms turn 2):
- positive: anthropic /v1/messages turn-2 body carries the note exactly once, in the trailing nudge user message; every other message is note-free.
- negative (ranxianglei#3617 bidirectional discipline): the same scenario over the openai chat wire appends its nudge too (turn-delta proves non-vacuity) but carries the anthropic note nowhere.

Mutation-verified: removing the ', "anthropic"' argument at both call sites turns the positive case red.
@ranxianglei
ranxianglei merged commit 724e590 into ranxianglei:master Oct 20, 2026
46 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.651-master.724e590 (rolling master tag).

npm install -g billion-context@0.0.651-master.724e590  # 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dsh p1 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants