Repository navigation
[PR] EN | kernel: relocate misplaced tool-delta systems instead of demoting them (fixes #4818) - #5800
ranxianglei wants to merge 3 commits into
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.10981-pr.5800.5c8e521This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5800.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重结论:不重复。open PR 里只有本 PR(#5800)在修 #4818;同族的 #4715 修的是相邻的 #4570(follow-side heal,不同半区),master 已在其基础上落了 #5438 实现,本 PR 是构建其上而非重复;#5031(move vs demote 决策)已关闭,本 PR 按 2026-11-02 拍板落地 delta-carrier 子集的重定位。同症状(系统位置 heal 触发 400)但机制/位置不同,判为同族不同半区,非重复。 标签: 审核状态(进行中):这是 owner 的内核 PR,我按 kernel-change 高审档独立过一遍(不复读 issue 结论)。已确认——
正在收尾:核对被改的旧 pin 是否只是「strip→relocate」行为变更而非削弱断言、确认 一个合并顺序提示:正文自述 open PR #5777 也把 acp-kernel bump 到 0.0.183——若 #5777 先合,本分支需 rebase 到 0.0.184,否则 release 门禁会因版本冲突而红。 |
(ai: vllm-qwen/qwen3.8-27b) PR #5800 审核结论 — 结构化八问(独立审,不复读 issue 侧)
测试有效性:新测试 CI / verif:head 两个合并顺序提示(非代码缺陷):① open PR #5777 也把 acp-kernel bump 到 0.0.183——若它先合,本分支需 rebase 到 0.0.184,否则 release 门禁会因版本冲突而红。② 同族 #4715(follow-side,#4570)与本 PR 不同半区、master 已在其上落 #5438,二者不冲突,可各自推进。 非阻塞小观察(备查):settle 槽位搜索用「紧邻前驱 判定:可合(approve) — 代码正确、测试有牙、Kernel Boundary 合规、CI 全绿。剩两项人工动作:owner 内核人审批准(human-only 档)+ 视 #5777 合入顺序决定是否 rebase 到 0.0.184。PR 合并 human-only,我不代合。 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Findings-only review — 不 approve(触及 kernel/ + 带 kernel-change 声明,转需 owner 授权,见下方 🔶 评论)。
结构化八问
-
是什么问题:#4818 — Anthropic 中会话工具变更(tool delta)链被位置修复逻辑拆断。当携带
tool_addition/tool_removal的 system 落在非法位置时,旧逻辑就地 demote 并按 WC-022 剥掉它的工具块,但同一链条上更靠后、位置合法的tool_removal被原样保留 → 孤儿 removal 引用不存在的工具 → Anthropic 硬 400tool_reference_unresolved,会话整体死亡(模型回复也丢)。另一变体:addition-only 载体被静默剪掉 → deferred-load 工具永久失效,无报错无日志(@BBleae 现场报告)。 -
什么原因导致的:
healIllegalSystemPositions(kernel/src/wire/anthropic.ts)对每个 mid-history system 独立判位置合法性并独立处置。tool delta 是一条有序链(add→remove→add),控制生效工具集;独立降级会拆链——剥掉一个 addition 就让它后面的 removal 悬空。根因在 kernel 出站渲染层(coreToAnthropic),是唯一能看到最终 wire 布局的层,host 侧修不了(PR 声明成立)。 -
影响范围与严重程度:p1(会话级死亡)。触发条件:Claude Code MCP connect/disconnect 抖动使 delta 落到折叠边界后的非法位置,或任何让 delta-carrier 孤立到非法位置的折叠序列。严重度:受影响会话每次请求都 400,完全不可用(Claude Code 靠丢 beta 恢复但付缓存代价;无 fallback 客户端永久卡死);addition-only 变体是静默永久工具丢失。
-
怎么修复的:给
healIllegalSystemPositions加一个 settle 预通道(settleToolDeltaPositions):只要有任何 delta-carrier 在非法位置,就把所有 carrier(保持相对顺序)一起搬到「最早的正向合法槽位」(同时满足位置规则两半、run-aware、与 demote 通道判定一致)。移动 system 不改变其它消息的合法性(system 对两半都透明),故一次搬移即收敛。仅当不存在正向合法槽位(trailing carrier 在纯 assistant 文本之后),才回退到既有 #5438 demote 路径(字节不变),并新增[acp-kernel]warn 点名每个被丢的工具。普通(非 delta)system 保持 owner 已批的 #5438 demote 语义逐字节不变;合法布局是缓存安全的 no-op。 -
是否有回归问题:逐项审过既有行为——① 普通 system 的 demote 语义:settle 只碰
carriesToolDelta && !isDirectiveOnlySystem,demote 通道新增的那行if (carriesToolDelta(e) && isLegalSystemSlot(...)) continue;也只作用于 carrier,普通 system 不受影响;② 合法 delta 布局(mid 合法位、Pi trailing run):settle 直接 return,负向 gate 测试钉住 byte-identical;③ 我手工推演了 #4818 精确 repro([user, sys(add), user, sys(rem), assistant]→[user, user, sys, sys, assistant],add<rem,链条解析)与 add/rem/add flap 序列,均收敛正确;④ 关键交互:settle 之后 demote 通道再降级的普通 system 不会破坏已搬移 carrier 的合法性——因为夹在 carrier 与其 assistant-successor 之间的 system 本身是合法的(其后继就是 assistant),不会被 demote。本地跑 6 个受影响套件全绿(46 kernel 用例 + 5 root 用例,root 需先npm --prefix kernel build出 dist,否则 importacp-kernel/wire报 ERR_MODULE_NOT_FOUND,属环境非代码问题);CI 30 checks 0 fail 0 pending。发现一处非阻塞缺陷(见下)。 -
是否破坏缓存:合法布局 no-op(零搬移零重分配);非法布局才搬移且只改 delta-carrier 的位置不改内容——这是有意行为变更(见 PR 披露 old→new),不引入超出既有 demote 路径范围的额外缓存扰动。
-
是否改了设计方向:未转向架构。在既有 #5438/#4457 位置修复框架内新增「delta-carrier 优先 relocate」预通道,demote 保留为最后手段。符合 owner 在 #4818 拍板的方向(relocate 优先于 consistency-pass)。
-
是否引入了新的配置:无新 env/config/默认值。纯 kernel 内部行为。
非阻塞缺陷(建议合并前修)
kernel/src/wire/anthropic.ts:481-490(fallback warn 点名逻辑)对真实 wire 形状的 tool_removal 失效。 fallback warn 的设计目的(@BBleae 明确诉求)是让「被丢工具可诊断」。但 removal 分支只读 b.tool_reference ?? b.tool_name(合成测试用的扁平字段),没读真实生产形状 b.tool.name(issue #4818 repro:{type:"tool_removal", tool:{type:"tool_reference", name:T}})。我用构建后的内核实测三种形状走 fallback warn 路径:
| removal 形状 | warn 输出 |
|---|---|
真实 nested {tool:{type:tool_reference,name}} |
unknown ❌ |
扁平 {tool_reference:name} |
正确打印工具名 ✓ |
扁平 {tool_name:name} |
正确打印工具名 ✓ |
而 addition 分支读 b.tool.definition.name ?? b.name,两种形状都覆盖——不对称。新测试的 removal helper(kernel/tests/issue4818-tool-delta-relocation.test.ts:37)恰好用扁平 tool_reference(与 buggy 读法自洽),所以测不出来;且 warn 路径的用例(test 3/4)只喂了 addition。修法(几行):removal 分支补 ?? (b.tool as {name?:string})?.name,并加一条「真实 nested removal 走 fallback warn 且 warn 点名 T」的用例。因属 kernel/,按授权边界我不代改,列此供 author/owner 决定(建议并入本 PR 一起合)。
协调提示(非缺陷)
PR 正文已声明:in-flight #5777 也把 acp-kernel bump 到 0.0.183;若 #5777 先合,本分支需 rebase 到 0.0.184(本 PR 当前 bump 到 0.0.183)。合并时序注意即可。
结论:核心 relocate 逻辑正确、测试有牙、回归审过、合法布局缓存安全;唯一实质问题是 fallback warn 对真实 removal 形状打 unknown(非阻塞但削弱该特性诊断价值,建议合并前补)。因触及 kernel/ + 带 kernel-change 声明,按授权边界不 approve。
🔶 需要决策 本 PR 触及 kernel/(
请拍板:A 授权合入(建议先补 warn-name 那处再合)/ B 要求 author 补 warn-name + 测试后重新 review。 |
[bot] 🏷 PR #5800(#4818 kernel tool-delta relocate 修复)review 完成 —— findings-only,未 approve,已转 🔶 需要决策。 因触及 kernel/( 审核结论:核心 relocate 逻辑正确——#4818 精确 repro 手工推演通过(add/rem 链保序、每个 removal 都能解析到更早的 live addition),settle→demote 交互安全(夹在 carrier 与 assistant-successor 之间的普通 system 本身合法、不会被 demote)。6 个受影响套件本地全绿;CI 30 checks 0 fail 0 pending(读镜像缓存,非 gh 轮询)。合法布局 no-op 缓存安全;version bump 0.0.182→0.0.183 合规;console.warn 符合 kernel 既有惯例。 一处非阻塞缺陷(已实测复现,未代改——属 kernel/):fallback warn 点名逻辑对真实 wire 形状的 协调提示:in-flight #5777 同 bump 0.0.183,若先合本分支 rebase 到 0.0.184。 已做:① findings-only review(COMMENT,含八问+finding)已发;② 🔶 需要决策 授权请求评论已发(选项 A/B);③ |
|
有问题改 |
[bot] 🏷 已按「有问题改」处理。已顺手修:fallback warn 对真实 nested 验证:kernel typecheck 干净;6 个受影响套件本地 52/52 绿(含新用例,旧代码下会因 至此唯一实质 finding 已闭环,PR 现仅剩 owner 人工合并(kernel 变更恒需人审)。 |
c9f323b to
4be887d
Compare
(ai: vllm-qwen/qwen3.8-27b) Merge conflict resolved on PR #5800 ( What I found & did this run:
结构化八问
判定:冲突已解决并通过定向验证,PR 现处可合并状态( |
(ai: vllm-qwen/qwen3.8-27b) Red CI fixed and verified green — PR #5800 is now conflict-free, all checks passing, awaiting human approval. What happened this run (verified live, nothing asserted from memory):
Behavioral-expectation note (flagged per policy): this commit changes test expectations only, not runtime behavior. The relocate-vs-demote behavior change was already made and disclosed by the PR author (old: revoice tool-delta carriers as 中文八问(结构化结论):
收工判定:可交付人工审核。 冲突已在上一轮解决,本轮红 CI 已修复并实测转绿;PR 现无冲突、CI 全绿,仅剩 kernel PR 必需的人工审批这一关(我无权也不应代批)。 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
复审(rebase 后新 head a9a92a02f)
分支已 rebase 到更新的 master,本 PR 三笔提交:
7db7552307kernel: relocate misplaced tool-delta systems instead of demoting them (#4818) —— 核心改动,与我首轮审核内容一致,rebase 未改语义。4be887dd17kernel: name real nested tool_removal shape in heal-fallback warn (#4818) —— 我上轮顺手修的 warn 取名缺陷,rebase 后原样保留(kernel/src/wire/anthropic.ts:485-491先读b.tool.name,再落扁平 fallback)。a9a92a02fckernel: align #4570 final-wire test pins …… —— 本轮新增:纯测试。原 PR 把 demote-strip 改成 relocate 时漏更了issue4570-system-position-final-wire.test.ts里两处仍断言旧 WC-022 行为的 pin,此提交把它们对齐到新行为。
对新增提交 a9a92a02fc 的核查(逐条对照 settle 算法):
- 尾部 carrier
[user, sys(text+add), …, user]→ 重定位到数组末尾、仍是 system、tool_addition保留、texts=["q","nudge","tools updated"]、violations=[]。✓ - assistant 后 carrier
[user, assistant(tool_use), sys(text+add), user(tool_result), assistant]→ 重定位到 index 3(tool_result 之后、收尾 assistant 之前),sent[2]=user、sent[3]=system、delta 保留。✓ - 两处新断言有牙:旧(demote-strip)行为下会红,旧断言恰恰是只有旧行为才过的形状。纯测试、无 src 改动、无需再 bump 版本(累计 PR 已带 0.0.182→0.0.183 + src 变更,version-guard 走
master...HEAD通过)。
CI:镜像缓存 30 checks,0 failed / 0 pending(16 success + 14 skipped)——绿。PR body 仍带 kernel-change: 声明 + Fixes #4818。
八问
- 是什么问题:#4818——anthropic 线 mid-history system heal 逐个独立判定,非法位的 tool-delta carrier 被降级为 user 且剥掉 tool block(WC-022),而后面合法位的同名 tool_removal 原样保留 → 孤儿 removal → 硬 400
tool_reference_unresolved,会话死亡并丢模型回复;另有静默变体(只剥 addition 不报错,工具永久失效)。 - 什么原因导致的:heal 对每个 system 独立判定 + 「降级即剥离」,破坏了「addition/removal 成链」这一不变量——链的一端被删、另一端留下。
- 影响范围与严重程度:claude-code / anthropic 线;触发条件 = mid-history 出现带 tool delta 的 system 且其位置非法。严重度 p1(会话不可用 + 丢模型回复)。
- 怎么修复的:
healIllegalSystemPositions加 settle 预遍settleToolDeltaPositions——只要有一个 delta carrier 在非法位,就把全部 carrier(保持相对序)搬到最早的前向合法槽;搬 system 不改变其它消息的合法性(system 对前后两半都透明)→ 一遍收敛。无前置合法槽(carrier 落在纯 assistant 文本之后)才回退到既有 #5438 demote(不变)+ 新增 warn 点名被丢工具。普通 system 仍按 #5438 逐字节降级;合法布局 = cache-safe no-op。 - 是否有回归问题:审过的既有行为——①普通(非 delta)system 的 #5438 降级路径逐字节不变;②合法 delta 布局 no-op(cache-safe);③无槽位时回退旧 demote 语义(含 warn)。高危模式逐项:语义漂移——delta carrier 由「剥」变「搬」是本 PR 有意变更,已披露 旧值=demote+strip → 新值=relocate verbatim;fail-fast 变吞错——无;阈值/时序/输出格式——无。
- 是否破坏缓存:合法布局下 relocate 是 no-op(不碰已合法消息)→ 前缀缓存稳定;仅非法布局才移动 carrier,而那正是必须修的场景。不破坏缓存。
- 是否改了设计方向:否。仍在
healIllegalSystemPositions内做位置修正,未动架构/边界/数据流;只是把同一决策点的「降级剥离」换成「重定位保链」。 - 是否引入新的配置:否。无 env/config/默认值变更。
结论:代码与测试均干净、完整,CI 绿;核心算法正确、warn 取名缺陷已补、遗漏的 #4570 pin 已对齐。但本 PR 触碰 kernel/ 且携带 kernel-change: 声明——按 HARD RULE 我无法 approve,合并须走人工 tier(owner 裁定)。除此之外无阻塞项。
🔶 需要决策 复审后仍需 owner 授权合并(rebase 到新 head 本 PR 触碰
被门禁的 diff: 请 owner 裁定合并(或指出需调整处)。完整八问见 Reviews 区本轮 review。 |
[bot] 🏷 复审完成(新 head 本轮相比上轮的变化是分支 rebase 到了更新的 master:
已验证:CI 镜像缓存 30 checks,0 failed / 0 pending;PR body 仍带 已落地:findings-only GitHub review(id 5853042145,含完整八问)+ 一处待办说明:规则要求「在协调 issue 报一行」,但现有工具查不到 review-lane 协调 issue(镜像 shim 不列 issue,全文检索无果)——为避免误报到无关线程,先在此标记该缺口;若你给协调 issue 编号,我补一行过去。 |
(ai: vllm-qwen/qwen3.8-27b) Re-verified live before doing anything — no work needed this wake.
Everything is already green; the reported blockers were on the pre-fix commit. Stopping without further changes. 中文:已实测当前头 |
(ai: vllm-qwen/qwen3.8-27b) Re-verified live this run — still fully green, no work needed. (This is the third identical wake on an already-fixed commit.)
Bottom line: the only remaining step is the human-only kernel approval. Further auto-wakes keyed to the old commit are expected noise until the PR is merged/closed. 中文:本轮已实测当前头 |
a9a92a0 to
ff95b5a
Compare
|
结论:这个分支( 我用自己报告里那种「只追加」(append-only)的形状核了这个分支:宿主只会发 每个用例都过一遍 master 这个分支 要留意的一点:(3) 和 (5) 里,载体(带 heal.mts// usage: KSRC=<file URL of kernel/src> node --import tsx heal.mts
const { coreToAnthropic } = await import(`${process.env.KSRC}/wire/anthropic.ts`);
const T = "late_tool";
const add = { type: "tool_addition", tool: { type: "tool_definition", definition: { name: T, description: "d", input_schema: { type: "object", properties: {} } } } };
const rem = { type: "tool_removal", tool: { type: "tool_reference", name: T } };
const U = (id: string, text: string) => ({ id, role: "user", contentType: "text", text });
const A = (id: string, text: string) => ({ id, role: "assistant", contentType: "text", text });
const S = (id: string, content: any[]) => ({ id, role: "system", contentType: "text", text: "", rawAnthropicMessage: { role: "system", content } });
const show = (label: string, msgs: any[]) => {
const warns: string[] = [];
const w = console.warn; console.warn = (...a: any[]) => { warns.push(a.join(" ")); };
let out: any[];
try { out = coreToAnthropic(msgs as any); } finally { console.warn = w; }
const row = out.map((m: any) => m.role[0].toUpperCase() + (Array.isArray(m.content) ? "[" + m.content.map((b: any) => b.type.replace("tool_", "")).join("+") + "]" : "")).join(" ");
const j = JSON.stringify(out);
console.log(`${label}\n out: ${row}\n addition kept: ${j.includes("tool_addition")}${JSON.stringify(msgs).includes("tool_removal") ? `, removal kept: ${j.includes("tool_removal")}` : ""}${warns.length ? `\n warn: ${warns.join(" | ").slice(0, 200)}` : ""}`);
};
show("(1) summary, S[add], summary, A, U (append-only host, fold boundary right after the carrier)",
[U("u0", "summary 1"), S("s1", [add]), U("u2", "summary 2"), A("a3", "ok"), U("u4", "use it")]);
show("(2) summary, S[text+add], summary, S[text+rem], A (the #4818 chain)",
[U("u0", "summary 1"), S("s1", [{ type: "text", text: "now available" }, add]), U("u2", "summary 2"), S("s3", [{ type: "text", text: "gone" }, rem]), A("a4", "ok")]);
show("(3) summary, S[add], summary, U (no assistant after the carrier; live user turn is last)",
[U("u0", "summary 1"), S("s1", [add]), U("u2", "summary 2"), U("u3", "now use the tool")]);
show("(4) summary, S[add], summary, U, A(tool_use), tool_result (tail is an open tool round)",
[U("u0", "summary 1"), S("s1", [add]), U("u2", "summary 2"), U("u3", "question"),
{ id: "a4", role: "assistant", contentType: "tool-call", toolCallId: "t1", toolName: "other_tool", text: "{}" },
{ id: "r5", role: "tool", contentType: "tool-result", toolCallId: "t1", toolName: "other_tool", text: "ok" }]);
show("(5) U, A, S[add], A, U (carrier between two assistant messages)",
[U("u0", "q"), A("a1", "a"), S("s2", [add]), A("a3", "b"), U("u4", "go")]);在仓库根目录跑, |
(ai: vllm-qwen/qwen3.8-27b) Thanks for the careful field test — I traced all five shapes through Array end is an explicitly allowed position, not a heuristic. The contract is documented verbatim at Your (3)/(5) satisfy the follow half too. In both, the relocated carrier lands right after a user message, which It's not a new or untested position. Array-end systems are pinned as legal across the suite:
Honest residual: the test |
[bot] 🏷 Status update (process was force-restarted after a 34-min stall): The review of @BBleae's field report on PR #5800 is complete — my full reply is already in the thread above (addressing the (3)/(5) array-end placement concern). No defect found:
The stall was a hung wait after posting that reply — no pending tool call, no blocked dependency, nothing lost; the analysis and reply are intact in the thread. Avoiding the trigger: I'm not re-running any checks. PR status: remains pending owner human approval (kernel changes are human-only tier). I did not approve or merge. Workspace restored to |
ff95b5a to
c4de64a
Compare
(ai: vllm-qwen/qwen3.8-27b) Merge conflict resolved on PR #5800 ( What I did this run (all verified live, nothing from memory):
No PR-body edits, no new issues, no design decisions needed — this was a pure mechanical conflict resolution. 结构化八问
判定:冲突已解决(dirty → blocked),定向验证全绿,CI 在新 head |
(ai: vllm-qwen/qwen3.8-27b) Findings-only review — kernel PR, cannot approve per HARD RULE (merge waits on owner human tier). Verdict: code correct, tests comprehensive, no blocking findings. Routed to owner for kernel approval. 1. Correctness (PASS). 2. Tests (PASS). New 3. Risks. Behavior change (disclosed in PR body): illegal-position tool-delta carriers old=revoice user+strip, new=relocate verbatim (demote only when no slot + warn). No security risk. No data-loss risk — the fix PREVENTS silent tool loss. 4. House conventions (PASS). Kernel Boundary: version 0.0.197→0.0.198 ✓, Non-blocking observation (safe, first noted floor 5): the settle slot search uses the immediate predecessor No small mechanical findings to fix. Code clean, tests comprehensive, comments accurate. Gated diff (owner approval): |
🔶 需要决策 PR #5800 (kernel) requires owner authorization for merge. The PR touches Gated diff: My review verdict (findings-only, above): code correct, tests comprehensive, no blocking findings. The fix resolves #4818 (tool-delta chains split by demote-strip → hard 400 Request: please review and approve (or request changes) at your discretion. The human-only kernel review tier is the required gate. |
c4de64a to
6e96e24
Compare
(ai: vllm-qwen/qwen3.8-27b) Merge conflict resolved (second occurrence) on PR #5800 ( What I did this run (all verified live in this run):
Honest status note: the mirror cache stopped refreshing ~13 minutes ago (last fetch still shows the shards in flight), so I could not verify full CI completion this run — I'm not asserting green. The conflict itself is resolved and verified; if any shard goes red, the auto-fix lane will pick it up on the next wake. No PR-body edits, no new issues, no design decisions needed — pure mechanical conflict resolution again. 结构化八问
判定:冲突已解决(dirty → blocked,实测确认),定向验证全绿,已强推最终 head |
(ai: vllm-qwen/qwen3.8-27b) Re-review (head advanced c4de64a → 6e96e24): PR rebased onto a newer master, code unchanged. The PR was rebased onto a newer master (
My previous review verdict stands (findings-only, above): code correct, tests comprehensive, no blocking findings. The single non-blocking observation (conservative slot search — safe, never produces an illegal layout) is unchanged. Still routed to owner for kernel approval (HARD RULE — kernel PR, human-only tier). The 🔶 需要决策 comment and |
) The fallback diagnostic read removals as flat tool_reference/tool_name only, printing 'unknown' for the production Claude Code shape {tool:{type:tool_reference,name}}. Read b.tool.name first (mirrors the addition branch), keep the flat fallbacks for synthetic test shapes. Adds a regression pin driving the real nested removal through the no-slot warn path.
…demote behavior issue4570-system-position-final-wire.test.ts still asserted the old demote+strip-on-demotion behavior (WC-022) for tool-delta carriers. The #4818 change relocates those carriers verbatim instead of stripping them, so two subtests now pin the relocated output: deltas preserved, layout legal. This completes the set of stale pins the PR already updated in issue4457-sidecar-system-folds / issue4292-orphan-system-guard / issue5432-follow-side-heal / anthropic-system-message-passthrough / root tests/issue4292-anthropic-fold-orphan-system. Test-only; no kernel/src change, no version bump.
6e96e24 to
329b263
Compare
(ai: vllm-qwen/qwen3.8-27b) Conflict rebase run 3 — done. This time it was a real code conflict, not just version lines. What I did this run:
结构化八问
判定:冲突已解决并推送( |
(ai: vllm-qwen/qwen3.8-27b) Re-review (head advanced 6e96e24 → 329b263): PR rebased again, code functionally unchanged. The PR was rebased onto a newer master (
My previous review verdict stands (findings-only, above): code correct, tests comprehensive, no blocking findings. The single non-blocking observation (conservative slot search — safe, never produces an illegal layout) is unchanged. Still routed to owner for kernel approval (HARD RULE — kernel PR, human-only tier). The 🔶 需要决策 comment and |
[bot] 🏷 Status update: The re-review of PR #5800 (head advanced 6e96e24 → 329b263) is complete — my full re-review reply is already in the thread above (floor 69). Summary:
Verdict stands (findings-only): code correct, tests comprehensive, no blocking findings. Still routed to owner for kernel approval (HARD RULE — kernel PR, human-only tier). The 🔶 需要决策 comment and |
Fixes #4818
kernel-change: healIllegalSystemPositions must stop splitting tool-delta chains — demote-strip orphans paired tool_removal blocks (hard 400
tool_reference_unresolved, session death) and silently drops addition-only carriers (permanent tool loss); the host side cannot fix this because the decision lives in the kernel's outbound render pass (coreToAnthropic), the only layer that sees the final wire layout.What
The position-based backstop (#4457 precede-side, #5438 follow-side) healed each illegal system independently by demoting in place: re-voice to user, strip
tool_addition/tool_removalblocks (WC-022), drop when nothing remains. Tool deltas form an ORDERED CHAIN (add → remove → add …) that controls the effective tool set under Anthropic's mid-conversation-tool-changes contract, so stripping one link breaks its neighbours:tool_additionbut keeps the latertool_removalfor the same tool → 400tool_reference_unresolved#4818 (Claude Code MCP connect/disconnect flapping): a strippedtool_additionplus a later verbatimtool_removalfor the same tool → 400tool_reference_unresolvedon every subsequent request; the model reply was lost as well.Fix
healIllegalSystemPositionsgains a settle pre-pass (settleToolDeltaPositions): when any system carrying tool deltas sits in an illegal position, ALL such carriers are moved together (original relative order preserved) to the earliest forward slot that is legal under BOTH halves of the position rule (run-aware, mirroring the demote pass exactly). Moving systems never changes any other message's legality verdict (systems are transparent to both halves), so one pass suffices. When no forward slot exists (e.g. a trailing carrier behind plain assistant text — the Maziar123 example-2 shape where both options demote anyway), the carriers fall back to the existing #5438 demote path UNCHANGED — and now emit a[acp-kernel]warn naming every dropped tool, making silent tool loss diagnosable.Plain systems keep the owner-approved #5438 demote semantics byte-for-byte. Legal layouts (assistant next, array end, directive-only anywhere) are a cache-safe no-op: the settle pass returns without touching the array.
Behavior change disclosure (old → new)
For systems carrying
tool_addition/tool_removalblocks in an ILLEGAL position only:Why: availability (#3128) — the old path hard-400'd sessions (orphaned removal) or silently removed tools (addition-only drop). Relocation preserves the exact chain order the contract requires.
Related
tool_additionbut keeps the latertool_removalfor the same tool → 400tool_reference_unresolved#4818 (this fix) · [Bug][anthropic] 0.1.206: system 400 still fires on nudge turns: the heal keeps a trailing system, then prepare-anthropic appends user notes after it #4570 (same family, reporter's dist/-side workaround) · [PR] kernel: heal system positions on the final Anthropic wire array (#4570) #4715 (open two-half heal PR — overlaps on the follow-side half; master shipped its own follow-side implementation in ca532d4/f06619ffc for kernel authorization request: heal must enforce the FOLLOW side of Anthropic's mid-conversation system position rule (#5432) #5438, which this PR builds on rather than duplicates)Tests
kernel/tests/issue4818-tool-delta-relocation.test.ts— exact [Bug][anthropic][claude-code] 0.1.208: the system-position heal drops atool_additionbut keeps the latertool_removalfor the same tool → 400tool_reference_unresolved#4818 repro, add/remove/add flap across folds with a chain-resolution oracle (every removal must reference a live earlier addition), fallback-warn shapes, legal-layout byte-identity negatives (gate discipline Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617).issue4457-sidecar-system-folds,issue4292-orphan-system-guard(incl. the silent-loss shape @BBleae reported),issue5432-follow-side-heal,anthropic-system-message-passthrough, roottests/issue4292-anthropic-fold-orphan-system.coreToAnthropic(incl.verif-wire-anthropic-roundtrip, which SMT-translates the modified function); typecheck clean on both layers.