Skip to content

[PR] fix(pi-msgids): model-switch rewrite no longer drops client message ids (pairing proof preserved) | fix(pi-msgids): 切模型改写不再丢客户端消息 id(配对证明保留) - #4834

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-26_msgid-transform-tolerant
Oct 26, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-26_msgid-transform-tolerant

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是啥问题

pi 切换模型后,历史消息的线上字节会被 pi 自己改写(thinking 块拍平成 text、redacted thinking 整块丢弃、非视觉模型把图片降级为占位文本、工具调用 id 跨模型规范化),但会话条目的 id 没变。旧版 laneMsgIdsForWire 指纹逐字节严格相等,任何一处改写都判"对不上"→ 整轮丢掉 msgIds 字段 → 退回内容派生 id → 账本为 id 从未变过的消息重新铸造身份。这正是 #4390 D4-1 一类"身份重铸"打地鼠的开关源头:每次切模型必复发。

根本原因

src/agent/pi-msgids.ts 的锁步配对把"pi 自己的合法转换"和"真的对不上"混为一谈:n.parts.length !== wParts.length || n.parts.some(...) 逐字节严格比较,thinking→text(块数不变但类型变)、redacted 丢弃(wire 少一块)全都 fail。

改动

  • 新增 partsLowerThrough:双指针配对,仍然证明角色、顺序、非工具部分的字节相等;只放行 pi-stable-ai transformMessages 自己的转换集(对照其 dist 逐条验证):
    • entry think ↔ wire text(同文本)
    • entry redact 跨模型被丢弃
    • entry img ↔ wire 占位文本 (image omitted: model does not support images),连续图片坍缩到同一占位符
    • tooluse/toolres 跨模型 id 规范化漂移(pin 的是 entry id,值漂移不入账本)
  • 合并 tool_result 分支同样只按类型+顺序配对,不再逐值相等
  • 真实文本被改、消息被插入/丢失 → 依旧整轮拒绝(宁可降级不可错位,不变)

为什么这样做(设计取舍)

宿主 id 是消息的稳定身份;切模型改的是字节不是身份。字节改动不该否决 id——否则 id 通道形同虚设,身份永远被字节 hash 绑架(打地鼠之源)。本 PR 只改"配对证明的放行集",不动统一账本的主键/世代判定(同 id 新字节仍走世代行,引用不撒谎)——"id 是否当主键"另议。

验证

  • 新增 6 个单元用例(4 个转换放行 + 2 个拒绝:真文本漂移 / 注入消息),tests/pi-msgids.test.ts 11/11
  • 家族回归:dsh-msgids 6/6、omp-msgids 4/4、opencode-msgids 35/35、msgid-lane-flow / msgid-algebra / msgid-pin 全绿
  • tsc --noEmit 干净

关联:#4491(id 通道)、#4390 D4-1(身份重铸事故)、#3752(编解码升级漂移)

A model switch rewrites WIRE bytes (thinking flattened to text, redacted
thinking dropped, images downgraded to a placeholder for non-vision
targets, tool-call ids renumbered) while the pi session entry id — the
message's stable identity — never changes. The walker's exact-equality
fingerprint treated every one of those rewrites as a mismatch, so the
first turn after a switch dropped the whole msgIds field and fell back
to content-derived ids, re-minting identity for messages whose host id
had not moved (#4390 D4-1 churn family).

Pairing is still proven — role, order, and non-tool part bytes must line
up; a dropped/injected message or a real text edit still refuses the
field (all-or-nothing). Only pi-stable-ai transformMessages' own
transforms (verified against its dist) are tolerated.
@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-26_msgid-transform-tolerant (1d49611)

Latest build — install this exact version

npm install -g billion-context@0.0.6287-pr.4834.6b93423

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
1d49611 billion-context@0.0.6287-pr.4834.6b93423 build
69ddf8d billion-context@0.0.6232-pr.4834.695fb23 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(pi-msgids): 切模型改写不再丢客户端消息 id(配对证明保留) [PR] fix(pi-msgids): model-switch rewrite no longer drops client message ids (pairing proof preserved) | fix(pi-msgids): 切模型改写不再丢客户端消息 id(配对证明保留) Oct 26, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复 —— 按「pi msgIds model switch」与「laneMsgIdsForWire」检索 open+closed issue/PR:仓库唯一匹配条目即本 PR 自身;#4491/#4390 是正文引用的上游关联,不是并行修复。

标签: bug / pi / scope/wiring / p2(理由:切模型后 id 通道整轮降级、身份重铸每次复发,但内容派生 id 回退仍正确可用——有绕行的功能缺陷 = p2,不构成缓存泄漏/不可用级 p1)。

审核结论(独立重审,非复读正文)

我做了什么:

  • 逐行通读完整 diff(仅 2 文件:src/agent/pi-msgids.ts + tests/pi-msgids.test.ts,单 commit 69ddf8d5f),并核对下游消费点 src/agent/pi.ts:1456-1460;
  • 本地定向测试:pi-msgids 11/11、dsh-msgids 5/5、omp/opencode-msgids 全绿;build 干净;
  • CI(head 69ddf8d5f,94 checks):18 个 test shard 全绿、静态门禁全绿;唯一红 = codex accepts CODEX_HOME overlay(windows node22)。拉了该 job 日志取证:tests/win-cmd-argv.test.ts 子测试 32("[Bug][Windows launcher] 经 codex.cmd 启动破坏 argv:嵌入引号拆分、%变量% 展开和 & 被解释 #2196 real win32: the official wrapper answers --help")报 spawnSync C:\hostedtoolcache\...\node.exe ETIMEDOUT(耗时 21.5s)——Windows runner 上真实进程 spawn 超时,本 PR diff 完全不触及该文件;master head 341e76c28 自身 run 全绿(25 success/5 skipped,重型车道按设计跳过),近期实际跑到过该 check 的 master 提交均为绿/skipped → 判定单次环境 flake,与 diff 无因果。已触发 failed job 重跑(run 40305442246,HTTP 201);
  • 基线新鲜度:分支落后当前 master 仅 [PR] fix(wiring): degenerate-turn continuation retry joins the 429 governor (#4743) #4802(src/degenerate-retry.ts + 其测试),与本 PR 零文件重叠,GitHub mergeable 无冲突,无交互风险。

代码判定要点(独立推导):

  • 双指针锁步仍证明角色/顺序/非工具部分字节相等;每个放行项要么保字节(think→text 同 v)要么身份中性(redact 丢弃、img→占位符、tool-id 漂移——pin 的是 entry id,值漂移不入账本);
  • wire 多块由结尾 wi === wParts.length 拒绝、entry 残留立即 false,插入/丢失消息仍整轮拒绝——降级方向不变(宁可降级不可错位);
  • 对抗样例推演:用户字面输入占位符字符串也诚实配对([img,img,text]→[placeholder,text] 坍缩正确,[img,text,img]→[placeholder,text] 正确拒绝);redact 无法掩护多出的 wire 块(计数检查兜住);空 thinking+signature 拍平后被丢弃的极端形 → 整轮拒绝(与旧行为一致,保守方向,非回归);
  • 同模型路径(无转换)逐项精确匹配,结果与旧代码完全一致——存量会话零行为变化;
  • 测试有牙(Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617 双向门):4 个放行用例钉死放行集(谁收紧回字节严格即红),2 个拒绝用例钉死拒绝边界(谁放宽到模糊匹配即红);直调真实纯函数,无 mock。
  • 一处风格观察(判为非缺陷,不动):新单元段把 import { laneMsgIdsForWire } 放在文件中部(line 280)——ESM 提升下合法,且与上方 e2e 式 harness 形成视觉分节,视为有意分区,不加修 commit。

八问

  1. 是什么问题:pi 会话中切换模型后,宿主自己对历史的合法改写(thinking 拍平 text、redacted 整块丢弃、非视觉模型图片降级占位、tool-call id 规范化)让 id 配对证明整体失败,msgIds 字段整轮被丢,退回内容派生 id → 身份重铸 churn 每次切模型必复发(Four storage-layer defects: identity hash contaminated with positional metadata (truncation triggers identity swap) / sw | 存储层四缺陷:身份哈希掺位置元数据(截断即换血)/清扫删除回退历史/渲染接缝图片只比长度/fork 谱系死列 #4390 D4-1 家族)。
  2. 什么原因导致的:旧锁步配对把「宿主的合法转换」与「真的对不上」混为一谈——逐字节严格相等没有转换集概念。
  3. 影响范围与严重程度:所有中途切过模型的 pi 会话;身份通道失效(功能可用但身份 churn),有绕行 → p2。
  4. 怎么修复的:配对从字节严格改为「双指针锁步 + 宿主转换集白名单」,只放行对照 pi-stable-ai dist 逐条验证过的四类转换,其余一律维持整轮拒绝。
  5. 是否有回归问题:逐项审过既有行为——同模型会话(零变化)、all-or-nothing 降级语义(不变)、multi-block delta guard / validateMsgIds / slice 逻辑(pi.ts 未动)、其他车道 msgids(dsh/omp/opencode 文件未动 + 套件绿)、wire 字节(msgIds 走 bili 信封,不进上游模型请求)、proxy 模式路径(不经此 hook)。未发现回归。行为变更披露(旧→新):切模型后的 pi 轮次现在会携带客户端 msgIds(此前恒丢)→ 服务端 canonical 跨模型保留客户端身份而不再重铸;这是修复的预期效果本身。
  6. 是否破坏缓存:不涉及——msgIds 不进上游请求体;稳定 id 反而减少身份重铸引发的重建。
  7. 是否改了设计方向:没有——只改配对证明的放行集,统一账本主键/世代判定未动(「id 是否当主键」按正文留待另议)。
  8. 是否引入新配置:没有。

判定:merge-ready(人审合并) —— 代码、测试、回归面均站得住;唯一 CI 红为 windows runner 环境 flake(证据如上),重跑已触发,转绿后无阻塞项。按 §7.4 属身份通道语义变更,不走 auto-merge,留人审合入。

@ranxianglei ranxianglei added bug Something isn't working p2 pi scope/wiring labels Oct 26, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b) 补一行收口:重跑已绿 —— run 40305442246 整体 success,codex accepts CODEX_HOME overlay 转 success,flake 坐实。现在 head 69ddf8d5f 检查矩阵全绿,无任何阻塞项,merge-ready,待人审合入。

@ranxianglei
ranxianglei merged commit 8539f78 into master Oct 26, 2026
22 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.859-master.8539f78 (rolling master tag).

npm install -g billion-context@0.0.859-master.8539f78  # 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.

ranxianglei added a commit that referenced this pull request Oct 26, 2026
[PR] docs: message-identity hierarchy is now msgid > order > hash (#4491/#4834)
ranxianglei added a commit that referenced this pull request Oct 26, 2026
…he turn

A turn that the guard discards had already claimed its msgIds
client-side (all-or-nothing, #4491). The burned ids were never
released, so the host's retry of the same turn lost the whole
msgIds field and the server pinned those rows to content-derived
identity — the exact host/server divergence #4834 just fixed,
self-inflicted here by the client lanes themselves.

Hoist the #3370/#3378 single-flight guard above planIncrementalTurn
in both native lanes (dsh, omp). The guard only reads the pending-ack
table, so the reorder changes nothing for the guard itself; planning
now only happens for turns that will actually be dispatched.

Regression test: a guard-blocked delta attempt must not burn its ids
— after the seed acks, the retry still pins msgIds (pre-fix: the
field is silently dropped).
yanhuojiyusheng pushed a commit to yanhuojiyusheng/billion-context that referenced this pull request Oct 27, 2026
…glei#4491/ranxianglei#4834)

The doctrine said stable client ids may only ever be join hints. That was
written before the plugin lanes started shipping host msgids in a bili-private
envelope (msgIds on the incremental turn / biliMsgIds stripped at ingress)
and before ranxianglei#4834 made resolution id-first. Agents reading the docs concluded
'we have no msgids' — true on the model wire, false on the plugin lanes.

- AGENTS.md KDD ranxianglei#11 retitled to the full hierarchy: msgid first where the
  envelope carries it (plugin lanes only, never forwarded upstream), order
  still primary on id-less resend reconciliation, hash stays the per-cell
  gate. Three-part PK (session_id, msg_id, content_hash) noted as safety belt.
- AGENTS.md KDD ranxianglei#13 evolution updated to four stages (hash -> order ->
  msgid pinning -> snapshot render).
- MESSAGE-IDENTITY.md: new section 'The msgid envelope' documenting the
  channel, all-or-nothing semantics, resync re-claim, ranxianglei#4834 id-first,
  ranxianglei#4863 claim-after-guard, and the boundary (model wire unchanged,
  tool-call ids are pairing keys, proxy-mode resends keep the ladder);
  Future-direction paragraph refreshed.
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
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 p2 pi scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant