Skip to content

[PR] fix(kernel): heal pass keeps a thinking block out of the final assistant block - #7332

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-20_fix-server-tool-heal-thinking-final
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-20_fix-server-tool-heal-thinking-final

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

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:

  • orphaned *_tool_result after a thinking block → [thinking, placeholder]
  • orphaned server_tool_use after a thinking block (non-last message) → [thinking, placeholder]
  • orphaned *_tool_result after a redacted_thinking block → [redacted_thinking, placeholder]
  • (negative) thinking + a COMPLETE server-tool pair round-trips byte-identical (no churn)

All 9 tests in the file pass; full kernel suite green (1649 pass / 0 fail); kernel typecheck clean. kernel/src/wire/anthropic.ts is 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).

…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.
@ranxianglei ranxianglei changed the title fix(kernel): heal pass keeps a thinking block out of the final assistant block [PR] fix(kernel): heal pass keeps a thinking block out of the final assistant block Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-20_fix-server-tool-heal-thinking-final (bc72fdc)

Latest build — install this exact version

npm install -g billion-context@0.0.11020-pr.7332.c6c19b7

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
bc72fdc billion-context@0.0.11020-pr.7332.c6c19b7 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7332.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(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

  • The fix in kernel/src/wire/anthropic.ts (healUnpairedServerToolBlocks) appends the SERVER_TOOL_FOLDED_PLACEHOLDER text block when the heal drops a block and the last surviving block is a thinking-family block. The thinking block's bytes/signature are untouched (KDD release v0.1.3 #10) — only a sibling text block is added after it.
  • The 3 new positive rows fail on the unfixed (master) code and pass on the fix — genuine regression tests, not tautologies. The negative row (complete pair + thinking) passes in both (no churn for legal messages).
  • Kernel version bump 0.0.200 → 0.0.201 (required for a kernel/src/** change) + root package-lock.json synced to 0.0.201.
  • CI on head bc72fdc505f: all static gates green (kernel-guard, lock-sync, version-guard, architecture-docs, pi-subagents-guard, config-surface-guard, docs-sync, …); 12 test shards still in progress, zero failures so far.

8问 (PR review)

  1. 是什么问题: healUnpairedServerToolBlocks 丢掉 server-tool 孤儿半块后,可能让 thinking 族块成为 assistant 消息的最后一块,触发 Anthropic 400("the final block in an assistant message cannot be thinking")——这是 [claude] 400 "final block in an assistant message cannot be thinking" after a compress call that follows a thinking block #5864 400 的第二个生产者(第一个 hide-pass 生产者由 [PR] fix(kernel): keep compress pair visible when its predecessor is signed thinking #5877 修)。
  2. 什么原因导致的: heal 把消息 content 重写成存活块时,只处理了"被清空"分支(补占位符保 role 交替),但没检查"最后一块是不是 thinking 族"——thinking 变末块时直接 400。两个 fold 方向都命中;result-drop 侧没有 last-message 豁免。
  3. 影响范围与严重程度: 触发条件窄——需 fold 恰好覆盖 server-tool 对的一侧、且该消息以 thinking/redacted_thinking 结尾;命中时整轮请求 400(该轮不可用),非命中无影响。特定条件下的请求失败,非全局不可用,p2 定级合理。
  4. 怎么修复的: heal 丢块后,若末块是 thinking 族,追加与"清空"分支同一个占位符文本块,使 thinking 永不成为末块;thinking 块本身字节/签名不动(KDD release v0.1.3 #10),只在其后加一个兄弟 text 块。
  5. 是否有回归问题: 无。审过该函数 5 项既有行为——合法 server-tool 交换字节一致(no churn)、plain tool_use/tool_result 不碰、孤儿 result 丢弃、孤儿 use 丢弃(非末消息)、清空消息补占位符保 role 交替——全部保持;新增行为只在"确实丢了块"且"末块是 thinking 族"时触发(负向行验证合法消息 round-trip 字节一致)。
  6. 是否破坏缓存: 不破坏。只有本来就会 400 的消息才被改写;合法消息保持同一对象引用,前缀缓存命中不受影响。
  7. 是否改了设计方向: 不涉及。单一 heal 函数内的守卫补全,不改架构/边界/数据流。
  8. 是否引入了新的配置: 不涉及。

判定: 代码正确、最小、测试是真回归测试、版本/锁同步到位、CI 静态门全绿(全量 test shard 仍在跑,暂无失败)。这是 kernel PR(human-only review tier),我不合并——ready for your review/merge。若你更想并进 #5877(option 2b)或 defer(option 2c),说一声我来调整。

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant