Skip to content

[PR] fix(session): keep a conversation on its main lane when full-compaction destroys the byte evidence — sessionid+host-msgid last-resort identity (#5719) - #5759

Merged
ranxianglei merged 1 commit into
masterfrom
2026-11-05_msgid-lane-identity
Nov 6, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-11-05_msgid-lane-identity

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是什么问题

dsh 桌面端在「全量压缩(一条 checkpoint 消息顶掉中间几百轮)和系统提示词变化(Web-GUI 端口号等易变字段)落在同一轮」时,会击穿车道解析的全部字节级逃逸梯——head 对齐、模型头佐证、prefix-affinity 续接、#4778 run、#5686 短尾对齐都要求字节证据,而这一轮恰恰把证据整段删掉又改了几个字节。结果是必然 fork 出一条零状态 <id>|sub: 副车道:refs/tsStamps/token 账本全丢、UI 里一个客户端会话裂成两条车道。会话 id 全程没变(#5719 已实证排除);仅 5 个端口数字就能决定走不走副车道。

这个 PR 做什么

在三个「确定要 fork」的出口处加一道最后兜底的身份判断,不碰现有任何一层:

改动文件 4 个(+412/-5,vs master 0aace2f):

验证

本地全绿(node v25.9.0):tsc clean;新测试 8/8;persona/lane 回归电池 103 pass/0 fail;7 个 e2e 红族文件全绿。统一存储零新增表、零写入路径变更(id 由 #4491 盖章时本来就钉在消息行上)。

与其他修复的关系

…of forking a zero-state lane

A full dsh compaction (one checkpoint user message replacing the middle of
the conversation) landing in the SAME TURN as a volatile-field rewrite of
the static system prompt (the Web-GUI port digits, #5517) defeats every
byte-level continuation rung in resolveSessionOrder simultaneously — the
rungs need fragments/cells/chain continuity and the compound event deletes
all of them. The resolver then FORKED `<raw>|sub:<fp>`: a lane with zero
state under an UNCHANGED client session id (issue #5719), which re-stamped
timestamps/refs/lineage from scratch on every restart window and left the
UI showing two lanes for one conversation.

Host-minted per-message ids survive BOTH destructive forces. dsh stamps a
stable UUID on every canonical message and re-sends them verbatim after a
restart or compaction (the #4491 biliMsgIds body field), so ANY overlap
between the ids riding the incoming request and the msg_ids RECORDED under
the key proves same-conversation with a random-collision probability near
zero — no threshold tuning, unlike simhash or content fingerprints.

Single source of identity evidence (owner ruling: the JSON recording
surface is being deprecated; do not add to it):

- recorded side = the UNIFIED STORE's messages.msg_id column, already
  pinned at ingest by #4491 (validateMsgIds/applyMsgIdPin). The lookup
  used is #5312's getStore().unifiedAllMessageIds(key) — the FULL
  historical id set of a key (live AND retired rows; retire-don't-delete,
  #4390), identity-only SELECT with no content hydration, and null on an
  unavailable store. No parallel id ledger anywhere: session-order
  skeletons stay byte-level only, order-persist.ts is untouched by this
  change.
- inbound side = incomingMsgIdsOf(body) in src/msgid-pin.ts: the same
  degrade-over-mispair discipline as validateMsgIds (#4491: malformed
  array => treat the field as absent, never half-trust it). No
  length-equals-messages contract here — compressed resends have uneven
  windows, and any-overlap is the proof we need (strict pinning stays with
  validateMsgIds).

Semantics — presence-gated, last resort, all lanes:

- resolveSessionOrder / personaConversationOrder gain two trailing
  optional params (msgIds, readStoredMsgIds); every existing call site is
  source-compatible. Requests that carry no stamped ids take EXACTLY the
  pre-change path — nothing about claim/match/reanchor/fork precedence
  changes unless both sides are present.
- readStoredMsgIds is LAZY by contract: invoked at most once, and only at
  a fork exit with non-empty inbound ids. null return (store latch-off,
  legacy epoch, #4407/#5536 auto-disable) degrades to the byte-evidence
  only path. The underlying read is `SELECT msg_id` — cheap on long
  sessions too.
- at each of the three fork exits (persona lane, derived-task grown,
  derived-task short): non-empty intersection => record() back onto the
  raw id + return {action: "reanchor"} with a reason naming the hit count
  and first matched id. The existing five escape rungs are untouched
  (each carries historical bug endorsements #2241/#2601/#4778/#5686 —
  this rung sits strictly BELOW them).
- handle.ts wires both params into all six persona-order lanes from the
  single shared lazy lookup over unifiedTailViewRows.

Tests (tests/issue5719-msgid-lane-identity.test.ts, 8 pins): incident shape
re-anchors with no fork; disjoint ids still fork; no ids / malformed ids
=> exactly the old path; stored rows outlive any wire projection AND the
JSON skeletons carry no ids field (single-source pin); restart wipes
resolver memory but the store survives so the FIRST post-restart request
already rescues; personaConversationOrder forwards everything lazily
(store queried at most once); store-unavailable (null) degrades to fork.

Verified: tsc clean; issue5719 file 8/8; persona/lane battery green
(issue2944 10, issue3397 4, dsh-persona-continuity 4, dsh-persona-fingerprint
11, issue2601 7, persona-fork-active-parent-guard 1, plugin-fork 56); e2e
red family green (3450 2, completion-wall 2, fix-1001 7, 3645 4,
empty-summary 9, hold 4).
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-05_msgid-lane-identity (5fd07ad)

Latest build — install this exact version

npm install -g billion-context@0.0.8276-pr.5759.157f14e

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
5fd07ad billion-context@0.0.8276-pr.5759.157f14e build

Download artifact

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

PR #5759 审核 — 可合(先 rebase,机械无冲突)。 已拉取分支 2026-11-05_msgid-lane-identity(head 5fd07ad)逐文件核对,读了它依赖的存储方法,核对了 CI 与 master 漂移。CI 绿:59 success / 31 skipped / 39 cancelled / 0 failure·error(ubuntu/windows × node22/24 各 test shard 均 success;cancelled 为被取代的 matrix 腿,非失败)。

结构化八问

  1. 是什么问题:dsh 桌面端在「全量压缩 ∩ 系统提示词易变字段(Web-GUI 端口号等)改写」落在同一轮时,车道解析的字节级证据被整段摧毁,必然 fork 出一条零状态 <id>|sub: 副车道——客户端一个会话裂成两条,refs/tsStamps/token 账本丢失。
  2. 什么原因导致:现有逃逸梯每层都要字节证据,该复合事件同轮既删证据(压缩)又改字节(系统提示词),所有层一起失守,且缺一条不依赖字节的身份兜底。属机制级根因,非表面现象。
  3. 影响范围与严重程度:触发 = dsh + 全量压缩与系统提示词漂移同轮(端口号极易触发)。p1 级:主车道状态被孤儿化到零状态副车道,长会话累积状态实质丢失;本 PR 恢复主车道可用。
  4. 怎么修复:只在三个「确定 fork」出口加一道 last-resort 身份判断——请求自带 host 盖章 msgid(Plugin lanes: pin identity to client msgids, render outbound from the server-owned history | 插件车道服务端正史:消息身份钉在客户端 id 上,出站前缀由正史渲染 #4491 稳定 UUID,跨重启/压缩不变)∩ 该 key 在统一存储的 msg_id 全集(unifiedAllMessageIds,live+retired),任意交集非空即判同一会话、re-anchor 回主车道;无盖章 / 校验不过 / store 不可用则退回逐字节等价老路径。只增不改任何现有层(疏非堵)。
  5. 是否有回归:无。① 两函数仅加尾部可选参数,老调用点 inboundIds===undefined → rescue 立即返回 null → 逐字节不变;② handle.ts 六个 persona 接线对不带合法 biliMsgIds 的请求零变化;③ 守卫栏保留——不相交 id 仍 fork(T2),host UUID 随机不碰撞、同 rawId+交集⟹确为同一会话,无误并;④ 懒查询契约成立(至多一次、仅 fork 出口、非热路径,T7 断言 lookup≤1);⑤ 降级安全——store 返回 null(latch-off/disabled)或 [](异步后端 sync===null)都跳过 rescue,永不猜;⑥ 单一源——T5 钉死 session-order skeleton 不携 ids 字段(废弃 JSON 记录面保持干净);⑦ rebase 干净——master 自 merge-base 前进 41 commit,但三个改动文件上游零变更,依赖的 allMessageIds 在 origin/master 逐字节相同(master 的 store.ts 改动在无关行)。
  6. 是否破坏缓存:否,反改善。rescue 只在「原本会 fork(=重置到新车道=缓存重置)」的点触发,改 re-anchor 是延续既有前缀而非重置;其余场景中性。
  7. 是否改设计方向:扩展非转向。新增「sessionid+host-msgid」兜底置于字节梯之下,与 KDD#11「msgid > 顺序 > hash」一致(msgid 在场时最优先);现有各层语义一字未动。
  8. 是否引入新配置:无。复用既有 biliMsgIds(Plugin lanes: pin identity to client msgids, render outbound from the server-owned history | 插件车道服务端正史:消息身份钉在客户端 id 上,出站前缀由正史渲染 #4491)与统一存储视图(billion-context instead of billion-context-pi for pi? #5312),零新增 env/config/knob。

代码 / 测试质量:命名达意(incomingMsgIdsOf/tryMsgIdRescue/storedMsgIdsOf)、null-safe,校验复用 #4491 纪律(上限 512 / reserved 前缀 acp_summary_ / 控制字符)。8 个 pin 全有牙且双向覆盖(符合 #3617 gate 纪律):命中 reanchor(T1)/ 不相交仍 fork(T2)/ 无 id 走老路径(T3)/ 四种坏 id 全降级(T4)/ store 跨 wire 存活+无 JSON ledger(T5)/ 重启首请求即命中(T6)/ 转发+懒≤1(T7)/ store-null 降级(T8)。诚实边界:测试用 fake store,验证的是 resolver 对抽象 lookup 的逻辑;真实 unifiedAllMessageIds 我已独立核对为 SELECT msg_id FROM messages WHERE session_id=?(live+retired,retire-don't-delete #4390),缺口补齐。唯一非阻塞 nit:rescue 建完整 Set 再判命中,可在首个命中处短路——罕见 fork 出口 ≤1 次,不值得为此重跑 CI。

判定:可合。 唯一机械步骤 = 先 rebase 到最新 master(当前 behind 41 commit,但三文件上游零变更,rebase 无文本冲突)。需要的话我可以代做 rebase。

⚠️ 需 owner 拍板(合并前):#5719 有多个在途方案——本 PR(host 盖章 msgid 兜底)与作者引用的 E5 方案(信任 checkpoint 内嵌 <bili-snapshot> 自声明,其 PR #5734)互补而非互斥,任一命中都不再 fork。请定:先后 / 并存 / 择一。我的推荐:本 PR 可独立合并(机制不同、互不干扰、单独即闭环),E5 另走;若暂不定的默认行为 = 按「本 PR 安全可合」处理不会有害。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

进度汇报(上一轮进程卡住被重启,这里同步现状):本 PR 的完整审核判定已在上一条回复给出(结论:rebase 后可合并,无回归、cache 只增不降、无新增配置),并已打上 needs-decision 标签。这条补上首条回复漏掉的开头必带项——接单查重结论。

查重:同症状、不同机制,不重复,但并存关系需你拍板。

本 PR(GitHub #5759)与另一条在途修复都指向同一个 bug(#5719:全量压缩 ∩ 系统提示词易变字段漂移落在同一轮 → 误 fork 出零状态 <id>|sub: 副车道),但机制不同:

PR 机制 身份依据
#5759(本条) host 盖章 msgid 兜底 dsh 为每条消息铸的稳定 UUID(#4491 盖章管线),与统一存储该 key 已记录的 msg_id 全集求交
#5734(E5,你正文引用) bili 自产标记自救 信任 checkpoint 内嵌的 <bili-snapshot> 自声明

两条用户可见症状相同(都是"字节证据被整段删掉又改了几个字节"导致误 fork),按 owner 2026-10-13「同症状 = 一个 issue」原则,它们本应归并到 #5719 这一个 issue 下统一管理;但作为在途 PR 各自独立、互不阻塞。我不关闭、不合并其中任何一条——是并存 / 择一 / 谁先合,由你在上一条 ⚠️ 决策块里拍板(默认行为:各自独立可合,任一命中即不再 fork)。

本 PR 自身核对结论:与 master 无冲突、CI 全绿、rebase 干净(src/session-resolve.ts / src/msgid-pin.ts / src/server/handle.ts 三个改动文件在 merge-base 0aace2f .. origin/master 之间零变更,且依赖的 unifiedAllMessageIds 读取路径未变)。

@ranxianglei
ranxianglei merged commit cc29523 into master Nov 6, 2026
129 of 168 checks passed
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1046-master.cc29523 (rolling master tag).

npm install -g billion-context@0.0.1046-master.cc29523  # 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 pushed a commit that referenced this pull request Nov 6, 2026
Only conflict: kernel/package.json version line — both sides bumped after
base 0.0.180 (ours 0.0.181 via #5608-B/C time-attr work, master 0.0.182 via
#5758/#5759). The merged tree carries BOTH unreleased change sets, which no
single prior version denotes, so reconcile to 0.0.183 (max+1).
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