Repository navigation
[PR] fix(kernel): heal pass keeps a thinking block out of the final assistant block - #7332
ranxianglei wants to merge 1 commit into
Conversation
…ition healUnpairedServerToolBlocks (added by the #7270/#7271 server-tool batch) drops the orphaned half of a server-tool pair when a fold covers exactly one side. When the surviving blocks of that assistant message end in a thinking-family block (thinking / redacted_thinking), the healed message collapses to one whose FINAL block is thinking — Anthropic 400s the whole request ("the final block in an assistant message cannot be thinking"). This is the second producer of the #5864 400; the first (the hide pass leaving a compress tool_use orphaned after a signed-thinking predecessor) is fixed by PR #5877. Fix: when the heal drops a block and the last surviving block is thinking-family, append the same placeholder the emptied case already uses ("(server tool exchange folded)") so the thinking block is never final. The thinking block's bytes and signature are untouched (KDD #10); only a sibling text block is added after it. Regression: 3 positive rows (orphaned result after thinking, orphaned use after thinking, orphaned result after redacted_thinking) + 1 negative row (complete pair + thinking round-trips byte-identical) in kernel/tests/server-tool-pair-heal.test.ts.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.11020-pr.7332.c6c19b7This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7332.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) Reviewed PR #7332 (kernel heal pass: keep a thinking block out of the final assistant block position). This is an already-opened kernel PR, so I did not redo the work — I pulled the branch, read the change in context, ran the targeted test locally (including a fail-on-unfixed check), and confirmed CI. What I verified
8问 (PR review)
判定: 代码正确、最小、测试是真回归测试、版本/锁同步到位、CI 静态门全绿(全量 test shard 仍在跑,暂无失败)。这是 kernel PR(human-only review tier),我不合并——ready for your review/merge。若你更想并进 #5877(option 2b)或 defer(option 2c),说一声我来调整。 |
kernel-change: healUnpairedServerToolBlocks can leave a thinking-family block as the final block of an assistant message after dropping an orphaned server-tool half; appended the function's own emptied-case placeholder so thinking is never final. The host side cannot solve this — the heal is a kernel post-render pass (kernel/src/wire/anthropic.ts) with no host hook.
What this fixes
The second producer of the #5864 400 ("the final block in an assistant message cannot be thinking"). The first producer (the hide pass leaving a consumed compress pair orphaned after a signed-thinking predecessor) is fixed by PR #5877; this is a DISTINCT mechanism in a DIFFERENT pass, so it is a separate PR (same symptom, tracked under #5864).
Root cause
healUnpairedServerToolBlocks(added by the #7270/#7271 server-tool batch) drops the orphaned half of a server-tool pair when a fold covers exactly one side. It rewrites the message content to the surviving blocks — but it never checks whether the LAST surviving block is a thinking-family block (thinking/redacted_thinking). When it is, the healed message ends in thinking and Anthropic 400s the whole request. Both fold directions hit it; the result-drop side has no last-message exemption.Fix
When the heal drops a block and the last surviving block is thinking-family, append the same placeholder the emptied case already uses (
"(server tool exchange folded)") so the thinking block is never the final block. The thinking block's bytes and signature are untouched (KDD #10) — only a sibling text block is added after it.Regression
3 positive rows + 1 negative row in
kernel/tests/server-tool-pair-heal.test.ts:*_tool_resultafter a thinking block →[thinking, placeholder]server_tool_useafter a thinking block (non-last message) →[thinking, placeholder]*_tool_resultafter aredacted_thinkingblock →[redacted_thinking, placeholder]All 9 tests in the file pass; full kernel suite green (1649 pass / 0 fail); kernel typecheck clean.
kernel/src/wire/anthropic.tsis not in the verif guard list, so no verif-subset-guard run is required.Process note
Proceeding under the mechanical-bug exemption (owner policy 2026-11-06) + the 无决策依赖先修 policy: this is a small, provably-broken missing guard (reproduced by a failing test before the fix), and the fix mirrors the function's own existing emptied-message handling. This implements the recommended option (2a) from the kernel-authorization request thread. The human-only kernel review tier still gates the merge — this PR is ready for your review, and if you'd rather fold it into #5877 (option 2b) or defer (option 2c), say so and I'll adjust or close it.
Part of #5864 (second producer of the same 400; first producer fixed by #5877).