Repository navigation
[PR] fix(session): keep long sessions on their raw lane when a host upgrade repacks the message records (#5844) - #5851
ranxianglei wants to merge 13 commits into
Conversation
… a host record repack (#5844) A host upgrade that changes BOTH the system prompt text and the message-record layout (dsh 0.2.1->0.2.2-rc.x: assistant text segments merged into adjacent records, some standalone assistant records dropped) destroys every byte-level continuation evidence at once: per-source-message fragment hashes are disjoint even though every logical turn is identical, so all four tagChanged escape rungs miss and the conversation forks onto an empty |sub:<fp> lane -> preflight folds from scratch -> resume dies with a fail-fast 413. Add a canonical-turn fingerprint rung at the #5686 site: when the replay is strictly shorter and kind-tail-aligned, reanchor onto the raw id if the last <=TAIL_WINDOW turns match the recorded skeleton turn-by-turn in CANONICAL form (neutralTurnCanonical — the identity chain's own hashing input), which survives record regrouping but not content mutation. The skeleton persists the canon column additively (absent on pre-change snapshots); a missing or malformed column degrades to exactly the pre-change byte-fragment path. The #5686 fragment reason string stays byte-identical.
…, degradation) Six pins: the bug shape reanchors with the new content-verified-tail reason; a mutated last user cell still forks derived-persona; a skeleton hydrated without the canon column forks exactly as before this change; the snapshot round-trip keeps the rescue alive across restarts; a malformed canon column degrades to the byte-fragment path; and a tag-invariant repacked shorter replay already reanchors through the pre-existing owner-rule branch (symmetry row).
…and exists (#5844) SESSION-IDENTITY en/zh: state plainly that there is no supported command or config knob to re-attach a drifted |sub lane to its parent, and give the sanctioned manual procedure (stop the proxy first — the daemon silently rewrites session-order.json from memory; set the parent entry's tagHash to the sha256 hex digest of the host's current full system text or delete the entry; restart; bili sessions rm the orphan lane). Answers the reporter's section-8 question from #5844.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8974-pr.5851.71db455This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5851.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…e length drifts from kinds The writers keep canon 1:1 with kinds (both derive from the same turn list in record()), so a length mismatch means the column is shifted/corrupted. Degrade to absent (byte-fragment path = pre-change behavior) instead of trusting misaligned fingerprints.
… a kind break The original guardrail replaced an assistant record with a user record, so the fork came from tailAligns' kind suffix comparison and never reached the canonical-fingerprint comparison it was meant to pin (it would pass even with the canon rung removed). Rewrite it to mutate the final tool result's text — layout and kinds unchanged — so the fork can only come from the canon mismatch itself.
…rified tail An assistant turn carrying tool calls hashes as calls+role only (cross-wire neutrality — OpenAI renders such turns with content:null), so a prose-only difference inside a calls turn is invisible to the #5844 rung exactly as it is to the rest of the identity chain that shares neutralTurnCanonical. State that boundary next to the manual re-attach procedure (en+zh).
[bot] 🏷 PR #5851 审核结论:可合(人工审层级——session-key identity 逻辑,§7.4 不自动合并)。 查重:不重复(本 PR 即 #5844 线程唯一修复 PR,无并列分支)。标签:PR 侧已有 bug/p1/dsh/scope/wiring/session-id,覆盖类别+优先级+车道+领域,未改标。 八问
回归审计清单(触碰路径的既有行为,逐项):tagChanged 分支裁决序(E5 self-checkpoint → head → model-switch → chain → #4778 → #5686/#5844 → msgid-rescue → fork)各档位置与谓词均未动;canon 档只在 frag 档已求值处触发(门控相同,无新可达面);frag 路径 reason 串字节不变;pinned 测试覆盖老快照解析、坏列降级、tag-invariant 对称性;快照线形仅 additive。性能:record() 热路径新增 O(turns) sha256,相对既有整包 parse 可忽略,接受。 审核中发现并已修(独立标注 commit,已推 PR 分支):
需 owner 知悉(不改代码):PR 描述「canonical form … but not content mutation」对 calls 轮散文场景表述过强(上述边界);建议措辞改为「not logical-content mutation(kind/text/calls)」。描述是作者原文,我不代改,留你处置。 CI:原 head 判定:可合,等 owner 人审签核;#5857 先落则 CI 直绿,否则预期上述单文件继承红(rerun 收敛)。 |
[bot] 🏷 CI 归因更正(接上轮回复):新 head
结论不变:可合,等待 owner 人工审层级签认(session-key identity 逻辑,§7.4 不可 auto-merge);代码面审查结论与三处 review 修复见上轮八问回复。 |
(ai: vllm-qwen/qwen3.8-27b) CI 修复完成:根因是 master 级跨分支陈旧(非本 PR 代码问题),已把自愈后的 master 合入分支,新 head 七问:
当前 CI 状态(镜像缓存,截至本轮收尾):30 项检查 = 7 success + 11 skipped + 12 个长跑测试任务运行中、零失败。对照:旧 head 的同批任务在 ~15 分钟内就红了;新 head 跑满 ~90 分钟无任何失败,且本地 19/19 已把原先失败的两例与预测风险例全部钉绿。 收工判定:本 run 的修复工作已完成(根因定位 + 合并修复已推送 + 本地门禁绿),修复本身不需要任何决策;剩余仅等 12 个长跑任务收尾确认——按现有证据预期转绿,届时 PR 回到「待 owner 人工审核」状态(§7.4 session-key identity 层,自动合并不适用)。若长跑任务出现任何红点,由本自动修复车道 attempt 2/3 接手处理。 |
🔶 需要决策 PR #5851 当前 head c0bdfb0(run 42366607622 + rerun 双重确认):残留 6 个确定性失败,全部是 master 级继承红,与本 PR diff 无关,需要 owner 拍板 #5860 的语义走向。 此前 9 项 golden 红已随分支并入 ci-fixes@6436b23b3c 转绿;#2791(affinity-crosswire-fold,win22-1 首跑 2!==1)rerun 转绿 = Windows 单次 flake,非回归。 待拍板:master #5860(nudge-hold-no-usage-sample,
证据链:纯 master 591e940(不含本 PR)本地逐项复现同款失败;reren-failed-jobs 全量二次确认确定性;#728B「real usage always takes precedence」仍绿,与 hold 只作用于无样本路径一致。本车道按规则不做语义级测试改写,停手等决策。 选项
默认(不拍板时):按 A 执行;在此之前不动本 PR 分支,这 6 项红不阻塞本 PR 自身变更的合并判断(与本 diff 无关)。协调记录见 #4599(issuecomment-6708595676),needs-decision 标签已打。 七问
收工判定:本 PR 自身变更保持可合(review 结论不变);6 项残留红全部 master 级,已按规则升级为决策请求(A/B/C + 默认 A),本车道停手等 owner 拍板。 |
(ai: vllm-qwen/qwen3.8-27b) 冲突处理结论:live 验证后确认无需任何推送——分支已在触发前自行追上 master,「dirty」是过期状态。本轮零代码改动、零推送。 背景核对(全部 live 源,非记忆):触发时刻(15:15Z)分支 head 七问
收工判定:本轮无可执行动作(远端 head 已是正确形态,任何推送都是冗余),已停手。PR 现处「待 owner 人工审核签核」+ CI 长跑任务收尾中(当前 0 失败);若长跑任务出现红点,由本自动修复车道后续 attempt 接手归因。 |
# Conflicts: # src/session-resolve.ts
(ai: vllm-qwen/qwen3.8-27b) 本轮是真实冲突(与上一轮的 stale 误报不同),已解完并推送。七问: 1. 是什么问题:PR 分支再次与其 base(master)冲突,系统报 merge state dirty。这次 master 在上次对齐后真的又前进了。 2. 什么原因导致的:上次对齐把分支带到 master@6945a354;之后 master 合入了 #5895(P2 review batch:model scan memo、ephemeral-ref pinning、preoom snapshot、msgid-rescue trace + kernel EPHEMERAL_QUERY_PARAM 修复,cda6e735)。master 新提交与本 PR 同时改了 3. 影响范围与严重程度:仅影响 PR 可合并性(dirty 挡住合并),无用户行为面。纯机械级。 4. 怎么修复的:merge 5. 是否有回归问题:无。并集 import 两侧符号都在( 6. 是否破坏缓存:不涉及(未触碰缓存/重试/游标/去重策略,本轮只是把 master 合进来)。 7. 是否改了设计方向或引入新配置:无方向变化;本侧未引入新配置。(master 自带的 收工判定:冲突解除,已推送;镜像缓存实测新头 |
…h reanchor rung
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
审查结论:APPROVE(通过)。此为 session-key identity 逻辑,按 AGENTS.md §7.4 需 owner 人工合入。(注:本操作账号即 PR 作者,GitHub 不允许对本人 PR 置 approve 状态,故以评审评论形式给出结论;合并请由你手动执行。)
独立审了 PR 正文、关联 issue #5844、完整 diff(4 文件 +281/−8;不碰 kernel/、不 bump version、无 config 面)。方向关通过:#5844 报的就是长 dsh 会话在宿主升级「同轮换 system prompt + 重打包 assistant 记录」后被误分叉到 <id>|sub:<fp> 空车道、压缩状态清零、preflight 从零压 ~2.5M token 超时 413;本 PR 修的是机制(延续证据通道太脆),不是掩盖 413 这个症状。
八问:
- 是什么问题:同一个对话,因宿主升级同时改了 persona 文本(tagHash 变→tagChanged)和消息记录布局(assistant 文本段并入相邻记录→重放更短),被顺序解析器误判成「换了个人」,分叉到空的派生车道,长会话的压缩状态随之丢失,resume 直接 413。
- 什么原因导致的:延续判定只有一条粒度敏感的字节级证据通道(逐源消息 fragment hash)。记录被重打包后逐消息粒度变了,fragment 全失配,但逻辑回合内容其实逐字不变;四道逃逸档全靠这种证据→集体失效。属「证据通道单一且脆」的机制缺陷,不是表面现象。
- 影响范围与严重程度:仅命中窄条件——同 id 上 tagChanged 为真 + 重放严格短于骨架 + 尾部 ≤8 轮 kind 对齐 + fragment 因重打包失配。严重度 p1(owner 规则:会话无法恢复类一律 p1);触发面窄(需宿主升级同时动 system+记录布局),但一旦命中即整个长会话状态丢失。
- 怎么修复的:给既有的「#5686 tagChanged+更短+尾对齐」档加一条并行内容校验证据——用身份链自有的
neutralTurnCanonical(kind+逻辑文本/调用)对末 ≤8 轮算规范化指纹(canonFp)。它抗记录重打包(重组不改逻辑内容→指纹不变)、但不抗内容变更(改一字即变→照旧分叉)。fragment 路径原样保留且优先、reason 逐字不变;仅当 fragment 失配才回落 canon。持久化加 additive 可选 canon 列,hydrate 严格校验(长度=kinds 数、每项 64-hex),坏值降级 absent→走改动前路径。 - 回归审查(逐项过既有行为):#5686 fragment 档(fragment 匹配时逐字不变、且优先于 canon)✓ 保持 / #5719 msgid-rescue 档(未触碰,仍是 fork 前最后一档)✓ / 全部 tag-invariant 分支(continue / grown / derived-task / tagged-shorter;测试 6 专门钉住 tagged-shorter 仍走既有 owner-rule-1 分支)✓ / 分叉护栏(mis-attribution 防护;测试 2 证明尾部真实内容变更仍分叉)✓ / 快照 wire 形状(additive-only,旧快照无 canon 列照常解析,测试 3/5 钉住)✓。唯一有意行为变更:原本会分叉的「重打包+tagChanged+更短+canon 尾匹配」现在 reanchor——正是本 bug,PR 正文+文档均已披露 old→new,非静默漂移。诚实边界已声明:修复前持久化的骨架没有 canon 列→受影响会话升级后首轮仍可能分叉,靠文档里的施工流程或 #5719 msgid 档兜底;一次成功 reanchor 后骨架即永久带 canon。
- 是否破坏缓存:不涉及。canon 是身份判定用的内存+持久化字段,不进出站渲染、不进 prefix-cache 键,不改任何缓存/重试/增量游标策略。
- 是否改了设计方向:未转向。仍在「顺序为中心 + 多路身份证据、永不模糊相似」框架内加一条更强证据(与 KDD #11/#13 的 msgid>顺序>hash 层级同向);文档明确把「客户端侧稳定身份信号」列为未来根治方向,durable home 留了注记,符合 §7.3「疏 not 堵 + 超范围留边界」。
- 是否引入了新的配置:无。无 config/env/CLI 新增;skeleton 的 canon 列是内部自愈合持久化字段,对用户不可见。
测试有效性:6 个测试都有牙(断言精确的 action/key/reason,非恒真)——正例(reason 匹配 /#5844/,证明走的是 canon 新路径而非 fragment)、护栏(变异末位 tool-result 仍分叉,且特意选 text 承载轮而非 calls 轮,避开跨线中性的已知盲区)、向后兼容(剥离 canon 列→fork,与改动前完全一致)、持久化往返(restart 保住 rescue)、加固(畸形 canon 降级 absent)、对称回归(tag 不变的 repack 走既有分支)。bug 若回归,这些抓得住。
CI:此前 head 各 gate(kernel-guard / version-guard / config-surface-guard / docs-coverage / build / gates)均绿;本次仅追加一行注释修正,无任何行为变化。
已顺手修:src/session-resolve.ts 中 #5686 档的注释序号笔误——原文写「fifth rung」,实为 tagChanged 分支的第 6 个 reanchor 档(前五个依次是 selfCheckpoint / headAligns / model-switch / chain-continues / #4778),改为「sixth rung」;纯注释、零行为影响 + commit 535bb92。
PR #5851(#5844 repack-reanchor)审查完成:结论 APPROVE(通过)。独立审了正文 + 关联 issue #5844 + 完整 diff——方向关通过(修的是「延续证据通道太脆」的机制,非掩盖 413 症状)、回归逐项过(fragment 档逐字不变且优先 / msgid-rescue 未触碰 / tag-invariant 分支未触碰 / 分叉护栏由测试 2 钉住 / 快照 additive-only)、测试 6 个都有牙、文档准确且中英同步、范围干净(不碰 kernel/、无 version bump、无 config 面)。唯一有意行为变更(重打包+tagChanged+更短+canon 尾匹配 由 fork→reanchor)正是本 bug,PR 已披露 old→new。顺手小修: |
[bot] 🏷 PR #5851(#5844 repack-reanchor)审查完成,结论 APPROVE(通过)。
|
…doc-move conflict (#5844 section ported to docs/session-identity.md)
(ai: vllm-qwen/qwen3.8-27b) 本轮触发再次报告「PR 与 base 冲突(dirty)」。逐条活体核验后确认这次是真冲突,已解决并推送。七问如下: 1. 是什么问题:master 又前进了(cda6e73 → 58a8796,20+ 个合并,含 #5991/#5809/#5609/#5903/#5983 及文档布局迁移),PR 分支(上次已带到 cda6e73)与之产生新的文本冲突;另外作者在我上次推送后又补了一个提交 535bb92(修正 session-resolve.ts 注释里的 rung 序号),我的合并建在它之上、完整保留。 2. 什么原因导致的:master 按文档布局裁决把 3. 影响范围与严重程度:纯文档层冲突,不影响任何运行时行为;不解决则 PR 保持 dirty 无法进入合并。属于发布流程阻塞,非用户面缺陷。 4. 怎么修复的:union-of-intent 双向保留——根路径两文件恢复为 master 的重定向占位(遵循文档迁移裁决),PR 新增的两个章节逐字移植到迁后新址: 5. 是否有回归问题:逐项审过——① 合并带入的 master 侧变更本身已由 master CI 覆盖;② 我的人工干预仅两处文档文件:根占位与 6. 是否破坏缓存:不涉及——纯 git 合并 + 文档位置调整,未触碰压缩/缓存/会话存储逻辑。 7. 是否改了设计方向或引入新配置:不涉及——无设计转向、无新配置项。 收工判定:冲突已解,合并提交 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Re-review @ new head 223226db5 (supersedes my review at 535bb92).
Delta since my last reviewed head: the author merged origin/master (58a87962) into the branch → merge commit 223226db5. That pulls in ~39K lines of already-merged master work (master's own kernel/ bumps 0.0.185→0.0.192, the docs/ hub relocation, and many unrelated merged PRs) — none of it is this PR's contribution.
Isolating the PR's own change (git diff 58a87962..223226db5) = the same 4 files, byte-for-byte identical to what I approved in round 1:
src/session-resolve.ts— thecanonFpcontent-verified rung. Re-read the full hunk; logic unchanged (import ofneutralTurnCanonical,Recorded.canon?,canonFp(),CANON_FP_RE,OrderSkeletonEntry.canon?,record()setting canon, thecanonTailEquals()closure, the modified #5686 shorter-tail rung whose fragment-case reason string stays byte-identical, the additiveorderSnapshot()emit, and the validating/degradingapplyOrderSnapshot()).docs/session-identity.md(+45) /docs/session-identity.zh-CN.md(+15) — the #5844 section, relocated todocs/per master's docs-hub move (owner ruling #5920); en/zh still synced, content unchanged.tests/issue5844-repacked-tail-reanchor.test.ts(+170) — present.
My round-1 spot-fix (stale ordinal fifth→sixth rung, src/session-resolve.ts:503) survived the master-merge and remains accurate (5 reanchor rungs precede it in the tag-changed branch). This PR touches no kernel/ path — the kernel/ files in the raw 535bb92..223226db5 diff are master's, not the PR's — so the kernel authorization HARD-RULE does not apply.
CI on 223226db5: green — 30 checks, 18 success + 12 gated-skip (e2e lanes), 0 failure/error/stale; mergeable_state: blocked means awaiting review/merge only, not a CI failure.
结构化八问
- 是什么问题:宿主升级在同一轮里既换 system prompt 又重组 assistant 消息记录后,长会话被误分叉到空的
<id>|sub:<fp>车道,恢复时从零压整段历史而超时(#5844)。 - 什么原因导致:唯一可用的字节级延续证据绑定在「记录的物理切分」(per-source-message fragment) 上;宿主把消息重组进不同记录后 fragment 全变,而逻辑轮次其实逐字未变——证据通道太脆。
- 影响范围与严重程度:能用但体验毁灭(升级后 dsh 长会话直接坏掉、恢复超时 413)→ p1;触发条件为宿主同轮改 system prompt 且重组 assistant 记录布局(实测 dsh 0.2.1→0.2.2-rc.x)。
- 怎么修复的:在 #5686 更短尾档位补一条「内容校验」证据——按身份链自有的 canonical 形式(
neutralTurnCanonical,kind+逻辑文本/调用)比较最后 ≤8 轮;canonical 对记录重组不敏感、对内容变更敏感,命中即 reanchor 到原始 id 而非分叉;持久化加可选 canon 列(additive,hydrate 时校验,畸形降级回旧路径)。 - 是否有回归问题:无。fragment 档 reason 逐字不变且优先 / msgid-rescue 未触碰 / tag-invariant 分支未触碰 / 分叉护栏由测试钉住(改最终 tool-result cell 仍分叉)/ 快照 wire additive-only(旧文件可解析、canon 缺失=变更前行为)。
- 是否破坏缓存:不涉及(不动压缩/缓存/重试策略)。
- 是否改了设计方向:不涉及(沿用既有 tag-changed 逃生阶梯,只在 #5686 档补一种等强度证据)。
- 是否引入新配置:无(内部持久化字段,additive 自愈,无 config/env/CLI 面)。
结论:APPROVE。 属 session-key identity 逻辑,按 §7.4 需人工合入。(操作账号即作者 ranxianglei,GitHub 不允许对本账号 PR 置 approve 位,故以 review-comment 形式给出结论。)
[bot] 🏷 PR #5851 复审完成(新 head 223226d)。 说明:上一轮我已审过并给 APPROVE(head 增量核对结论:
结论维持 APPROVE(§7.4 session-key identity 逻辑需人工合入)。操作账号即作者,GitHub 不允许对本账号 PR 置 approve 位,已在 GitHub 以 review-comment 形式给出完整八问结论(review id 5850052912 → pull/5851)。 |
Closes #5844
Behavior change disclosure (old -> new + why)
Old behavior: when a host changes the system prompt text AND the message-record layout in the same turn (dsh 0.2.1 -> 0.2.2-rc.x does exactly this: assistant text segments merged into adjacent records, some standalone assistant records dropped), every byte-level continuation evidence is destroyed at once — per-source-message fragment hashes are disjoint even though every logical turn stays identical. All four
tagChangedescape rungs inresolveSessionOrdermiss structurally, so the conversation forks onto<id>|sub:<fp>with zero compression state; resuming such a session then dies with a fail-fast 413 (preflight folds the whole history from scratch — #5844: 32 rounds x ~26s > stream-idle timeout) and the parent's blocks sit unclaimed until manual surgery onsession-order.json.New behavior: at the #5686 rung site, a strictly shorter, kind-tail-aligned replay whose last <=TAIL_WINDOW(8) turns match the recorded skeleton turn-by-turn in canonical form (
neutralTurnCanonical— the identity chain's own hashing input) reanchors onto the raw id instead of forking. Canonical form survives how the host regroups messages into records (a merged text+tool_use record projects to the same canonical turn as split ones) but not content mutation, so the fork guardrail holds.Why this is sound: a canonical-turn match means the replayed tail IS the recorded conversation — forking it was a false positive. Both existing master rungs miss this shape by construction: #5686 still compares per-source-message fragments (disjoint after repack), #5719 requires host-stamped msgids with stored rows (sessions accumulated before stamping have an empty stored id set).
Mechanism
src/session-resolve.ts:canonFp()= sha256 of each turn'sneutralTurnCanonical; skeletons and the persisted snapshot gain an additive optionalcanoncolumn;applyOrderSnapshotvalidates elements against/^[0-9a-f]{64}$/and degrades a missing/malformed column to absent. The new condition!fragOk && canonTailEquals(n)joins the existingfragOkat the dsh Long-Session Drift Comprehensive Remediation: Sealing the Last Leak Window for Native Compression Local Deployment + | dsh 长会话漂移综合治理:堵死原生压缩本地落地的最后漏窗 + 会话身份分叉可见化与自愈 #5686 site; the fragment-case reason string stays byte-identical.SESSION-IDENTITY.md+ zh mirror): state plainly that NO supported command or config knob exists to re-attach a drifted lane to its parent, and give the sanctioned manual procedure (stop the proxy first — the daemon silently rewritessession-order.jsonfrom memory; set the parent entry'stagHashto the sha256 hex digest of the host's current full system text, or delete the entry; restart;bili sessions rm <id>|sub:<fp>). This answers the reporter's section-8 question.Honest boundary
A parent skeleton persisted by a PRE-FIX version carries no canon column, so the first post-upgrade request of an affected session can still fork (there is nothing to verify against yet). Recovery for those sessions = the documented manual procedure above, or the #5719 msgid rung when the host stamps ids and rows carry them; after one successful reanchor the skeleton permanently carries canon. Hosts that stamp msgids get automatic recovery without any manual step.
Regression audit (existing behaviors checked)
Scope honesty / related work
Same
|sub:-drift family, different shapes — cross-linked, none superseded: #5719 (full compaction intersecting tag drift), #5517 (checkpoint drift), #5714 (grown+shifted replay — needs subsequence alignment, still open), #5686 (fragment-tail predecessor). This PR covers the upgrade-repack variant only. The report's section-7 item 4 (fail-fast 413 message naming unclaimed parent blocks) lives in a different module (the preflight site) and is deliberately not bundled here.Config surface
None. No config/env/CLI changes; the skeleton snapshot field is internal persistence (additive, self-healing).
Review tier
Session-key identity logic => human review required per AGENTS.md section 7.4 (no auto-merge). No
kernel/change; no version bump (master stays at v0.1.212 until the release branch).