Skip to content

[PR] fix(loop): hold a bili-owned round's thinking until its signature, so a cut inside round ≥2 stays re-fetchable - #4681

Merged
ranxianglei merged 15 commits into
ranxianglei:masterfrom
Maziar123:fix/round2-thinking-hold
Nov 9, 2026
Merged

ranxianglei merged 15 commits into
ranxianglei:masterfrom
Maziar123:fix/round2-thinking-hold

Conversation

@Maziar123

@Maziar123 Maziar123 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4679

What

Round ≥ 2 is bili's own re-request (a proxy tool already executed and bili re-sends on the client's behalf). Its truncated attempt must therefore stay invisible, or the client is stuck: round 1 has already committed visible text (the 📦 [ACP] … receipt) to the client's stream, so the client cannot replay the turn itself.

Before: an upstream cut inside a round-2 thinking block streamed the block's start + deltas to the client, the signature never arrived, unsignedThinkingBarsRefetch (#2501) — correctly — refused both re-fetch shapes, and the loop ended the turn with event: error. Unrecoverable.

After: on an upstream that is evidenced to sign thinking, a bili-owned round keeps its thinking payload off the wire until its signature_delta:

Nothing in #2501 changes: its round-1 hold and its gate are untouched. The round-≥2 case simply never reaches the gate with an unsigned block on the wire.

Why not the alternatives

  • Receipt off the assistant-text channel: does not help whenever any text precedes the proxy tool, changes designed client-visible behaviour (the receipt is the user's only evidence the fold happened), and is unnecessary once bili can retry its own round.
  • Retry the round after the unsigned block is already out: re-fetches a response whose predecessor already poisoned the client's history — exactly the [bug] anthropic 线盲重取(#413/#1455)把没签名的 thinking 块交给客户端:下一轮 400 "thinking.signature: Field required",Claude Code 随即永久剥掉全部历史 thinking #2501 failure mode (next replay → 400 thinking.signature: Field required → Claude Code strips ALL prior thinking).
  • Hold unconditionally in round ≥2: delays every never-signing relay's (GLM/DeepSeek anthropic-compat) round-2 thinking to a burst at block end for no benefit — those endpoints have no signature contract to violate. The evidence gate is what keeps that behaviour intact; the flag exists, so widening it later is a one-line change if the maintainer prefers.

Tests

tests/anthropic-round2-thinking-hold.test.ts (new, 4 cases, hermetic — mocked fetch, no network):

case before after
T1 cut inside round-2 thinking, history evidence — nothing unsigned on the wire, blind re-fetch recovers FAIL (calls === 1, turn ends in error) PASS
T2 never-signing relay keeps streaming round-2 thinking live (negative direction: the hold must NOT arm) PASS PASS
T3 a signature-completed round-2 block arrives as ONE block, start first PASS PASS
T4 turn-level evidence — round 1's signature arms round 2 on a history with none FAIL (payload leaked to the wire) PASS

Commands (this clone, node 24 / linux):

node --import tsx --test tests/anthropic-round2-thinking-hold.test.ts                    # 4/4 pass
node --import tsx --test tests/anthropic-round2-thinking-hold.test.ts \
  tests/anthropic-truncation-unsigned-thinking.test.ts tests/anthropic-round2-stream.test.ts \
  tests/anthropic-thinking-replay.test.ts tests/issue1455-truncation-ping.test.ts \
  tests/issue1470-anthropic-nudge.test.ts                                               # 23/23 pass
npx tsc --noEmit --project tsconfig.json                                                 # exit 0

Local full npm test in this checkout is dominated by pre-existing environment failures: pristine d1b46fc0 reports the same ~20 (storage engine/golden state digests, storage-orphan-recovery, native-host module evaluation, opencode-native, v2 setup, HTTP fork, #2443/#3278/#3304) — none of them in the anthropic loop path. Between the pristine run and the run on this branch the ONLY differences are my new T1/T4 flipping fail → pass, plus one flaky module evaluation marks the process as a native {pi,opencode} host test whose identity alternates between runs. Full-suite verdict is CI's anyway (AGENTS.md §7).

Branch head: a220df9c on fix/round2-thinking-hold = the reviewed 30c70efa plus a merge of master bcbd1a3d (no conflicts). Against master the diff is 4 files and touches nothing under kernel/ or the lockfiles, so kernel-guard has nothing to gate. On the merged head: tsc --noEmit exit 0, node scripts/check-unused-exports.mjs clean (6 waived, none added).

Risk

  • Wire shape: unchanged for round 1 and for every round on a never-signing relay. On an evidenced signing upstream, round-≥2 thinking now arrives as one burst at its signature instead of streaming — the same latency price [bug] anthropic 线盲重取(#413/#1455)把没签名的 thinking 块交给客户端:下一轮 400 "thinking.signature: Field required",Claude Code 随即永久剥掉全部历史 thinking #2501 already accepted, and the only way to keep a cut recoverable.
  • Memory: bounded by max_tokens per block; no cap added.
  • Rebuild parity: held payload still feeds the loop's accounting, so the re-request rebuild and the client's persisted history hold the same bytes as before (withheld is accounting-only, no wire bytes).
  • parseStream gained an optional third parameter (ParseStreamOpts, module-private since f87e96a7); the other adapters are unaffected (fewer params stay assignable) and no call site outside the loop changed.
  • Two thinking blocks in one round ≥2, cut after the second (found in review): the first block is committed and signed, and the cut can trigger a blind refetch. Both blocks are legal signed blocks, so the replay is accepted (no brick); the cost is one extra prefix on that narrow path.

… a cut inside round >=2 stays re-fetchable (ranxianglei#4679)

A proxy tool (compress …) makes bili re-request on the client's behalf
(round >=2) after it has already streamed its own receipt as assistant TEXT,
so the client cannot replay that turn at all. When the upstream cut landed
inside a thinking block, the block's start + deltas were already on the
client's wire unsigned, ranxianglei#2501's unsignedThinkingBarsRefetch refused both
re-fetch shapes, and the !sawDone branch ended the turn with `event: error`
— unrecoverable, and the fold the user paid for was already committed.

Round >=2 is bili's OWN round, so its truncated attempt must leave no client
state. On an upstream evidenced to sign (signed thinking in history, or an
earlier round of this request), the adapter now buffers a round-2 thinking
payload off the wire and reports it to the loop as accounting only
(`withheld: true`, still feeding the re-request rebuild); `signature_delta`
releases start + payload + signature together as ONE block, and a
`content_block_stop` with no signature discards the buffer (on an evidenced
signing upstream a signature-less block is invalid history by definition).
The adapter self-arms the hold the moment a parse sees a signature.

Death before the signature therefore leaves nothing behind, so the existing
ranxianglei#413 blind re-fetch of the same round fires and heals the turn. Never-signing
relays (GLM/DeepSeek anthropic-compat) have no evidence and keep streaming
live; ranxianglei#2501's round-1 behaviour and its gate are untouched.

tests/anthropic-round2-thinking-hold.test.ts: T1/T4 fail on d1b46fc (one
fetch call, turn ends in error / payload leaked) and pass here; T2 (relay
keeps streaming, hold must NOT arm) and T3 (one signed block) pass both ways.
@ranxianglei ranxianglei changed the title fix(loop): hold a bili-owned round's thinking until its signature, so a cut inside round ≥2 stays re-fetchable [PR] fix(loop): hold a bili-owned round's thinking until its signature, so a cut inside round ≥2 stays re-fetchable Oct 25, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 检索了 open+closed 的 issue 与 PR,没有针对「bili 自有轮(round≥2)thinking 截断后不可恢复」这一具体缺陷的既有项。PR 依赖的 #2501(unsignedThinkingBarsRefetch)、#413(盲重取)、#1960(KDD#10 thinking 签名校验)是它构建其上的机制,不是重复项。
标签:bug / claude-code / scope/wiring / p2(修的是缺陷;受影响的具体客户端代表是 Claude Code——#2501 里「Claude Code 会永久剥掉整段 thinking」正是这个死局的执行者;领域在请求管道/wire 改写 src/loop/,非 kernel;p2 而非 p1:丢的是单轮、可重发,会话没坏、无数据丢失/损坏,够不到「会话无法恢复/缓存泄露」的 p1 线)。

一句话结论:代码本身正确、测试有牙、方向对;唯一拦路的是一个几行级 CI 红(unused-exports),我这边推不进你的 fork,给你精确修法。 这是 wire/消息形状 + KDD#10 相邻改动,按 §7.4 必须人工合并,我不会代合。


结构化八问

1. 是什么问题
Anthropic 系会签名的上游上,bili 自己重发的那一轮(round≥2,即代理工具如 compress 执行后)若在 thinking 块中途被上游截断,整轮就死了且救不回来:客户端手里留下一个无签名 thinking 块,#2501 正确地拒绝所有重取;而 round 1 已把回执文本写进客户端流,客户端自己也没法重放。用户丢一轮,还得为已提交的压缩再付一次钱。

2. 什么原因导致
三个既有行为叠加:① round 1 的工具回执按设计写成 assistant text → 让 round≥2 对客户端不可重放;② thinking 增量每一轮都实时转发(#2501 只 hold 起始帧、首个增量就放行)→ 首个增量后客户端就有一个开着的无签名块;③ #2501 的 unsignedThinkingBarsRefetch 于是禁掉了唯一的恢复手段(盲重取),落空即终态 error。根因是:#413/#2501 的「零副作用重取」保证只覆盖了起始帧,没覆盖 bili 自有轮的 thinking 增量。

3. 影响范围与严重程度
仅签名的 Anthropic 上游(直连/CCR、Vertex、Claude-via-OpenRouter 一类)proxy 模式,且切点落在 bili 自有轮某个 thinking 块内才触发;不签名的中转(GLM/DeepSeek anthropic 兼容端点)不受影响。频率取决于上游部署特性,不是 bili 的。严重度 p2:丢单轮、可重发兜底,会话不坏、无数据丢失/损坏。

4. 怎么修的
不是放宽 #2501,而是把 bili 自有轮做成可重放安全。证据门控的 hold:当上游被证据判定会签名(请求历史含签名 thinking,或本请求早期轮次已见签名;解析中见到 signature_delta 即自武装)时,adapter 把 round≥2 的 thinking 载荷缓冲在 wire 之外、只以记账形式(withheld)喂给 loop;signature_delta 到达才把「起始帧+载荷+签名」一次性按单块放出;无签名的 content_block_stop 丢弃缓冲。于是死在签名之前 = 客户端零状态,既有的 #413 盲重取照旧触发并治愈整轮。round 1 与不签名中转完全不动。

5. 是否有回归问题(逐条过触碰路径的既有行为)

  • round 1:不动(hold 要求 round>1)✓
  • 不签名中转:无证据 → hold 不武装 → 仍实时转发,由测试 T2 钉住 ✓
  • [bug] anthropic 线盲重取(#413/#1455)把没签名的 thinking 块交给客户端:下一轮 400 "thinking.signature: Field required",Claude Code 随即永久剥掉全部历史 thinking #2501 门与其 round-1 语义:逐字未改 ✓
  • KDD#10(thinking 永不改写):hold 重放的是同一批字节;唯一变换是走既有 remapIndexInEvent 的索引重映射(每个转发事件本来就这么做),thinking 文本与签名逐字不变;rebuild 对 withholding 的文本无过滤累积、并对签名协议丢弃无签名段(requiresThinkingSignature),故重请求字节自洽 ✓
  • 每次 attempt 顶部重置记账(core.ts 循环头 roundParts.length=0 等)→ 重取的 rebuild 不会重复计数一个块 ✓
  • 我单独查过的边界:某轮≥2 响应里有两个 thinking 块、切点落在第 2 块之后(第 1 块已提交+签名)时,盲重取可能触发(此时无可见输出、wire 上无未签名块),会把第 1 块的帧在高索引处再发一次。两份都是合法签名块 → 回放被接受(不会砖),只是下一轮前缀多付一次 token 的成本瑕疵,严格优于修复前的终态 error。发生条件很窄(需 round≥2 多块 + 切在两块之间)。如实记录,非拦路项。
  • 高危模式逐项:无 fail-fast 变吞错、无阈值/时序/输出格式漂移(除下述已披露的 burst 变更)、无缓存键/失效变化。

6. 是否破坏缓存
否。重取复用同一份请求体(byte-identical,沿用 #413 既有设计),前缀缓存前沿标记不受影响;hold 后放出的帧索引/内容一致;没有引入新的失效。

7. 是否改了设计方向
无架构转向。是把既有 #413/#2501 的零副作用机制从「起始帧」扩到「起始帧+载荷」、且仅在 bili 自有轮、且门控在新的轮级证据 sawSignedThinkingThisTurn 上。新增一个导出类型 ParseStreamOpts 把证据传进 parseStream。

8. 是否引入新配置
无新 env/config/CLI。武装全自动(基于证据),不加旋钮。(若日后要无条件 hold round≥2,flag 已在、一行即可——但刻意不做,那会让每个不签名中转的 round-2 thinking 都延迟到块尾一次性出,是给 GLM/DeepSeek 用户的可见回退。)


⚠️ 行为变更(必须披露,旧值→新值+原因)

对被证据判定会签名的上游,round≥2 的 thinking 到达方式变了:

  • 旧:delta 逐条实时流式下发。
  • 新:缓冲到 signature_delta 到达时一次性 burst 下发。
  • 范围:仅 bili 自有轮(round≥2)+ 签名上游;round 1 与中转不变。
  • 为何:只有把它留在 wire 外直到签名,才能在签名前被切断时做到客户端零状态、从而可重取。这是本修复成立的前提,属有意为之。

🚧 CI 唯一红项(需处理后才能合)

head 61a09db2 上 CI:23 成功 / 16 skipped(受门控的 e2e 车道)/ 1 失败 = unused-exports。

  • 是我核实的、本 PR 引入的:ParseStreamOpts(src/loop/core.ts:342)只在 core.ts 内被引用(定义:342、CompressLoopAdapter.parseStream 签名:352、使用:786),其它文件都不按名 import → 判 INTERNAL_ONLY。我本地跑了那个零依赖门禁脚本确认,非 master 继承红。
  • 精确修法(加一条 WAIVER,与现有 5 条同一套先例;不要去掉 export——导出的 CompressLoopAdapter.parseStream 按名引用了该类型,降为模块私有会让 tsc 声明产出报「uses private name」)。在 scripts/check-unused-exports.mjs 的 WAIVERS Map 里加:
// #4679 round2-hold: ParseStreamOpts 是传给 adapter 的解析期证据记录;adapter 以
// 结构化方式实现 parseStream(...)(opts 为位置参数、实现处不标注类型)、从不按名
// import;保留 export 使类型与其所在定义点(紧邻 CompressLoopAdapter)保持具名。
["src/loop/core.ts", new Set(["ParseStreamOpts"])],
  • 我推不进你的 fork:Maziar123/billion-context 对我的凭据只有 pull、没有 push,所以没法替你把这个 commit 提上去。麻烦你应用上面这行(或给我 push 权限我来补)。

小 nit(可选清理)

PR 描述里还留着起草期的元指令行「Before posting: replace #4679 … with the filed issue's number.」——commit 和 CHANGELOG 里的编号其实已经替换成 #4679 了,这句建议从正式描述里删掉,免得读者困惑。


收工判定:代码正确、测试有牙(SSE 校验器逐块断言「thinking 必带签名关闭」正是这个 bug 的不变量;T1/T4 断言重取、T2/T3 钉住非回归路径)、方向对。唯一拦路的是一行级 unused-exports 红。 作者补上那条 WAIVER(或授权我推)后,即可进入人工合并;涉及 wire/消息形状 + KDD#10,按 §7.4 我不代合。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

状态收尾(详细八问审核见本线程我上一条评论,这里只报结论与剩余一步):

  • 审核完成:代码正确、测试有牙、方向对。KDD#10 合规(hold 重放同一批字节,仅走既有 remapIndexInEvent 索引重映射;thinking 文本+签名逐字不变)。round 1 与不签名中转不受影响。
  • 标签已打:bug / claude-code / scope/wiring / p2。
  • CI:head 61a09db2 = 23 成功 / 16 skipped(受门控 e2e)/ 1 失败 = unused-exports,是本 PR 引入的——ParseStreamOpts(src/loop/core.ts:342) 只在 core.ts 内按名引用。修法一行:在 scripts/check-unused-exports.mjs 的 WAIVERS 加 ["src/loop/core.ts", new Set(["ParseStreamOpts"])](不要去掉 export,会破坏 tsc 声明产出)。上一条已贴精确片段。
  • 卡点:我对你的 fork 只有 pull、没有 push,推不进去这行。请你应用这条 WAIVER(或给我 push),补完即可进人工合并。
  • 合并判定:wire/消息形状 + KDD#10 相邻改动,按 §7.4 必须人工合并,我不代合。

等作者处理那一行后即可收工。

…ate flags it INTERNAL_ONLY

Adapters receive the opts object contextually through
CompressLoopAdapter.parseStream; no module imports the name, so the
export adds API surface the gate (ranxianglei#1440) rejects. Type-only change,
zero behavior impact. (CI fix for ranxianglei#4681)
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 —— open/closed issue 与近期 PR 中均无针对本 CI 失败(unused-exports)的既有条目;这是 PR #4681 自身工作的直接续作,不另立项。

CI 自动修复(第 1 次尝试)已完成并推送:f87e96a72(PR 分支 fix/round2-thinking-hold),新 CI 已触发。

结构化八问

  1. 是什么问题:PR 的 unused-exports 检查红——新增导出的 src/loop/core.ts: ParseStreamOpts 没有任何文件引用它,被门禁判为 INTERNAL_ONLY。
  2. 什么原因导致的:该类型只在 core.ts 内部被引用——adapter 通过 CompressLoopAdapter.parseStream(upstream, round, opts?) 的签名以上下文类型推导拿到它,从不 import 这个类型名。导出是多余的 API 面。
  3. 影响范围与严重程度:仅影响本 PR 的 CI 门禁;纯类型层改动,运行时零字节变化,对用户无任何影响。
  4. 怎么修复的:按门禁对 INTERNAL_ONLY 的标准处置,删掉 ParseStreamOpts 声明前的 export(类型名、JSDoc、结构全部保留)。一行改动,无豁免条目、无其他文件变更。
  5. 是否有回归问题:无。改动不触及任何运行时行为(thinking-hold 逻辑原样未动);已本地跑通 node scripts/check-unused-exports.mjs(gate clean),并全仓 grep 确认 src/tests/scripts 无任何跨文件引用该类型名,删除 export 不存在编译风险。全量测试以推送后远端 CI 为准。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

判定:CI 修复为单行类型可见性调整,不改变 PR 的任何行为;待新 head 的 CI 全绿后即可进入正常 review。

@Maziar123

Maziar123 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged master bcbd1a3d into the branch (new head a220df9c, no conflicts). The branch's only kernel/ change was a lockfile version line, and that diff is gone after the merge: against master the PR now touches 4 files (CHANGELOG.md, src/loop/adapter-anthropic.ts, src/loop/core.ts, tests/anthropic-round2-thinking-hold.test.ts), nothing under kernel/ and no lockfile, so kernel-guard should pass without a declaration.

On the merged head:

  • npm run typecheck: exit 0
  • node scripts/check-unused-exports.mjs: clean (6 waived, none added)
  • node --import tsx --test over anthropic-round2-thinking-hold, anthropic-truncation-unsigned-thinking, anthropic-round2-stream, anthropic-thinking-replay, fold-round2-shape, issue2499-anthropic-round2-cache: 18/18 pass

Description updated per the review: the drafting line is removed, and the two-thinking-block edge case is listed under Risk.

On #4712: as noted in its thread, it fixes the same #4679 path. Happy for whichever lands to close the other.

@Maziar123
Maziar123 force-pushed the fix/round2-thinking-hold branch from e428e46 to a220df9 Compare October 27, 2026 15:43
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

合并后的新 head a220df9c 已独立核验完毕,全部通过:

  • 我先前推的 CI 修复(f87e96a72,去掉 ParseStreamOpts 多余 export)在你的 merge 里完整保留,unused-exports 在新 head 上重新变绿。
  • 对 merge-base bcbd1a3d 的 diff 确认就是你说的 4 个文件(CHANGELOG.md、src/loop/adapter-anthropic.ts、src/loop/core.ts、tests/anthropic-round2-thinking-hold.test.ts),无 kernel/、无 lockfile/版本行——kernel-guard 无需声明即通过,与你的判断一致。
  • 新 head 全量 CI:51 项检查,37 通过 / 14 skipped / 0 失败,全部 test lane 绿。之前那个 fork 基线陈旧导致的版本行漂移也随这次同步 master 一并消除了。
  • 结论:[PR] fix(loop): hold a bili-owned round's thinking until its signature, so a cut inside round ≥2 stays re-fetchable #4681 当前状态可以进入正常 review/合并流程。

关于 #4712 与 #4681 的去重(两者都修 #4679、同为「签名到达前压住 round≥2 thinking」方案):保留哪个、关闭哪个由 owner 决定(按政策 agent 不关闭任何 PR/issue)。供决策的现状快照:

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b) Merge-guard sync done: merged origin/master (9b6ec234) into fix/round2-thinking-hold — clean, no conflicts; pushed new head c3afbe7c, which now fully contains master, so the "behind" flag is resolved by construction (fresh CI runs on the new head).

@Maziar123

Copy link
Copy Markdown
Contributor Author

Merged master b08fbf36 (new head bbd6b4d0). The only conflict was CHANGELOG.md [Unreleased] → Fixed, where #4984 added its I3 line in the same spot; both entries are kept. Against master the PR still touches the same 4 files, none under kernel/. Local checks on the new head: tsc --noEmit 0 errors, tests/anthropic-round2-thinking-hold.test.ts 4/4.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b) Verified independently against the live tree: master tip is b08fbf36, the branch now fully contains it (no longer behind), the CHANGELOG [Unreleased] → Fixed union kept both entries (your round≥2-thinking line + the #4862/#4984 I3 pairing-invariant line), and nothing under kernel/ is touched. One delta from your note: after your bbd6b4d0 head, an origin/ci-fixes merge landed bringing #4982's LIVE_FILES registration (scripts/live-files.mjs), so the actual head is now 4a4c59ceb and the net diff vs master is 5 files — the fifth is that CI-sentinel change, not PR scope. My earlier sync c3afbe7c is still in the ancestry, so nothing was dropped. Merge state is clean; fresh CI runs on 4a4c59ceb.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Synced origin/master (tip 58e61a3d) into the branch and resolved the single conflict — CHANGELOG.md under [Unreleased] → Fixed, where both sides had added a top bullet; kept both entries (#4681 round≥2-thinking-hold + #4392/#4986 shadow-digest-drift), no other file conflicted, nothing under kernel/. Pushed new head 744e385dc: the conflict is cleared (merge state no longer dirty) and CI is running on the new head (0 failed / 16 pending).

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Verdict: APPROVE. Correct root-cause fix, real regression teeth, clean scope, behavior change disclosed. No kernel/ changes, no kernel-change declaration.

Independently verified (re-derived from the diff, not taken from the PR text)

  1. Mechanism, end-to-end. Round ≥2 thinking payload deltas are buffered server-side (heldThinkingDeltas, per-parse) only when evidence says this upstream signs — signed thinking in the client's history OR a signature already seen this turn (src/loop/core.ts:873). At signature_delta the held start plus the concatenated remapped deltas flush as one burst; if the block closes WITHOUT a signature the whole block is discarded — the client saw zero bytes of it, and the withheld text stays out of replays because rebuild drops unsigned reasoning segments for signing protocols (src/loop/core.ts:1363-1370).
  2. The heal path really fires post-fix. A held block leaves unsignedThinkingOnWire net-false (set + clear happen atomically at signature time), so the #2501 gate no longer bars recovery, and the dead attempt forwarded zero visible bytes — exactly the #413 blind re-fetch precondition. A cut after a completed signed block also recovers (blind shape b) at the documented cost of re-streaming block 1.
  3. Teeth proven, not assumed. Ran the new suite against pristine master in a throwaway worktree: T1 and T4 fail there (dead round-2 attempt not re-fetched — calls expected 2, actual 1 — turn ends in error), T2/T3 pass. On the PR head everything passes.
  4. Adjacent behavior audited: round 1 byte-identical (hold requires round > 1) · relay/no-evidence lanes byte-identical (T2 pins the negative direction) · redacted_thinking never held (arrives whole in its start frame) · multiple blocks per round OK (per-index maps) · #2501 / #413 / #1455 resume semantics preserved (held-start map cleared at every parse start; dead attempt's open blocks closed by synthetic stops).
  5. Local evidence: extended suite 6/6, adjacent truncation/thinking suites 38/38, typecheck clean. CI at head a68014017: 0 failed / 0 pending (mirror check cache).

Findings (non-blocking)

  1. Duplicate PR — owner decision needed before merging either. #4712 is open with a near-identical fix for this same issue (created 2026-10-25T13:12Z vs this PR 11:08Z; the issue triage comment already cites #4712). Loop guard: one issue ≤ one PR. Agents can't close PRs — please close the later one (#4712) if this merges.
  2. Doc drift: the PR body says the evidence expression includes ctx.protocol === "anthropic" &&; the code omits the protocol check. Harmless in practice (only the anthropic adapter implements holding), but body and code should match.
  3. Pre-existing write-only lastThinkingIndex in parseStream (src/loop/adapter-anthropic.ts:373, never read — dead on master too); this PR adds one more write in the flush path (L626). Left untouched deliberately to keep the diff auto-merge-clean; optional follow-up cleanup.

Added during review (pushed to the PR branch, 4b8c4c64f)

Two regression paths the original four tests did not cover:

  • T5 (self-arm): no evidence in history or round 1 — the first round-2 block streams live, its signature arms the hold mid-parse, and a cut inside the second block must still leave zero unsigned bytes for the blind re-fetch. Fails on master.
  • T6 (Opus 5.5): start → signature_delta with no payload deltas — the held start must release on the signature alone, or the signature frame would precede its own start on strict clients.

Behavior change (re-confirming the PR's own disclosure)

OLD: on an evidenced-signing upstream, round ≥2 thinking streamed live from the first payload byte. NEW: buffered server-side, released as one burst at signature. Cost bounded by max_tokens per block; relay lanes and round 1 unchanged. Disclosed in the PR body + CHANGELOG ✓.

结构化八问

  1. 是什么问题:bili 自己发起的第 ≥2 轮请求(执行 compress 后的重发)在流式返回中途被切断时,客户端已持有未签名的 thinking 块,#2501 门禁正确地拒绝重取,回合以 error 终结且不可恢复。
  2. 什么原因导致的:第 ≥2 轮的 thinking 载荷逐帧实时转发给客户端(只有 start 帧被延迟),而签名帧永远在最后——切点落在载荷中段时,客户端落盘的就是无签名块,重取路径对这种状态按设计封死。
  3. 影响范围与严重程度:仅代理模式 + 确实会签 thinking 的 anthropic 上游 + 切断恰好发生在 bili 自发起回合(round ≥2)的 thinking 载荷内。触发面窄但后果重:该回合彻底丢失、用户可见 error(p2 定级合理)。中继/不签名上游不受影响。
  4. 怎么修复的:有签名证据时,round ≥2 的 thinking 载荷先缓冲在服务端(每个 parse 独立缓冲,死尝试的缓冲随其消失),签名帧到达时一次性重映射释放;块未签名即关闭则整块丢弃(客户端零字节),被丢文本由重建层既有规则排除、不回放。
  5. 是否回归问题:审过的既有行为——round 1 流式、中继车道、redacted thinking、多块响应、#2501/#413/#1455 语义——全部保持;唯一有意变更即上面披露项,T2 负向钉住中继不变。
  6. 是否破坏缓存:不影响前缀缓存策略;盲重取是既有恢复机制,本修复只是让它在被错误封死的场景下可用。
  7. 是否改了设计方向:没有。沿用既有 hold/release、blind re-fetch、rebuild-drop 三层机制,把 round ≥2 纳入证据门控的 hold。
  8. 是否引入了新的配置:没有。无新 env/config/CLI。

Mergeable (human merges). Please resolve the #4712 duplicate first.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

Review complete → APPROVE posted (review link).

What was done:

  • Independent verification (not taken from the PR text): mechanism re-derived end-to-end — round ≥2 thinking held server-side only with signing evidence, burst-released at signature_delta, discarded (zero client bytes) if the block closes unsigned, discarded text excluded from replays by the existing rebuild rule; heal path confirmed net-false at the [bug] anthropic 线盲重取(#413/#1455)把没签名的 thinking 块交给客户端:下一轮 400 "thinking.signature: Field required",Claude Code 随即永久剥掉全部历史 thinking #2501 gate so the 启动横幅硬编码 raw-HTTP-capture(on) 而真开关是 ACP_DUMP_BODY(默认关):日志永远撒谎,取证被带偏过 #413 blind re-fetch fires.
  • Teeth proven: ran the new suite against pristine master in a throwaway worktree — T1/T4 fail there (bug reproduced: dead round-2 attempt not re-fetched, turn ends in error), all green on the PR head. Adjacent truncation/thinking suites 38/38 + typecheck local-green; CI at head a68014017: 0 failed / 0 pending (mirror check cache).
  • No kernel/ changes, no kernel-change declaration → approval permitted; behavior change (round ≥2 thinking: live-from-first-byte → buffered burst at signature) already disclosed in PR body + CHANGELOG, re-confirmed.
  • Added during review (pushed to the PR branch as 4b8c4c64f): T5 (self-arm mid-parse) and T6 (Opus 5.5 start→signature with no payload deltas) — two regression paths the original four tests did not cover; both pass.
  • Non-blocking findings: doc drift on the protocol-check claim in the PR body; pre-existing write-only lastThinkingIndex left untouched for diff cleanliness.

⚠️ One owner action before merging: #4712 is a near-duplicate PR fixing this same issue (#4681 created ~2h earlier). One issue ≤ one PR — please close the later one; agents can't close PRs. Also flagged on #4679.

Verdict: mergeable (human merges), after resolving the #4712 duplicate.

@Maziar123

Maziar123 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Restored the two missing regression cases in 13422a97:

  • T5: a signature encountered mid-parse arms the hold for later thinking blocks in the same response.
  • T6: a thinking start followed directly by signature_delta releases the held start without requiring payload deltas.

Verification on the previous PR head plus this test-only commit:

  • tests/anthropic-round2-thinking-hold.test.ts: 6/6 passed.
  • npm run typecheck: passed.

This push triggers a fresh CI matrix; the earlier cancelled matrix is not being treated as a green run.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

Confirmed and verified against the new head 13422a97:

  • No duplication: 13422a97 is byte-identical (full-tree diff empty) to the test-only commit this review pushed earlier as 4b8c4c64f before being superseded — so the branch carries exactly ONE clean addition of T5/T6, not two copies. T5 (mid-parse self-arm) and T6 (start → signature_delta with no payload deltas) match what the review asked for.
  • Independent re-run at the new head: 6/6 pass in a fully isolated checkout (own deps + kernel/pi-subagents builds). Note: a local run mid-check initially failed with ERR_MODULE_NOT_FOUND — that was shared-workspace interference (concurrent session reshuffled the shared node_modules), not a code issue; the isolated run rules that out.
  • CI: mirror check cache at head 13422a97 shows 0 failed / 12 pending — running, and agreed, not counted as green until the matrix completes.
  • APPROVE stands for the new head: test-only delta over the already-reviewed base, no behavior change introduced by the test commit itself.

Reminder before merge: #4712 remains a near-duplicate PR for the same issue (#4679) — owner needs to close one of them (agents can't close PRs).

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

Labels

Projects

None yet

2 participants