Skip to content

[PR] fix(kernel): heal the follow side of Anthropic's mid-conversation system rule (#5438) - #5522

Merged
ranxianglei merged 6 commits into
masterfrom
2026-11-02_anthropic-heal-follow-side
Nov 2, 2026
Merged

ranxianglei merged 6 commits into
masterfrom
2026-11-02_anthropic-heal-follow-side

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

kernel-change: heal gains the FOLLOW half of Anthropic's two-sided mid-conversation system-position rule + single-source insertBeforeTrailingSystemRun export; owner approved this exact diff as option A in #5438 on 2026-11-02 (approval recorded in issue comment), closing #5432's remaining exposure.

#5438 approved diff — the follow half of Anthropic's two-sided system-position rule

Closes the remaining exposure of #5432: healIllegalSystemPositions enforced
only ONE half of the API contract. A mid-conversation system must follow
a user message (or an assistant ending in a server tool_result) AND
precede an assistant or end the array. The precede half was healed
(#4292/#4457); the follow half sailed through the backstop and 400ed the whole
request — messages.N: role 'system' must follow a 'user' message — until the
client self-clears its mid-conversation systems. Field repro: claude-code
v2.1.316 + mid-conversation-tool-changes contract, bili v0.1.210 /
acp-kernel 0.0.175 era (#5438).

Changes (all inside kernel/, per the approved diff)

  1. healIllegalSystemPositions gains the predecessor leg. The nearest
    non-system predecessor of each non-directive system must now be a user, or
    an assistant whose last content block is tool_result; a system with no
    predecessor (array start) stays legal by existing contract. Demotion
    reuses the EXACT existing pipeline (re-voice to user, strip
    tool_addition/tool_removal per WC-022, drop when nothing remains;
    directive-only exempt anywhere and never legitimizing a neighbour).
    The single left-to-right mutating pass means an early demotion
    re-legitimizes a later run member — minimal repair, pinned by test.
  2. New export insertBeforeTrailingSystemRun(messages, additions) —
    single source of truth for inserting ephemeral tail messages BEFORE any
    trailing system run instead of after it (the append-after shape is exactly
    what 400s case-2). No trailing run → byte-identical to plain append;
    empty additions → same array reference (zero prefix-cache churn).
  3. Version bump acp-kernel 0.0.177 → 0.0.178 (+ both lockfiles).

Behaviour-change disclosure

Only requests that previously 400ed are affected: they ship healed (same
semantics users already get from the precede-half heal). Every LEGAL layout
round-trips byte-identical — negative tests pin it, so stock cache breakpoints
are untouched. No config surface change; no new surface.

Out of scope (small follow-up PR)

Host takeover: delete the interim insertBeforeTrailingSystemRun copy in
src/util.ts (#5441) and route the steady-path tail-injection sites through
the kernel export, so the rule lives in exactly one place. Deliberately NOT
here — it would collide with the open #5441 branch; do it once BOTH merge.
Then #5432 can close for good.

Tests & local verification

  • NEW kernel/tests/issue5432-follow-side-heal.test.ts (10 tests): the
    FOLD-DRIVEN field regression through the real chain (applyCompression
    covering the turns AFTER a never-fold sidecar leaves it behind an exposed
    assistant → healed, delta text survives as user content, tool_addition
    never leaks outside system), client-side case-1 shapes (trailing /
    mid-array behind assistants), verbatim guards ([user, system, assistant],
    server-tool-result terminator, directive-only exemption), the chain
    minimal-repair pin, and insertBeforeTrailingSystemRun units.
  • issue4457-sidecar-system-folds.test.ts: local orphanSystems checker
    upgraded to the two-sided rule (stronger assertion, same fixtures — still
    green). All [Bug][anthropic] fold summary rendered as user right after a mid-conversation system message → 400 "role 'system' must precede an 'assistant' message" (0.1.204, since #3992) #4292 verbatim/heal pins pass UNCHANGED.
  • Kernel: typecheck clean, suite 1553/1553 green.
  • Host: anthropic wire suites (issue4159 verbatim e2e, wire-contract,
    system-to-user, e2e-vertex-anthropic) 33/33 green; full local suite run
    shows failures ONLY in pre-existing environment-dependent categories
    (update-advisory feed, opencode/omp/pi native-host detection, opencode-v2
    setup) — verified byte-identical failure set against a pristine-master
    baseline (same 5 files, same fail counts: 1 + 6).

Owner decision recorded in #5438 (option A, 2026-11-02). Gate: kernel unit
suite + bili e2e green; human-only review tier unchanged.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-02_anthropic-heal-follow-side (f9f4a9b)

Latest build — install this exact version

npm install -g billion-context@0.0.7865-pr.5522.be209b3

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
f9f4a9b billion-context@0.0.7865-pr.5522.be209b3 build
335afa0 billion-context@0.0.7863-pr.5522.3b09403 build
3ee3ff6 billion-context@0.0.7848-pr.5522.5cdf35d build
f862e4a billion-context@0.0.7844-pr.5522.c5c482c build
ca532d4 billion-context@0.0.7835-pr.5522.9235271 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5522.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)

查重:不重复。镜像检索(open+closed,按机制关键词 "healIllegalSystemPositions follow side" / "mid-conversation system follow heal")零命中;相关线程 #5432(母 issue)、#5438(kernel 授权申请,owner 已批 option A)、#5441(host 侧止血 PR,未合入 master)——本 PR 是 #5438 批准 diff 的交付,与三者机制或范围均不同。

标签:bug, claude-code, scope/kernel, p1, needs-decision —— 缺陷类;现场客户端为 claude-code v2.1.316(mid-conversation-tool-changes 契约);修复位置在 kernel wire 编码器;受影响配置下整请求 400、会话级不可用 → p1(可用性缺陷类)。


背景一句话:本 PR 实现的是你已在 #5438 拍板(option A,2026-11-02)的 kernel diff,但 PR 正文缺 kernel-change: 声明字面量,kernel-guard 判红,依赖它的全部远端 test/e2e 车道被 skip——目前不存在远端全量裁决。按授权卡点政策(agent 不得自行往 PR 正文补 kernel 声明:#4814/#4825 反面教材、#4828 正面范例),这一步需要你。

待决问题:由谁在 PR #5522 正文补上 kernel-change 声明?

选项:

  • A(推荐):由你(或你明确授权的 agent)在 PR 正文加一行,例如 kernel-change: heal the follow side of Anthropic's mid-conversation system position rule — owner-approved option A, #5438 (2026-11-02)。代价:一次编辑;CI 全车道重跑即出远端裁决。
  • B:为此 PR 破例豁免声明。代价:先例风险——kernel 人工门禁的机械要素被绕过一次,后续同类 PR 失去锚点。

不决定的默认行为:PR 停在 kernel-guard 红,test 车道持续 skip,无法合并。代码审查不受此阻塞——我已独立通读 diff 并核完版本/lockfile,八问结论随后单独给出。


初审状态:diff 已通读(6 文件全部在 kernel/ 内 + 两个 lockfile,无 host 侧改动);kernel 版本 0.0.177→0.0.178 与两个 lockfile 一致性已核对;正在本地跑定向测试(新增回归文件 + 4457 双侧 checker),完整八问结论随后给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #5522 审核结论(结构化八问)

我独立做了什么:通读全部 6 文件 diff(逐行读了 kernel/src/wire/anthropic.ts 改动与两个测试文件);手工推演了 mutating pass 的索引有效性与边界形状;核对了 master 版本(0.0.177)→PR 版本(0.0.178)与两个 lockfile 一致性;在 PR head 本地跑了定向测试 28/28 绿(新回归文件 10 个 + issue4457-sidecar-system-folds + issue4292-orphan-system-guard,全真链 anthropicToCore→applyCompression→prune→coreToAnthropic)+ kernel typecheck 干净。全量裁决按纪律留给远端 CI——目前因 kernel-guard 红被 skip,尚不存在(见上一条 🔶 需要决策)。

  1. 是什么问题:Anthropic 对 mid-conversation system 的位置规则是双侧的(必须 FOLLOW user/以 server tool_result 结尾的 assistant,且 PRECEDE assistant 或数组末尾)。bili 的后补修复只查了 PRECEDE 一侧——fold 把 sidecar system 前面的 user turn 盖掉后,system 悬在暴露的 assistant 正后方,整个请求 400,直到客户端自己清掉 mid-conversation systems。
  2. 什么原因导致的:healIllegalSystemPositions(kernel wire 编码器内、coreToAnthropic 出站前)只判 follower 一侧,predecessor 侧非法布局直接放行。非法形状产生于 fold 之后、编码器之内——宿主打到的是已发出的数组,宿主侧再查一遍等于规则两份必然漂移(kernel authorization request: heal must enforce the FOLLOW side of Anthropic's mid-conversation system position rule (#5432) #5438 的方向判断成立,本 PR 修在产生点,不是堵症状)。
  3. 影响范围与严重程度:claude-code(v2.1.316 era)+ mid-conversation-tool-changes 契约用户;触发条件 = fold 覆盖 sidecar 之后的回合(或客户端位置非法输入)使 system 落在暴露 assistant 后。严重度:该会话所有请求 400 直到客户端自清 = 会话级不可用 → p1。其余队列/合法布局不受影响。
  4. 怎么修复的:同一个左到右单遍修复里加 predecessor 腿,复用现有降级管线(re-voice to user / WC-022 剥 tool_addition+tool_removal / 空则丢);directive-only 任意位置豁免且永不合法化邻居;数组起点无 predecessor 按既有契约仍合法。单遍语义给出最小修复(前面降级成 user 后,run 内后续成员自动合法化)——有专门 pin 防未来粗化。另新增导出 insertBeforeTrailingSystemRun 作为尾部临时消息插入的唯一规则源(空 additions 返回同一引用,零缓存扰动);宿主侧切换刻意留给 [PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441 与本 PR 都合入后的小跟进 PR,避免分支冲突。
  5. 是否有回归问题:对我清点的既有行为逐项过——precede 半判定条件字节级未变;降级管线(demotion)代码路径未动;directive-only 豁免未动;fresh-object 纪律(原 rawAnthropicMessage 不被就地改写)保持;golden wire-contract pin 未触碰;host 代码零改动;新导出为纯增量(unused-exports 门绿)。无意回归:未发现。有意行为变更(已在 PR 正文披露):follow 非法但 precede 合法的布局从「原样发出→400」变为「降级为 user 后发出」——这些请求此前本来就 400,没有任何原本工作的请求改变字节。残留风险(诚实声明):谓词与线上 API 实际接受面的精确吻合(尤其 assistant+tool_result 条款)依赖 kernel authorization request: heal must enforce the FOLLOW side of Anthropic's mid-conversation system position rule (#5432) #5438/Anthropic 400: mid-conversation system must FOLLOW a user message — heal only checks the follower, and trailing nudge/notes land after a trailing system #5432 现场证据 + verbatim 测试钉死,沙箱内无法独立探测活 API;已知合法形状均有负向钉。
  6. 是否破坏缓存:否。合法布局字节级往返(negative tests 钉死);空 additions 同引用返回;降级只作用于本来就会 400 的请求,无存量断点被改写。
  7. 是否改了设计方向:否。位置规则所有权留在 kernel wire 编码器(KDD#2),只在既有 backstop 原位扩展;宿主接管明确 out-of-scope 且排好了序(等 [PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441 先合)。
  8. 是否引入了新的配置:无。无 config/env/flag 新增。

测试有效性:真测试——fold 驱动回归走真实压缩链并断言精确内容(delta text 以 user content 存活、tool_addition 绝不泄漏出 system)、双向门纪律齐全(正例 heal + 负例 verbatim)、链式最小修复有 pin、空 additions 同引用有 assert.equal。bug 复发时抓得住。

diff 整洁度:6 文件全部服务于目的,lockfile 只有版本行,无空行/重排噪音。代码整洁硬标准逐项过:命名达意、无死代码、无魔法数、注释讲为什么(带 issue 锚点)、风格与周边一致、零新依赖。


合并判定:代码本身通过独立审核,可合的条件是两个前置:① owner 在 PR 正文补 kernel-change: 声明(上一条 🔶 需要决策,推荐选项 A);② 声明落地后 CI 全车道重跑绿(kernel 单测层 + bili e2e 两层,人工 review tier 不变,最终合并动作归 owner)。在此之前 PR 停在 kernel-guard 红是门禁机制正常工作,不是代码问题。

ci-check added 2 commits November 2, 2026 14:48
…llow side (#5438)

Review follow-up to the approved heal: legitimatesFollowSide matched ONLY the literal 'tool_result' as an assistant's last block, but on the real Anthropic wire server-executed tool results ride INSIDE assistant messages as the <name>_tool_result family (web_search_tool_result, code_execution_tool_result, ...; plain tool_result is user-role only). The parser rides those blocks on the #3410 unknown-block sidecar, so a legal system-after-server-tool-result-assistant hit the over-demotion path: re-voiced to user on every request — byte drift vs verbatim = one-time prefix-cache break plus a system->user authority shift on previously-legal traffic.

Fix: match the whole family by suffix (endsWith 'tool_result') — every member shares the convention, future server tools inherit it, and no non-result block type ends in 'tool_result'.

Tests: mirrored orphanSystems checker updated to the same family rule; new regression pins BOTH directions — the real wire shape (assistant ending in web_search_tool_result keeps the following sidecar system verbatim) and its precede-side-violating twin (still demoted, proving the two legs stay independent).
…nversation system rule (#5438)

The #5432 production 400s documented a permanent upstream constraint (system messages must FOLLOW a user or a tool-result-terminated assistant AND PRECEDE an assistant or end the array; directive-only form exempt anywhere) that had no WIRE_RULES ledger entry — #1304 requires one inside the fixing PR.

Adds WC-023 with provenance citing both live error strings, and midConversationSystemViolations() mirroring kernel healIllegalSystemPositions exactly (per-run verdict at the first non-directive member; missing predecessor legal; <name>_tool_result family on the follow side), enforced on BOTH Anthropic lanes (main validator + vertex-anthropic lane validator share the clause — same Messages API behind both). Gate test asserts both directions plus the four legal shapes; probe row feeds the ledger self-check.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #5522 审核结论(findings-only,不 approve —— kernel 人工门禁)

我独立做了什么(不复读前一轮结论):逐分支推演 healIllegalSystemPositions mutating pass 的索引有效性与级联语义;把 legitimatesFollowSide 对照契约与 #5438 open-item(a)「缺前驱=合法」逐条核对;验证 insertBeforeTrailingSystemRun 全部边界(无尾 run=纯 append、空 additions=同引用、全 system=插头);核 kernel 版本 + 两个 lockfile 纪律;扫 WIRE_RULES 台账;读镜像缓存确认 CI 状态。

核心判定:代码正确、测试扎实,可合——但有一处我在前一轮之外新发现的流程缺口(见第 5 问),需 owner 定夺。

结构化八问

  1. 是什么问题:Anthropic 对 mid-conversation system 的位置规则是双侧的(必须 FOLLOW user/以 server tool_result 结尾的 assistant,且 PRECEDE assistant 或数组末尾)。bili 的后补修复此前只查 PRECEDE 一侧,FOLLOW 一侧非法布局直接放行 → fold 把 sidecar 前的 user turn 盖掉后,system 悬在暴露 assistant 正后方,整请求 400。
  2. 什么原因导致:healIllegalSystemPositions(kernel wire 编码器内、出站前)只判 follower,predecessor 侧缺判。修在产生点(编码器)而非宿主侧再查一遍——避免规则两份必然漂移,方向正确。
  3. 影响范围/严重度:claude-code(v2.1.316 era) + mid-conversation-tool-changes 契约用户;触发 = fold 覆盖 sidecar 之后回合使 system 落在暴露 assistant 后。该会话所有请求 400 直到客户端自清 = 会话级不可用 → p1。合法布局/其余队列不受影响。
  4. 怎么修的:同一左到右单遍里加 predecessor 腿,复用既有降级管线(re-voice→user / WC-022 剥 tool_addition+tool_removal / 空则丢);directive-only 任意位置豁免且永不合法化邻居;无 predecessor(数组起点)按既有契约仍合法。单遍语义给出最小修复(前面降级成 user 后 run 内后续成员自动合法化)。另导出 insertBeforeTrailingSystemRun 作尾部临时消息插入的唯一规则源。
  5. 是否有回归问题:逐项过既有行为——precede 半判定字节级未变、降级管线未动、directive 豁免未动、fresh-object 纪律保持、host 代码零改动。无意回归:未发现。⚠️ 但发现一处前一轮未提的流程缺口:§7.3/[CI/testing] wire-contract anti-regression system: validation-parity fake upstreams + golden schema snapshots + constraint ledger + staged 4-protocol x 3-mode client smoke matrix #1304 要求生产环境发现的每条上游约束成为 WIRE_RULES 台账永久条目(ledger + gate + fake-upstream enforcement),且 kernel authorization request: heal must enforce the FOLLOW side of Anthropic's mid-conversation system position rule (#5432) #5438 floor-1 open-item(d) 明确承诺「并入同一 PR」——本 diff 未触碰任何 tests/wire-contract*,台账仍只有 WC-001..WC-022(无位置规则条目)。回归本身已被新增 kernel 测试钉住(断言 orphanSystems(coreToAnthropic(...))==[]),所以不影响本次修复的正确性,但规范台账没长、宿主 fake-upstream 也缺对「错位 system」的 parity 拒绝。此为跨多个测试基建文件 + 设计判断的非小改动,我不代改,交 owner 定夺(见下方 🔶 需要决策 选项 A/B)。
  6. 是否破坏缓存:否。合法布局字节级往返(负向 verbatim deepEqual 钉死);空 additions 返回同一引用;降级只作用于本来就会 400 的请求,无存量断点被改写。
  7. 是否改设计方向:否。位置规则所有权留 kernel wire 编码器(KDD#2),只在既有 backstop 原位扩展;宿主接管明确 out-of-scope 且已排序(等 [PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441 先合)。
  8. 是否引入新配置:无。

测试有效性:真测试。fold 驱动回归走真实压缩链并断言精确内容(delta text 以 user content 存活、tool_addition 绝不泄漏出 system);双向门纪律齐全(正例 heal + 负例 verbatim,#3617);链式最小修复有 pin;空 additions 同引用 assert.equal。bug 复发抓得住。

CI 状态(镜像缓存 @ ca532d4,06:40Z):kernel-guard ✅、全部 guard/gate 车道绿(version/lock-sync/config-surface/lane/unused-exports/docs/pi-subagents/lifecycle-ledger),0 failed / 0 pending。注意:本快照里 test/e2e/static-gates matrix 车道记为 skipped(red-signal cancelled),故「全量套件绿」我按合并步的确认项对待,不自行断言。

diff 整洁度:6 文件全部服务目的,lockfile 仅版本行,无噪音。版本纪律正确(acp-kernel 0.0.177→0.0.178 随 kernel src 变更同 commit,CI 强制;host package.json version 未触碰)。

小 nit(不处理):PR 正文写「10 tests」,实际新文件 11 个顶层 test()。在正文非代码,不改作者正文,仅记录。

合并判定:代码本身通过独立审核,可合。但本 PR 触及 kernel/(kernel/src/wire/anthropic.ts + acp-kernel 版本号),按 Kernel Boundary 属人工 review tier——AI reviewer 不 stamp APPROVE。剩余动作归 owner,见下方 🔶 需要决策。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)

PR #5522(gated diff:kernel/src/wire/anthropic.ts + acp-kernel 0.0.177→0.0.178)触及 kernel/,按 Kernel Boundary 属人工 review tier,AI reviewer 不 approve。方案方向你已在 #5438 拍板(option A,2026-11-02),此处不是重议方案,而是请你做人工 review + 合并授权,并就我一个新发现拍板一处。

待决事项(1 项,不阻塞代码正确性):WIRE_RULES 台账缺口。#5438 open-item(d) 承诺把「mid-conversation system 位置规则」作为 WIRE_RULES 永久条目并入本 PR(§7.3/#1304),但本 diff 未加——台账仍只有 WC-001..WC-022。回归已被新增 kernel 测试钉住,所以两条都可接受,请你选:

合并前请顺手确认:镜像缓存本快照里 test/e2e/static-gates matrix 车道为 skipped(red-signal cancelled)——请确认最新 head 上这些车道已跑绿再合(kernel-guard 与各 guard 车道已绿、0 failed)。

其余:代码正确、测试扎实、行为披露完整、diff 干净,无其他阻塞项。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b) review-worker-r1 完成:findings-only 审核(不 approve,kernel 人工门禁)+ 🔶 需要决策 + needs-decision 标签均已落地;代码判定可合,待 owner 人工合并授权并就 WIRE_RULES 台账缺口(选项 A/B)拍板。

…23 (#5522)

The WC-023 ledger commit (f862e4a) accidentally deleted three permanent WIRE_RULES entries (WC-010 cache-breakpoint cap, WC-013 reasoning.summary, WC-014 Jinja head-system) and overwrote WC-011's #1733 provenance with unrelated #4882 text - violating the ledger-grows-only rule (#1304). Their enforcement clauses and gate tests were never removed, so this is a faithful byte-for-byte restore of the known-good records from ca532d4. Verified locally: tests/wire-contract.test.ts 23/23 green (ledger self-check now sees all 25 rules) and tsc --noEmit clean.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

第二轮审核(新 head f862e4a98,含我的修复 3ee3ff65b)— findings-only,不 approve(kernel 人工审批门槛)

作者在我第一轮审核后推了两个 commit。我独立重审了增量(未照抄 issue/上一轮结论):

① f06619ffc(kernel 谓词修正)— 正确,且修掉了一个真实潜在回归

  • 原 legitimatesFollowSide 只认字面 type === "tool_result"。但真实线上,服务端工具结果以 <name>_tool_result 家族(web_search_tool_result、code_execution_tool_result…)挂在 assistant 消息里;裸 tool_result 是 user 角色专属(配 tool_use)。
  • 后果:旧谓词对「assistant 以服务端工具结果结尾」这种合法布局判为非法 → 每请求都把后续 system 降级成 user → 逐字漂移 + 一次性前缀缓存断裂 + 合法流量上 system→user 的权限语义漂移。
  • 修法 endsWith("tool_result") 精确覆盖整个结果家族:成员共享该命名约定、未来服务端工具自动继承,且没有任何非结果块型以 tool_result 结尾(server_tool_use 以 tool_use 结尾,不命中)。我逐分支核对过极性(badFollow = !legitimatesFollowSide),方向正确。测试双向钉死(真实线形保持 verbatim / precede 侧违规孪生仍降级,证明两腿独立)。✅ 这条正好消掉了我第一轮 hedged 的残留风险项(谓词与活 API 接受面的精确吻合依赖现场证据)。

② f862e4a98(WC-023 台账条目)— 补上了我第一轮的主发现

③ 我另发现并当场修掉一个阻塞级缺陷(#1304 违规)
f862e4a98 在加 WC-023 时误删了三条永久台账条目(WC-010 cache-breakpoint 上限、WC-013 reasoning.summary、WC-014 Jinja 头部 system),并把 WC-011 的 #1733 provenance 覆写成了无关的 #4882 tool_addition 文本。而这三条的 enforcement 代码 + gate 测试都还在(WC-010 校验器逻辑、WC-013 两个 gate 测试)——典型改坏而非有意精简,直接违反「台账只增不减、缩减须 owner 签核」。
已顺手修:从 ca532d4f3 逐字恢复这三条 + WC-011 的 #1733 provenance(保留新增的 WC-023),本地验证 tests/wire-contract.test.ts 23/23 绿(台账自检现见全部 25 条)、tsc --noEmit 干净 + commit 3ee3ff65b。若你本意是要删其中某条,请说明,我会回滚这次恢复。


结构化八问

  1. 是什么问题:修 Anthropic「会话中段 role:system」规则的两个方向(follow + precede),让客户端自带的非法位置 system 不再整请求 400(Anthropic 400: mid-conversation system must FOLLOW a user message — heal only checks the follower, and trailing nudge/notes land after a trailing system #5432 生产事故)。
  2. 什么原因导致的:根因是客户端把宿主下发的 system 工具增量消息原样重发、落在 API 不接受的位置;本轮追加的根因是首轮 heal 的谓词只认裸 tool_result、没匹配真实线上的 <name>_tool_result 家族。
  3. 影响范围与严重程度:Anthropic 车道(含 Vertex)携带客户端源中段 system 的请求。此前直接 400 = 会话不可用(p1 可用性);谓词修正额外消除了合法流量上的缓存断裂 + 权限漂移这一潜在回归。
  4. 怎么修复的:healIllegalSystemPositions 双侧位置约束(指令式豁免、连续 run 取首个非指令成员裁决)+ legitimatesFollowSide 按后缀匹配整个结果家族 + WC-023 作双车道永久 tripwire;host 侧抑制在 [PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441。
  5. 是否有回归问题:审过既有行为——heal 是 fail-safe 降级非吞错;合法布局逐字节不变(verbatim deepEqual 钉住缓存稳定);空 additions 同引用零扰动。发现的回归:WC-023 commit 误缩台账(删 3 条 + 坏 1 处 provenance,违反 [CI/testing] wire-contract anti-regression system: validation-parity fake upstreams + golden schema snapshots + constraint ledger + staged 4-protocol x 3-mode client smoke matrix #1304)→ 已当场修(3ee3ff65b)并本地验证绿。无其它回归。
  6. 是否破坏缓存:无净负向——降级只在会 400 的回合触发;谓词修正反而消除了窄谓词在合法流量上造成的一次性缓存断裂。合法布局对前缀缓存保持字节稳定。
  7. 是否改了设计方向:否。仍在 kernel authorization request: heal must enforce the FOLLOW side of Anthropic's mid-conversation system position rule (#5432) #5438 option-A 批准范围内(kernel heal + host 抑制分 [PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441),无新配置面。
  8. 是否引入新配置:无。

结论:代码正确、测试有效、台账已补齐并恢复,可审层面全部收敛。唯一挡合并的是 kernel 人工审批门槛(Kernel Boundary §1 + 本节 HARD RULE)——agent 不自批 kernel 变更,转 🔶 需要决策,等 owner 授权后再由人合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

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

PR #5522 触及 kernel/(kernel/src/wire/anthropic.ts 的 legitimatesFollowSide / healIllegalSystemPositions / 导出的 insertBeforeTrailingSystemRun,两个 kernel 测试文件,kernel 版本 0.0.177→0.0.178),带 kernel-change: 声明。按 Kernel Boundary §1(先声明 + owner 事前批准 + 人工评审)与本任务 HARD RULE,agent 不自批 kernel 变更。

请 owner 就以下被门禁的 kernel diff 授权:

  • legitimatesFollowSide:assistant 末块判定从 === "tool_result" 放宽为 endsWith("tool_result")(匹配 <name>_tool_result 家族)。
  • healIllegalSystemPositions:新增 follow 侧校验 + 降级(复用既有 pipeline,coreToAnthropic 内调用点不变)。
  • insertBeforeTrailingSystemRun:导出。当前无生产调用方,消费者落在 [PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441 之后的收尾 PR——请确认该 follow-up 会落地(届时删除 host 侧临时拷贝),否则会成为永久死代码。
  • kernel 版本 0.0.177→0.0.178:随 kernel src 变更、CI 强制 bump,合规;与 host package.json 版本无关(未动)。

背景:owner 已于 2026-11-02 在 #5438 确认 option A(「你直接把他修复到闭环吧」),本 PR 即其实现;host 侧配套为 #5441。此授权是合并前的最后人工关卡。我这边可审层面已全部收敛(含当场修掉的台账误删,见上一条 review)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

✅ 第二轮审核完成(head f862e4a98,含我的修复 3ee3ff65b):两个新 commit 均正确(谓词修正消除了合法流量上的过度降级回归;WC-023 补上了第一轮缺的台账条目);另发现并当场修掉 WC-023 commit 误删的三条台账(WC-010/WC-013/WC-014)+ 坏掉的 WC-011 provenance——本地 tests/wire-contract.test.ts 23/23 绿 + tsc --noEmit 干净。kernel 变更按门槛转 🔶 需要决策、已打 needs-decision 标签,等 owner 授权后由人合并;全量套件由 CI 在新 head 上把关。

…r-convergence asserts

The windows/node22 shard-2 flake behind #5522 run 41407086184: settle()
trusted one fixed sleep of debounceMs+60 (80ms for these fixtures) before
asserting all 11 clustered-duplicate rows had settled — under Windows load
the debounced disk flush outran that budget (9/11 rows). Both affected
assert sites now poll a bounded 10s window (waitUntil) before the SAME
assertions; no behavior change shipped, test file only.
@ranxianglei

ranxianglei commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner Author

红因定位 + 修复(test-only,已 rebase 在分支上):

唯一红的 job: windows/node22 测试矩阵分片 2(run 41407086184,job 125151570147)。TAP 2512 个用例只挂 1 个:「#5155 integration: duplicate-content messages (clustered <base>_<n> rows) still converge pointers」→ AssertionError strictEqual 9 !== 11(tests/issue5155-incremental-per-turn.test.ts:234)。

根因是时序 flake,与本 PR diff 无交集:该测试的 settle() 是固定睡眠 debounceMs+60(fixture debounceMs=20 → 共 80ms),睡完就断言 11 条同内容消息的持久化行全部落盘并匹配指针。Windows 分片高负载下(同文件相邻用例单跑 3.9s),防抖磁盘写入没赶上 80ms 预算 → 只匹配到 9 行。这条链路全是宿主持久层(SessionStore 防抖 / inc:canonical-ptrs 扩展字段),与本 PR 的改动(kernel/src/wire/anthropic.ts follow-side heal + kernel 测试 + 版本号)零重叠;同一份代码在 05:43Z、06:48Z 两轮完整 CI 都是全绿,本地 linux 全量也绿。

修复(commit 335afa0):把两个指针收敛断言点前的固定睡眠换成有界轮询 waitUntil(≤10s),断言语义完全不变,仅测试文件,+22 行;本地跑该文件 7/7 通过。

另告知:本分支在两次推送之间被另一会话(ci-check@local)追加了 3 个 commit——f06619ff(kernel 侧放行真 server-tool-result 块族)、f862e4a9(WC-023 ledger 条目+tripwire)、3ee3ff65(恢复其误覆盖的 ledger 条目);本次修复已 rebase 在其上,本轮 CI 一并覆盖它们(此前 06:48Z 批次已单独验证过全绿)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

独立复核了你的 flake 修复 commit 335afa0d3(未照抄结论,自己核过代码与本地跑过):

  • 范围:纯测试——仅 tests/issue5155-incremental-per-turn.test.ts +22/−0,不碰 src/kernel/版本号。两个指针收敛断言点前各加一个有界轮询 waitUntil(≤10s),原断言逐字保留、语义不变;helper 干净(40ms tick、超时抛错,比原来的固定魔法睡眠失败信号更清楚)。✅
  • 本地跑:fixed head 上该文件 7/7 绿,含此前红的「duplicate-content … converge pointers」那条(每条 ~3.3s,与你说的分片高负载吻合)。低负载 linux 下 80ms 本就够,waitUntil 是让它在高负载下不再赌固定预算。✅
  • 根因归属——确认成立,补一处精确化:失败断言是宿主持久层的行数时序(SessionStore 防抖 / inc:canonical-ptrs,走 src/incremental-lane.ts + src/persist.ts),本 PR 完全没碰这条链。精确一点说:该测试确实经 acp-kernel/wire(anthropicToCore/coreToAnthropic,heal 所在)间接依赖内核,所以不是字面「零共享模块」;但这些 fixture 里根本没有中段 system 消息供 heal 作用,且 heal 只改出站 Anthropic body、不改客户端侧落盘行数——因果上确与本 PR 无关。结论不变:时序 flake,归因正确。

状态:CI 红已消解并验证。整个 PR 现在只剩一道门槛——按 Kernel Boundary §1 / 🔶 需要决策,等你对 kernel diff 的显式授权后由人合并;我这边代码面没有其它待办。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

第四轮(新 head f9f4a9b15)— 干净的主干同步合并,无新增本 PR 代码,结论不变

这个新头是把 origin/master 合进分支的一次同步合并,我核过:

结论不变:代码正确、可审层面全部收敛。仍只差一道门槛——按 Kernel Boundary §1 / 我的 🔶 需要决策,等你对 kernel diff 的显式授权后由人合并。本轮无新增待修项、无新发现。

@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Nov 2, 2026
@ranxianglei
ranxianglei merged commit d5a84f1 into master Nov 2, 2026
109 checks passed
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.998-master.d5a84f1 (rolling master tag).

npm install -g billion-context@0.0.998-master.d5a84f1  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Nov 2, 2026
…low-side heal

Kernel gains the follow-side half of the mid-conversation system rule
(ranxianglei#5438) plus two wire-contract ledger entries and a bounded-poll fix for
issue5155. Zero overlap with this lane's 16 files.
@github-actions github-actions Bot mentioned this pull request Nov 2, 2026
ranxianglei pushed a commit to Mako-L/billion-context that referenced this pull request Nov 4, 2026
…i#5438 two-sided heal; keep final-array backstop; kernel 0.0.181)

Conflict resolution: master shipped the sibling fix for this family (ranxianglei#5438 via PR ranxianglei#5522: two-sided heal inside coreToAnthropic, demote-only) plus the insertBeforeTrailingSystemRun helper (host wiring pending in ranxianglei#5441). Take master's approved heal semantics wholesale; keep ranxianglei#4715's residual contribution: the healAnthropicSystemPositions standalone export + the three host final-array call sites + WC-023 pins (ledger entry kept from master's side, one entry per id). Branch move-past-next-user design superseded by the owner-approved ranxianglei#5438 approach. Kernel bumped 0.0.180 -> 0.0.181 (kernel-change-vs-base rule).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR claude-code needs-decision p1 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant