Skip to content

[PR] Outbound invariant judge: add I3 pairing invariant — folded/split tool_use/tool_result no longer marked clean (#4862) | 出站不变量判官补 I3 配对不变量:折叠拆断的 tool_use/tool_result 不再判 clean(#4862) - #4984

Merged
ranxianglei merged 4 commits into
masterfrom
2026-10-28_issue4862-judge-egress-pairing
Oct 28, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

修什么

一句话:判官(出站不变量校验)此前只对账「入站 vs 出站的连续性」,从不检查出站体自己的协议结构——折叠把一对 tool_use/tool_result 拆掉半侧送出去,判官照样判 clean 放行,直到上游用 400 tool_use ids were found without tool_result blocks 打回来。日志里那条 clean fold verdict 正是最容易被误读成「bili 没问题」的行(owner 在 #4862 的 triage 评论原话)。

根因

src/invariant-judge.ts 只定义两条不变量,全是 entry↔exit 连续性对账:

  • I1(无折叠):入站每条 stable 消息按序出现在出站;
  • I2(折叠):差异局限在折叠区即合法——折叠区是自由区。

#4862 的形状:折叠/渲染只送出一对工具调用的半侧 → 差异全在折叠区 → I2 判合法 → clean 放行 → 上游 400。

修法

新增 I3 出站配对不变量(纯检测、零拦截、零出站字节改动):

测试

tests/issue4862-invariant-judge-unpaired.test.ts 12 例(#3617 正负双向):

  • NEG:折叠吃掉 result 半侧 / call 半侧、render-lane 渲染前缀含断对、id 重铸洗白 → 全红;
  • POS:宿主自发半对回显、compress 在途、整对折叠(kernel 边界对齐)、同 id 复用 precedence → 全绿;
  • Wired:真 anthropic body 主车道 + loop 连续性车道正负各一。

既有判官三件套(46 例)原样全绿;折叠/压缩/孤儿相关回归(issue4292、compress-success-tail、loop-responses-orphan、issue3222、affinity-crosswire-fold,38 例)全绿;typecheck 过。

划界

第 2 层(真正拦 400 的出口修复:剥孤儿半侧 / anthropic 邻接楔入上提)是 wire/message-shape 变更,属人工审核层,不在本 PR——等本层判官红线在真实流量确认命中形状后单独决策。与 #4774(根修共享 session id,消除主触发源)正交且互补。

关联 #4862 #4769 #4774

…e/tool_result half-pairs no longer judge clean (#4862)

The judge's I1/I2 only reconcile entry↔exit continuity; the folded region was
a free zone, so a fold that ate ONE half of a tool pair earned a clean fold
verdict right before the upstream answered 400 (tool_use ids without tool_result
blocks). I3 checks the exit body's own protocol structure: every tool-call
answered by a later same-id tool-result, every tool-result preceded by a
same-id tool-call — kernel-parity directional walk (prune.ts #3046),
fold-split agnostic, all four modes (legacy/render-lane/main/loop).

Attribution stays 'whose fault': host-sent half-pairs skipped per-id, a
volume guard arbitrates id re-mints (#2821), compress calls stay exempt
(hideConsumedCompressCalls parity). Pure detection — zero outbound bytes
changed, never blocks, diagnostics.invariantJudge knob as before.

Tests: 12 rows (NEG half-pair folds/render prefix/re-mint laundering;
POS host-broken echo/compress in-flight/whole-pair fold/same-id precedence;
wired main+loop lanes). Existing judge suites (46) stay green.
@ranxianglei ranxianglei changed the title 出站不变量判官补 I3 配对不变量:折叠拆断的 tool_use/tool_result 不再判 clean(#4862) [PR] Outbound invariant judge: add I3 pairing invariant — folded/split tool_use/tool_result no longer marked clean (#4862) | 出站不变量判官补 I3 配对不变量:折叠拆断的 tool_use/tool_result 不再判 clean(#4862) Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-28_issue4862-judge-egress-pairing (90eb12a)

Latest build — install this exact version

npm install -g billion-context@0.0.6532-pr.4984.ea025bf

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
90eb12a billion-context@0.0.6532-pr.4984.ea025bf build
a8956fc billion-context@0.0.6526-pr.4984.8176db8 build
3fc164c billion-context@0.0.6509-pr.4984.8a98f81 build

Download artifact

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

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

查重:不重复。 检索了 open+closed issue/PR(按「invariant judge / pairing / unpaired tool_use / I3 / #4862」多组关键词+失败签名),无其他条目触碰判官的出站配对缺口。关联项均已在 PR 正文挂链且机制不同:#4862 = 本 PR 修的对象;#4774 = 根修(子代理不再共享 session id,消除主触发源);#4769/#4352/#4409 = 共享 id 线的历史面。

标签:bug / claude-code / scope/wiring / p2 —— 判官观测缺口修复(纯检测、零拦截),触发形状来自 claude-code 子代理车道;p2 因为本层不改任何出站字节,用户侧行为不变(上游 400 的根治仍在 #4774/第 2 层)。

审核进行中(独立重做,未照抄 issue 结论):

  • ✅ 分支与 master 无落后(base bcbd1a3 即当前 master tip,无需 rebase);diff 5 文件 +394/-1,单 commit,干净。
  • ✅ 代码核对:I3 配对行走与 kernel 守卫(kernel/src/prune.ts stripOrphanedToolCalls/ToolResults,[Bug] prune strip guards pair tool calls by id-set, so duplicate host ids ship an unpaired half (upstream 400, session bricked) #3046)逐行同构——precedence-only、集合语义、compress 在途豁免只豁免 call 侧(kernel 自己剥 orphaned compress result,判官镜像同一边);归因两层护栏(逐 id 跳过宿主断对 + 体量护栏防 id 重铸洗白)与 DESIGN 一致。接线点 src/server/relay.ts:769(主车道)+ src/loop/core.ts:516(loop 第 2+ 轮)均为 advisory-only:只写日志、try/catch 吞错、零出站字节改动。
  • ✅ 本地定向测试:新文件 12 例 + 既有判官三件套 46 例全绿;折叠/孤儿相关回归(issue4292、compress-success-tail、loop-responses-orphan、issue3222、affinity-crosswire-fold)38 例全绿;typecheck + build 过。
  • ⏳ CI 在跑(镜像缓存:26 项中 4 绿、5 skipped(e2e 车道未由文件列表触发)、17 pending,0 failed)——等全绿后给结构化八问终审。

两点小观察(不影响方向,终审里一并处理):① PR 正文把「clean fold verdict 最容易被误读成『bili 没问题』」标为 owner 原话,实际出处是 #4862 floor 3 的 agent triage 评论(#4862 无 owner 评论),归属小误;② defaultSink 日志前缀 I${v.folded?2:1} 是 I3 之前的写法,I3-only 违规在非折叠请求上会打成 "I1 violation: unpaired-tool-call"(kind 名能消歧,措辞瑕疵)。

ci-check added 3 commits October 28, 2026 00:41
…ine (#4862 review follow-up)

The defaultSink labeled every violation by folded-ness (I2 when a fold
carrier is present, else I1). An I3-only violation on a non-folded request
read as "I1 violation: unpaired-tool-call" — exactly the misread this
invariant exists to prevent. Label by the invariant that actually fired.
…ume counts (#4862 review follow-up)

POS row: entry ships one host-broken non-compress call plus an in-flight
compress call, exit re-mints both ids. Compress must be excluded from BOTH
the exit and entry volume counts or the re-minted compress inflates the
exit side into a false positive.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #4984 审核完成。方向、实现、测试、回归全部独立复核过;审核中发现两处小问题已直接在 PR 分支修掉(两个独立标注 commit,已推送);未发现阻断项。

八问

  1. 是什么问题:判官此前只对账入站↔出站的连续性(I1/I2),且把折叠区当自由区——折叠拆断一对 tool_use/tool_result 的半侧时,判官照判 clean 放行,直到上游用 400 打回来;那条 clean verdict 日志行还是最容易被误读成「bili 没问题」的行。
  2. 什么原因导致的:I2 的语义是「差异局限在折叠区即合法」,本意管内容连续性,但没约束出站体自身的协议结构;判官从不检查出站体内部的配对完整性——结构性盲区,不是参数或调优问题。
  3. 影响范围与严重程度:所有折叠/渲染可能拆断工具对的场景(当前受害者:claude-code native subagent,[Bug][claude] 0.1.207: subagent requests fail with 400 "tool_use ids were found without tool_result blocks" right after a fold in the parent session #4862)。本层只补可观测性缺口(假 clean 判决),不改出站字节、不拦截——用户侧 400 依旧发生,修它靠根修 [PR] fix: split header-less claude code subagents onto their own session lane (#4352) #4774 + 第 2 层出口修复(本 PR 明确划出、留人工审核)。严重度:p2 可观测缺陷。
  4. 怎么修复的:新增纯检测的 I3 出站配对不变量——正向走查(每个 tool-result 前面必须有同 id tool-call)+ 反向走查(每个 tool-call 后面必须有同 id tool-result),precedence-only,与 kernel prune.ts([Bug] prune strip guards pair tool calls by id-set, so duplicate host ids ship an unpaired half (upstream 400, session bricked) #3046)守卫同构;归因两层护栏:宿主自发断对逐 id 跳过(谁的错谁背)+ 体量护栏(只对超出宿主断对数的部分告警,公告:release v0.1.193 修复dsh 切模型导致上下文暴涨问题,修复fork问题,修复claude codex dsh等自动压缩导致会话破坏问题 . 另外修复几十个bug. 我本地场景有限,未必都测全,麻烦大家小场景先测试下是否有问题.任何问题及时反馈. #2821 式 id 重铸洗不白);compress 在途调用豁免(对齐 hideConsumedCompressCalls,bare + mcp__bili__compress)。零拦截、零出站字节改动,advisory warn 只出不拦。
  5. 是否有回归问题:触碰路径的既有行为逐项审过——(a) 判官判决逻辑:I1/I2 语义未动,既有 46 例原样全绿;(b) 两个调用点(relay 主车道、loop 连续性车道):只是多了一次 try/catch 包裹的无条件调用,失败吞掉不影响请求路径;(c) 出站字节:零改动;(d) 高危模式逐项过:无 fail-fast→吞错、无阈值/时序/默认值漂移、无缓存键变化;唯一输出格式变化是日志行标签(见下方披露)。本地定向验证:判官三件套+新文件合计 58/58(含本次新增 1 例)、孤儿/折叠相关回归 5 文件 38/38,typecheck/build 全绿。
  6. 是否破坏缓存:不涉及——纯检测,零出站字节改动,任何缓存键/游标/去重策略都不受影响。
  7. 是否改了设计方向:没有。只做第 1 层检测;第 2 层出口修复(剥孤儿半侧 / anthropic 邻接楔入上提)属 wire/message-shape 变更,明确留给人工审核,与 [PR] fix: split header-less claude code subagents onto their own session lane (#4352) #4774 正交互补。
  8. 是否引入新配置:没有——沿用既有 diagnostics.invariantJudge 开关,无新 env/config/默认值。

行为变更披露(旧→新)

日志行原为按 folded-ness 打标(I${folded ? 2 : 1} violation:),I3 违规在非折叠请求上会被标成 I1;现改为按实际触发的不变量打标(I3 违规标 I3)。原因:防止出现「这条 I3 告警又被误读成 I1 连续性事件」——正是本不变量要消灭的那类误读。除此之外无任何行为变化。

审核中推送到 PR 分支的两处小修(新 head a8956fcfd)

  • 02cfc8371 fix:sink 日志标签(即上面披露项);
  • a8956fcfd test:新增一例 POS 钉死「compress 豁免对两侧体量计数对称生效」——此前只有负向被钉住,若有人从退出侧体量计数里去掉 compress 排除,现有用例抓不到,此例能抓到。

推送前本地 typecheck + 定向 58/58 全绿。

仅报告项(未改)

PR 正文引用「owner 在 #4862 的 triage 评论原话」——该句实际出自 agent triage 评论(#4862 floor 3;#4862 线程里没有 owner 评论)。轻微归属偏差;按政策 agent 不改写 PR 正文,在此报告,由作者/owner 定夺。

CI 状态(截至写作时)

新 head a8956fcfd:11 success + 11 skipped(e2e 车道按 file-list 未触发)+ 8 个轻量 guard 排队中,0 failed;master 全绿(#4599 已于 16:21Z 结案,head 9b6ec2345),无继承红。镜像 check 缓存自 ~16:49Z 起刷新停滞(共享 GitHub API 读配额耗尽,单次 REST 探测同样命中限额),最后 8 个 guard 的终态暂无法确认——恢复后我会补一条确认评论。base 落后 master 3 个提交(#4904,dsh 车道文件),与本 PR 五个文件零交集,无需 rebase。

判定

代码级审核通过,未发现阻断项;建议待 CI 全绿确认后合并(合并操作人工执行)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Merge guard sync done: merged origin/master (9b6ec23) into branch 2026-10-28_issue4862-judge-egress-pairing cleanly (no file overlap), pushed new head 90eb12a. Merge state moved behind → blocked; CI re-running on the new head — 0 failed so far (12 success / 11 skipped, 7 test shards still in progress).

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收工小结(审核已完成,详见上方八问回复与补充):

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 全绿确认:head 90eb12a23 上全部 30 项检查完成——18 success + 12 skipped(e2e 车道按 file-list 未触发)+ 0 failed,含最后 7 个 test 分片。镜像缓存已恢复刷新(此前停滞原因见 #4599 记录)。

至此审核闭环:代码级审核通过(八问见上方)、两处小修已随分支推送、base 已追平 master、CI 全绿。建议合并(合并操作人工执行)。

@ranxianglei
ranxianglei merged commit 9d2ac52 into master Oct 28, 2026
47 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.893-master.9d2ac52 (rolling master tag).

npm install -g billion-context@0.0.893-master.9d2ac52  # 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.

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