Skip to content

fix: skip draft-tail retry when the request itself asks for the summary (#2612) - #2619

Merged
ranxianglei merged 20 commits into
ranxianglei:masterfrom
YunzhouLi-hub:2026-10-10_draft-tail-compaction
Oct 12, 2026
Merged

ranxianglei merged 20 commits into
ranxianglei:masterfrom
YunzhouLi-hub:2026-10-10_draft-tail-compaction

Conversation

@YunzhouLi-hub

Copy link
Copy Markdown
Contributor

Fixes #2612.

Problem

Since #2303 (0.1.188), a reply that ends with </summary> / </analysis> and makes no tool call is treated as a stalled draft and re-issued once. Claude Code's own compaction (/compact, auto-compact) instructs the model in its final user message to answer with plain text only — "an <analysis> block followed by a <summary> block", "Wrap your summary in <summary></summary> tags" — so a compliant reply necessarily trips the #2303 detector. The retry re-asks, the retry also complies, and the #870 in-band error surfaces to the client as "automatic compaction failed". Every client compaction on the bili claude lane fails; the proxy lane (src/loop/core.ts) has the same structural risk.

Fix

Skip the draft-tail retry when the request itself is a client summarization request. All three #2303 lanes get the same gate:

  • src/degenerate-turn.ts — requestExpectsProseSummary(requestText) matches the two verbatim Claude Code instruction phrases (not a bare <summary> tag, which also appears in bili compress receipts riding the history and must NOT suppress the retry); lastUserSummaryInstruction(messages) finds the last user message's text for the proxy lane.
  • src/plugin.ts chat pipe — draftTail verdict gains && !requestExpectsProseSummary(requestText) (requestText is the shipped wire body text).
  • src/plugin.ts responses pipe — same gate.
  • src/loop/core.ts draft-tail block — same gate via lastUserSummaryInstruction(coreMessages).

Tests

tests/issue2612-compaction-draft-tail.test.ts (7 tests, mirrors the #2303 fixtures):

tests/issue2303-draft-tail.test.ts stays 14/14 green; tsc --noEmit clean; branch based on current master (98fb91c).

…ary (ranxianglei#2612)

Claude Code's own compaction (/compact, auto-compact) instructs the model
to answer with a plain-text <analysis> + <summary> block and no tool call,
so a compliant reply necessarily ends in </summary> - exactly the ranxianglei#2303
draft-tail shape. The empty-turn retry re-asks, the retry also complies,
and the ranxianglei#870 in-band error surfaces to the client as "automatic
compaction failed".

Gate all three ranxianglei#2303 lanes on the request itself carrying the client
summary instruction (two verbatim Claude Code phrases; a bare
</summary> riding the history - e.g. a compress receipt - must NOT
suppress the retry):

- src/degenerate-turn.ts: requestExpectsProseSummary() plus
  lastUserSummaryInstruction() helper for the proxy lane.
- src/plugin.ts chat pipe: !requestExpectsProseSummary(requestText).
- src/plugin.ts responses pipe: same gate.
- src/loop/core.ts draft-tail block: same gate via the last user
  message text.

tests/issue2612-compaction-draft-tail.test.ts: 7 tests - helper unit
tests (incl. near-miss and bare-tag false cases), no-retry with the
instruction on both pipes and the loop, ranxianglei#2303 still enforced without
the instruction.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始按规范审查 PR #2612(审原 issue 方向 → 回归清点 → 代码精读 → 测试有效性 → diff 整洁度)。分支已拉取核对中,结论稍后按结构化八问给出。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2619(Fixes #2612)审查完成 — 可合(human merge)

① 是什么问题:Claude Code 自己的 /compact、auto-compact 在最后一条 user 消息里明确要求「纯文本回复,<analysis> 块后跟 <summary> 块、不要调工具」;#2303 的 draft-tail 检测器把这种合规回复当成「模型把压缩草稿写成正文」的停滞草稿重试一次,重试同样以 </summary> 结尾 → #870 in-band error → bili claude 通道每次客户端压缩都失败("automatic compaction failed")。

② 什么原因导致的:DRAFT_CLOSE_TAIL(src/degenerate-turn.ts:51)只按响应形状判定,不问「本次请求本身是否就要求这个形状」。违规字节的产生者是客户端压缩指令,不是模型故障——修复点在判定处加门控,而不是过滤载荷。方向正确(疏而非堵)。

③ 影响范围与严重程度:bili claude(plugin chat pipe)客户端压缩完全不可用(0.1.188+);responses pipe 与 proxy loop(src/loop/core.ts)存在同构风险,任何模仿 CC 压缩提示词格式的客户端触发。严重度高,但仅限该特定请求形态。

④ 怎么修复的:新增 requestExpectsProseSummary()——匹配 CC 两条逐字指令短语(大小写不敏感),刻意不匹配裸 <summary> 标签(裸标签也出现在历史里的 bili compress receipt 中,若匹配会错误抑制普通轮次的重试);三条 #2303 判定线各加同一门控:plugin chat/responses pipe 用 requestText(发出的 wire body 文本,src/server/relay.ts:957),proxy loop 用 lastUserSummaryInstruction(coreMessages)(最后一条 user 消息文本)。

⑤ 是否有回归问题(逐项清点既有行为):

⑥ 是否破坏缓存:不涉及。前缀缓存、更新节流、增量游标均未触碰,仅本地重试判定条件变化。

⑦ 是否改了设计方向:无。未采用原 issue 备选方案「本轮请求不含 compress 工具」——plugin 模式下 bili 本就不向请求注入 compress 工具(agent 自持压缩,KDD #7),该谓词对每一轮都为真,会永久禁用保护;短语匹配在三条通道上都成立,是正确选择。

⑧ 是否引入了新的配置:无。

验证证据:本地 tsc --noEmit clean;tests/issue2612-compaction-draft-tail.test.ts 7/7 + tests/issue2303-draft-tail.test.ts 14/14 绿;分支基于当前 master(merge-base = 98fb91c,单提交,4 files +331/-4,diff 干净);GitHub CI 首轮 20/27 success、主 test matrix 运行中,无失败。测试有效性:refetch/fetch 计数断言有牙(bug 回归即红),near-miss(<summery> typo)与假阳性用例齐全。

顺手小修(已推 PR 分支,独立标注提交 173c7e90b):fixture CC_COMPACTION_PROMPT(tests/issue2612-compaction-draft-tail.test.ts:23)混入一个游离汉字「约」→ 改为 "about",不影响断言。

MINOR 发现(未动,留作者/owner 裁量):原提交 4521a99b3 的 subject 在 fix: 前有一个 UTF-8 BOM(U+FEFF,已 hexdump 确认)。功能上惰性(CI 无依赖该前缀解析的门禁,各 guard 全绿);修复需 amend 作者提交并 force-push 其 PR 分支,超出「附加式顺手修」的安全边界,故只报告。

判定:方向正确、修法打在根因、回归覆盖充分、diff 整洁——可合。按 §7.4,改动横跨 degenerate-turn.ts/plugin.ts/loop/core.ts 且改变重试机制的触发条件,属 human-review-and-merge 档位,请人工合并。

@YunzhouLi-hub

Copy link
Copy Markdown
Contributor Author

CI note: test (windows-latest, 24) fails here, but the same test fails on master itself — run 38034641775 (98fb91c) has test (windows-latest, 22) and test (windows-latest, 24) both red with the identical failure:

✖ #2605: dsh.bundle.patch.yml restates every default code + MALFORMED_RESPONSE on both DeepSeek routes

All ubuntu combos green on both master and this PR, and every other check passes. This looks like a pre-existing Windows-specific breakage introduced with #2610, not something from this branch (which only touches the draft-tail retry gates).

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 已独立核实,你的判断成立——两个红色 windows job 与本 PR 无关,判定不变:可合(human merge)。

核实过程与补充定位:

  1. 失败内容逐字节一致。拉取了 master run 38034641775(98fb91cc2)与本 PR head 173c7e9(run 38035411113)的四个 windows job 日志,两边 ✖ 行集合 diff:唯一失败项都是同一个测试——
    #2605: dsh.bundle.patch.yml restates every default code + MALFORMED_RESPONSE on both DeepSeek routes
    AssertionError [ERR_ASSERTION]: compaction-basic auto:false row must stay intact @ tests/issue2605-dsh-retry-patch.test.ts:27:12
    ubuntu 四组合两边全绿,其余 check 全绿。

  2. 根因已定位(比「pre-existing」再进一步):.gitattributes 只为 tests/golden/wire-contract/*.json 钉了 text eol=lf(test: wire-contract anti-regression system — parity fakes, goldens, unified ledger #1305 修的正是这一类 bug),而 dsh.bundle.patch.yml 不在清单里。仓库内该文件是纯 LF(git blob 验证 0 个 CR),但 Windows runner 上 Git-for-Windows 默认 core.autocrlf=true 把它 checkout 成 CRLF;测试用 LF 锚定的常量做精确 includes() 匹配(tests/issue2605-dsh-retry-patch.test.ts:19-23),于是必挂。同文件的 overlay 测试通过是因为 writeDshAcpPatch 内存生成、天然是 LF。本地模拟 CRLF 内容复现:includes(LF_ROW)=false,归一化后 true。引入提交 eb0e4d2(一次坏工具参数就让整轮作废:希望把 MALFORMED_RESPONSE 纳入重试名单 #2605/fix: retry MALFORMED_RESPONSE on DSH built-in DeepSeek routes (#2605) #2610 的 bundle-lane 钉线测试)。

  3. 已立项跟踪:windows-latest CI red on master: #2605 bundle-patch test breaks under CRLF checkout (dsh.bundle.patch.yml missing from .gitattributes eol=lf) #2623 (带来源标记;建议修法:.gitattributes 加一行 dsh.bundle.patch.yml text eol=lf,与 test: wire-contract anti-regression system — parity fakes, goldens, unified ledger #1305 先例一致;备选是测试内 \r\n→\n 归一化)。纯 CI 卫生问题,无运行时影响。

结论重申:本 PR 只动 draft-tail retry 门控(degenerate-turn/plugin/loop 三处 + 新测试),与上述 Windows 红 job 零交集;除该 pre-existing 失败外 CI 全绿。可合,请人工合并(§7.4 human 档位:跨三个模块且改变重试触发条件)。

@YunzhouLi-hub

Copy link
Copy Markdown
Contributor Author

冲突已解决(e581649):master 的 #2756 answer-chars 重试逻辑与 #2612 的
equestExpectsProseSummary\ 门控逐字共存——chat-pipe 与 responses-pipe 两处 draftTail 判定均为 ... && !requestExpectsProseSummary(requestText),#2756 的 answerChars 分支原样保留。本地回归:issue2303 14/14、compaction-archive 7/7、issue2756-degenerate-gate 12/12 全绿。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 冲突解决 e581649 已独立核实——逐字共存属实,判定不变:可合(human merge)。按八问:

① 是什么问题:长期存活的 PR 分支与 master 冲突——master 的 #2756(answer-chars 门控)重写了本 PR #2612 所改的同一批 draft-tail 判定行(典型热文件竞争,§7.5 第 1 类)。

② 什么原因导致的:两个 PR 各自向同一条 draftTail = … 表达式追加不同子句(#2612 加请求侧短语门控,#2756 把「可见字节」判据改为「ANSWER 文本」判据),文本级冲突。

③ 影响范围与严重程度:若解错,要么丢 #2612 门控(CC 压缩失败复现),要么丢 #2756 answerChars 条件(纯空白应答不再触发重试)。属高危解决点,故做了逐行验证而非只看测试。

④ 怎么修复的:把 master 合入 PR 分支(e581649e,parents 09862cd+e7b94a2e0),三处判定取两侧意图的并集。

⑤ 是否有回归问题:无。证明方式——git diff e7b94a2e0..e581649e(合并结果 vs 合并前 master)在热文件上的新增行与原始 PR 提交的新增行逐字节一致(sort-diff IDENTICAL),删除集合也一致;即 合并结果 ≡ master(含 #2756 原样)∪ #2612(原样),不存在第三种写法。三处判定实测:src/plugin.ts:2170(chat)、src/plugin.ts:3516(responses)均为 … && endsWithDraftClose(proseAcc) && !requestExpectsProseSummary(requestText),且相邻的 #2756 answer-chars 注释/分支原样在位;src/loop/core.ts:995 门控保留。本地定向回归 47/47 绿:issue2303 14 + issue2612 7 + issue2756-degenerate-gate 12 + compaction-archive 7 + loop-degenerate-retry 7;tsc --noEmit clean。

⑥ 是否破坏缓存:不涉及。

⑦ 是否改了设计方向:无——两套机制按各自设计意图共存。

⑧ 是否引入了新的配置:无。

补充状态:CI 对 e581649 29/29 全绿(含 windows-latest 两组合——之前那个 pre-existing 红 job 已被 master 上的 #2631/#2634 EOL 修复治愈)。master 此后仅前进一个 #2763(raw-url compaction sniff,只动 src/agent/native-intercept.ts+其测试+dsh-compaction-guard,与本 PR 零文件交集),不产生新冲突。可合,请人工合并。

@YunzhouLi-hub

Copy link
Copy Markdown
Contributor Author

CI 红 3 例已查明:不是本 PR 的回归——上一轮 merge 落在了 master 的一个坏点上(525b4f5,#2807 引入 fork/affinity 回归),owner 随后在 1b7e380 修复。已合入最新 master(21b99d7,含 v0.1.194),六个相关套件 45/45 全绿。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 本轮「CI 红 3 例」已独立核实——归因成立,非本 PR 回归。判定不变:可合(human merge)。按八问:

① 是什么问题:PR 分支的一次同步合并(abd855500 "merge master")落在了 master 的一个中间坏点上——#2807(cross-protocol affinity)已引入回归、而其修复尚未合入的时间窗内,导致 CI 三个测试用例转红。

② 什么原因导致的:时序窗,不是本分支代码。族谱证明:525b4f51(#2807 merge)∈ abd8555 的祖先,而 1b7e3802(fix(affinity): append-continuation rung + hv2 ladder preference)∉ abd8555;修复随后续 master 进入 21b99d7 后治愈。

③ 影响范围与严重程度:红点精确为 3 个用例(拉取红头 bb5a63d 的 ubuntu24 job 日志逐一比对):#2033 A1 anchored anonymous session…、#2601 unit: image placeholder appended to the TAIL projects equal、forkAdoption disabled leaves the responses fork at zero compression state——全部位于 #2807/修复所触碰的 affinity/fork 域(src/affinity-neutral.ts、src/prefix-affinity.ts、src/server/handle.ts),与本 PR 文件(degenerate-turn/plugin/loop-core)零交集。回归本身已由 1b7e380 在 master 上修复,无残留运行时影响。

④ 怎么修复的:把最新 master 合入 PR 分支得 21b99d7。小更正一处措辞:21b99d75 是 PR 分支 head,master tip 实为 cd02d2d(Merge #2826 release-v0.1.194)——即 21b99d7 的父提交;merge-base(PR, master)=cd02d2dc5,分支相对当前 master 零落后。

⑤ 是否有回归问题:无。验证链——(a) 上述族谱三项断言全部实测通过;(b) 红用例集合与 #2807 文件域吻合、与本 PR 域不相交;(c) 本地 21b99d7 上定向跑 8 套件 59/59 全绿(issue2303 14 + issue2612 7 + issue2756-degenerate-gate 12 + compaction-archive 7 + loop-degenerate-retry 7 + 三个曾红的测试文件 12),tsc --noEmit clean;(d) 三处 draft-tail 判定在本轮合并后仍逐字节原样在位(src/plugin.ts:2170、src/plugin.ts:3516、src/loop/core.ts:995)。

⑥ 是否破坏缓存:不涉及。

⑦ 是否改了设计方向:无。

⑧ 是否引入了新的配置:无。

CI 现状(21b99d751):29 项中 25 success,仅 4 个 test-matrix job 运行中,零失败。分支基于含 v0.1.194 的当前 master,无新冲突。可合,请人工合并。

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

Labels

None yet

Projects

None yet

2 participants