Skip to content

[PR] fix: invariant judge issues false mid-history-rewrite verdict for egress-shed archived images (exempt from directional s | fix: invariant judge 对 egress-shed 归档的图片出假 mid-history-rewrite 判定(豁免方向性结构证明) - #5093

Open
ranxianglei wants to merge 4 commits into
masterfrom
2026-10-29_judge-shed-exemption

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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

Part of #5049(item 2;该 issue 为 #4982 全量回归 review 的遗留项跟踪母题)

问题

egress shed(#3701 字节预算 / #4124 图片数量收敛,均默认开启)在 sentBody 捕获前把出站图片归档成占位 note([image: <mime> <WxH> <mNNNNN> omitted for size limit],唯一生产者 src/egress-shed.ts:78-87),入站孪生仍是图片核。invariant judge(relay.ts:769)拿 shed 之后的实际出站字节重解析并与入站逐格比对:stableEqual 无 shed 豁免 → 每个被 shed 的图片格都判成假 mid-history-rewrite。当前 log-only(defaultSink),但污染 #3842 信号面——图片密集会话每次发送都在刷假告警。

修法

stableEqual(src/invariant-judge.ts)新增方向性结构证明 isShedArchivedTwin:exit 格文本必须与单一生产者格式锚定全串相等(非子串扫描,#1456 纪律),且入站孪生必须是图片核(imagePart sidecar,四条 wire codec 一致置位)。

刻意不加有界豁免计数器、不改 JudgeVerdict 形状:(a) 证明是结构+方向的,内容缺陷无法批量制造合格配对;(b) shed 每次发送重跑、归档的是同一批最老图片 → note 存量随会话历史增长,设上限会在这类会话里造出新的假阳性溢出类。shed 配对按 matched 计(与 isTruncatedTwin 同待遇)。

行为变更披露(judge 判定面,advisory-only)

旧值:图片密集会话超预算/超限后,每轮发送产出 warn 级 mid-history-rewrite 假判定 → 新值:这些格判 clean(matched)。wire 行为零变化;judge 默认 log-only,BILI_INVARIANT_JUDGE=0 可整体关闭。

测试

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-29_judge-shed-exemption (6993a77)

Latest build — install this exact version

npm install -g billion-context@0.0.7162-pr.5093.53442e8

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
6993a77 billion-context@0.0.7162-pr.5093.53442e8 build
86d7401 billion-context@0.0.6942-pr.5093.c7efda6 build
f59152a billion-context@0.0.6724-pr.5093.51d7a14 build
1bcca84 billion-context@0.0.6709-pr.5093.f250099 build
4e53754 billion-context@0.0.6705-pr.5093.9e97825 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: invariant judge 对 egress-shed 归档的图片出假 mid-history-rewrite 判定(豁免方向性结构证明) [PR] fix: invariant judge 对 egress-shed 归档的图片出假 mid-history-rewrite 判定(豁免方向性结构证明) Oct 29, 2026
Egress shed (#3701/#4124) archives outbound images to a placeholder note
in the sent body only; the inbound twin stays the image core. The
invariant judge re-parses the post-shed body, so every shed cell read as
a false mid-history-rewrite in image-dense sessions. stableEqual now
accepts the directional structural proof: exit cell is EXACTLY the
single-producer shed-note format AND the inbound twin is an image core
(imagePart sidecar). No new verdict shape or exemption counter — the
proof cannot be mass-produced by content defects, and a cap would mint
a new overflow class in exactly these sessions.

Negative controls pin both gate directions: note-shaped text against a
non-image twin, non-note rewrites of an image, and malformed notes all
stay red.

Part of #5049 (item 2)
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收到,开始 review PR #5093(单 commit 1bcca84,2 文件 +67/-2)。

查重: 不重复 —— #5093 本身即 #5049 item 2 的修复 PR;open/closed issue 与 PR 中无其他针对「judge 对 shed 归档图片出假 mid-history-rewrite」的条目(#4862/#4241 是 judge 的其他缺陷面,#3701/#4124 是 shed 本体,机制不同)。

初审已核实的点(先报进度,完整结论稍后按八问给出):

  • 生产者/消费者格式锚定核对通过:shedNote(src/egress-shed.ts)bits 只含 mime/WxH/mNNNNN 无空格 token,正则 ^\[image: [^\s\[\]]+(\s[^\s\[\]]+)* omitted for size limit\]$ 恰为其全串族;四条 wire codec(anthropic/google/openai/responses)图片核均为独立 CoreMessage(contentType "text" + imagePart:true),方向性结构证明成立。
  • relay 顺序核对通过:pre-send byte/count shed 在 relay.ts L769 judge 之前,judge 判的 sentBody 确为 shed 后实际出站字节——bug 前提成立。
  • 发现一个测试缺口:5 个新例没有覆盖「note 形状文本被嵌进更长 exit 文本」这条锚定纪律(bug(ccr): embedded [acp-stored text is misclassified as a canonical placeholder #1456)的 NEG 行——正则 ^...$ 能保证,但没有测试钉住这个声明。准备按小问题直接修补一行进 PR 分支。

继续:CI 状态(镜像缓存)+ 本地定向测试,随后给八问结论。

…#1456)

Review follow-up on #5093: the five new gate rows covered directionality,
malformed notes and non-note rewrites, but no row locked the claim that the
exemption matches the producer format as a WHOLE cell (anchored ^...$), not
a substring. Adds the missing NEG control: an image twin whose outbound cell
merely contains the note text stays red (mid-history-rewrite).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Review 结论:PR #5093 可合(新 head f59152a,CI 47/47 全绿,0 失败)

审核独立性声明:以下结论是对 diff 与 master 源码独立重读产出,未复用 issue 侧表述。

结构化八问

  1. 是什么问题:图片密集会话超过 egress shed 的字节预算([Bug] Jimp is active, but image accumulation still triggers Responses WS 1009; duplicate request size not reduced (v0.1. | [Bug] Jimp 已生效,图片累积仍触发 Responses WS 1009;重复请求未缩小(v0.1.200) #3701)/数量上限(No per-prompt image count cap: upstream "Too many images in request: 165 > 30" is forwarded as-is | 缺少按 prompt 的图片张数上限:上游 "Too many images in request: 165 > 30" 被原样转发 #4124)后,出站图片被归档成占位 note,而 invariant judge 拿 shed 后的实际出站字节与入站逐格比对时没有这个豁免——每个被归档的图片格都被误判成 mid-history-rewrite,每轮发送刷一条 warn 假告警,污染 [design] Pin cache stability with two outbound invariants: no-fold ⇒ exit only appends a tail; fold ⇒ bytes before the f | [design] 用两条出站不变量定死缓存稳定:无折叠=出口只多尾部,有折叠=折叠点前字节不动(证明式断言 + 属性/SMT 搜索分层) #3842 的信号面。
  2. 什么原因导致的:judge 的逐格相等判定 stableEqual(src/invariant-judge.ts)只认「内容归一化后相同」及既有的 crush/CCR/truncated 豁免,不认识「出站格是 shed note、入站孪生是图片核」这一对合法配对。shed 发生在 relay L573/L579(judge L769 之前),所以 judge 看到的 sentBody 天然是 shed 后的字节——两侧结构性不等,判定必然假红。
  3. 影响范围与严重程度:仅 judge 信号面(advisory log-only,默认 sink 只写日志,BILI_INVARIANT_JUDGE=0 可整体关闭);wire 行为零变化、用户无感。触发条件:会话图片多到超预算/超限(如截图密集的工作流)。严重度:体验/信噪比问题,非可用性缺陷。
  4. 怎么修复的:在 stableEqual 里加一道方向性结构证明 isShedArchivedTwin:exit 格文本必须与唯一生产者 shedNote(src/egress-shed.ts)的格式锚定全串相等(正则 ^\[image: [^\s\[\]]+(\s[^\s\[\]]+)* omitted for size limit\]$,非子串扫描,bug(ccr): embedded [acp-stored text is misclassified as a canonical placeholder #1456 纪律),且入站孪生必须是图片核(imagePart:true)。两个条件都过才豁免;shed 配对按 matched 计,不进有界豁免账本(理由 issue 已述,我认可:note 存量随历史增长,设上限会造出新的假阳性溢出类)。
  5. 是否有回归问题:逐项审过——
    • stableEqual 是模块内私有函数(grep 全仓确认无其他调用者),豁免作用面严格限于 judge 的两个 I1 配对扫描(frozen-prefix + render-lane tail);
    • 非图片孪生 × note 形状文本:仍红(方向性门,测试钉住);
    • 图片孪生 × 非 note 改写:仍红(正则门,测试钉住);
    • 畸形 note(缺右括号等):仍红(锚定门,测试钉住);
    • 理论残留:客户端显式传空 media_type 且尺寸不可解码且 session 无对应 ref 时,bits 为空 → note 变双空格形态,正则不匹配 → 保持红。保守方向、输入退化、advisory-only,接受不修;
    • 高危模式逐项:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化、缓存/重试/去重策略零触碰。
  6. 是否破坏缓存:不涉及——judge 纯观测,不改 wire 字节、不动 prefix cache;shed 本身的确定性重跑行为未变。
  7. 是否改了设计方向:不涉及——judge 架构、verdict 形状、sink 全部不变,只加了一道配对认定。
  8. 是否引入了新的配置:不涉及——无新 env/config/默认值。

既有行为清单(回归审查第②条要求)

触碰路径 = src/invariant-judge.ts 的 stableEqual + tests/invariant-judge.test.ts。既有行为:① entry==exit 恒绿(保持,45 例原测全过);② 各既有豁免(crush/CCR/truncated/carrier/reasoning)语义不变(保持);③ 真缺陷形状(rewrite/drop/reorder/mid-insertion/I2 fold-boundary)仍红(e2e + 4862 + 4241 套件 19/19 过);④ matched 计数:仅新增「shed 配对计入 matched」这一项,即本 PR 已披露的行为变更(假红 → clean)。

Review 中顺手补的一个小修(独立标注 commit)

发现 5 个新例缺一条锚定纪律的 NEG 行:PR 声称「锚定全串相等,非子串扫描」,但没有测试钉住「note 形状文本被嵌进更长 exit 文本时对图片孪生仍红」。已按小问题直接修补进 PR 分支:commit f59152a(test only,+10 行,新增 1 例 NEG)。本地定向验证:invariant-judge 46/46、e2e/4862/4241 共 19/19、typecheck 干净;新 head CI 47/47 完成、0 失败。

合并判定

可合。 代码质量达标准确、diff 干净(单文件逻辑 +67/-2 加我的测试小修)、双向门禁齐全、行为变更已披露、CI 绿。当前 mergeable_state: blocked 是分支保护待人工批准,请 owner 自行合并:#5093

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

补一行(首条回复漏了):标签: bug + scope/wiring + p2 —— judge 逐格判定的缺陷面,位于请求管道观测层(src/invariant-judge.ts,非 kernel/);确定性日志信号污染、advisory-only 无用户可感破坏,故 p2。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

状态确认(进程曾被强制重启,重启后核对过线程):review 已全部完成,无遗留动作——

  • 终审结论在上一条八问回复:可合,新 head f59152a CI 47/47 全绿(含我补的锚定纪律 NEG 测试行);
  • 标签已打齐:bug + scope/wiring + p2;
  • 我这边没有待办,等 owner 批准合并即可(分支保护 pending approval,合并权在你)。

@ranxianglei ranxianglei added bug Something isn't working p2 scope/wiring labels Oct 29, 2026
@ranxianglei ranxianglei changed the title [PR] fix: invariant judge 对 egress-shed 归档的图片出假 mid-history-rewrite 判定(豁免方向性结构证明) [PR] fix: invariant judge issues false mid-history-rewrite verdict for egress-shed archived images (exempt from directional s | fix: invariant judge 对 egress-shed 归档的图片出假 mid-history-rewrite 判定(豁免方向性结构证明) Oct 29, 2026
ci-check added 2 commits October 30, 2026 09:58
Sync origin/master (153 commits) to clear the behind state flagged by merge-guard. No conflicts. PR content (src/invariant-judge.ts + tests/invariant-judge.test.ts) unchanged.
Sync origin/master (81 more commits since last sync) to clear the behind state flagged by merge-guard. No conflicts; PR content (src/invariant-judge.ts + tests/invariant-judge.test.ts) byte-identical.

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

Labels

bug Something isn't working p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant