Skip to content

[PR] fix: persona conversation keys survive proxy restarts; management calls follow the fork holding cited refs (#3397) - #3405

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-16_fix-persona-restart-orphan
Oct 20, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-16_fix-persona-restart-orphan

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3397

Problem

A long dsh session's compress calls failed forever ("every ref is unknown to this session" / "All requested refs are above this session's highest ref") while brand-new sessions worked fine. The reporter's v0.1.197 log shows two mechanisms compounding into one symptom family:

F1 — restart race orphaned the accumulated compression state (root cause). The session-order resolver's recorded skeletons (src/session-resolve.ts) were process memory. Every proxy restart re-ran the cold-start race: whichever lane arrived first under the host id — the main conversation or a tagged shallow sidecar request (dsh's auto-review blob carries its own system) — claimed the raw key, and the winner FLIPPED across restarts. When the main conversation lost, all refs/blocks minted while it lived on its |sub: lane stayed there; post-restart it ran on the near-empty raw key, resends cited refs that existed only in the orphaned generation, and every compress failed forever. New sessions had no orphaned state → "新会话反而没事".

F2 — #2601's no-witness follow chased the chattiest fork. When a host-stamped management call resolved to a stale parent with no outbound witness, livePersonaDescendant picked the MOST RECENTLY ACTIVE |sub: descendant. dsh's review persona fires every few seconds while the owner conversation idles, so the follow landed on the sidecar's small ref space (log: 01:43:24 + 02:05:24 routed to …|sub:1ee4… — highest ref m00313, 0 blocks → FAILED; 01:56:51 routed to the owner via lineage witness → SUCCESS).

Fix

  • F1: persist the recorded skeletons to <state>/billion-context/session-order.json using the affinity-persist mechanics (debounced atomic write with fsync, merge-with-disk fresher-wins per id, LRU 1024 entries + 8 MiB byte budget, hydrate at boot, flush at shutdown and both in-process restart paths). Tag comparisons move to sha256 hashes so persisted records stay small regardless of system-text length. Resolution is now restart-stable: the main conversation keeps its key, sidecars keep their lanes; deep records still keep aux blobs off the raw key.
  • F2: when tool args cite refs (mNNNNN), the no-witness follow prefers descendants whose minted ref space can contain them; no citation or no fit → the recency pick (byte-identical pre-fix behavior in those cases). Content-blind, no per-client special cases.

Behavior changes (disclosed)

surface old new why
persona/conversation key resolution decided by the cold-start race each boot (winner could flip across restarts) stable across restarts via persisted skeletons the flip orphaned compression state → permanent compress failures (#3397)
management-call fallback routing (no witness) most recently active |sub: descendant ref-space-fit pick when args cite refs; identical pick otherwise the chatty sidecar beat the real owner every time
state dir contents — new best-effort file session-order.json (warn-only on I/O failure) persistence substrate for F1

No config/env surface added. No wire/protocol change. No kernel/ change.

Verification

Out of scope (tracked separately)

The same log also contains [storage] unified shadow DIGEST DRIFT … migration parity broken errors (the reporter runs BILI_STORAGE_UNIFIED shadow mode, so severity is telemetry-only). Different symptom AND different mechanism (unified-storage migration parity, not persona identity) → filed as its own issue with a 来源 marker rather than bundled here.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_fix-persona-restart-orphan (274470b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4296-pr.3405.2855801

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3405.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 是 #3397 的修复交付(单 commit,head 2026-10-16_fix-persona-restart-orphan,base master,6 文件 +551/-23)。检索 open+closed 无并列的「persona-key 持久化」或「no-witness 路由」PR;#3397 floor 3 已定位 F1/F2 两个机制,本 PR 与之逐条对应,是同一条线的交付而非并行重复。

开始 review:拉分支核对代码 → 定向测试 → CI 状态 → 按八问给结论。注意:改动落在 persona/会话身份路由(load-bearing,§7.4 human-only merge 域),我只审不合。

ranxianglei pushed a commit that referenced this pull request Oct 16, 2026
… redundant parse (#3405 review)

Review clean-up on #3405: hydrateOrderSkeletons() assigned a JSON.parse result
to an unused var whose only effect was throwing on a corrupt file (surfacing the
warn via the catch). Route through readDiskEntries()' null-vs-empty contract so
the corrupt-file warn is explicit and the file is read once instead of twice.
No behavior change: missing=no-op, corrupt=warn+empty (next flush heals), valid=import.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

结论:可合(人工合)。 代码正确、两个机制都打到根因、无回归;唯一红是 Windows 上一个与本 PR 无关的已知抖动测试(#3259),新 head CI 正在重跑确认。我已在本 PR 分支补了一个已验证的清理 commit(70b4c32db)。

审核独立性声明:以下八问是我独立读 PR head 的 diff、跑定向测试、查 CI 得出的,不是照抄 #3397 的结论;#3397 只作需求背景读。

① 审原 issue(方向) #3397 = 长 dsh 会话 compress 永久失败、新会话没事。作者定位 F1/F2 两个复合机制,方向对:F1 是根因(persona 锚点只在进程内存,重启后冷启动竞态翻转主对话的 key → 积累的 refs/blocks 被孤儿化),F2 是放大器(#2601 无 witness 兜底按「最近活跃」挑 fork,dsh 高频 sidecar 永远赢)。修的是根本原因,不是表面现象。✓

② 回归审查(既有行为逐项)

  • persona/conversation key 解析:旧=每次冷启动竞态定 winner(可能翻转);新=持久化骨架跨重启稳定 —— 这是要修的缺陷本身,披露充分;深记录仍把 aux blob 挡在 raw key 外(测试 A2 钉住)。✓
  • 管理调用无 witness 兜底路由:旧=livePersonaDescendant 取最近活跃 |sub:;新=有引用时优先 ref-space 能装下的 fork,否则回退旧选择。逐行核过:引用为 0 或无 fit 时 cands[0]=filter(保序)[0],与 pre-fix .find(lastSeen>parent) 结构完全等价(filter 保序,都取第一个满足谓词者);listSessions() 按 lastSeen 降序(src/session.ts:1076),所以 fit 路径也是确定性选「最近-且-fit」。无引用路径字节级不变,任何情况都不比 pre-fix 更差。✓
  • state 目录新增 session-order.json:best-effort,I/O 失败仅 warn 不阻塞请求/重启;降级(文件缺失)与升级(新特性首见)都干净。✓
  • ESM 循环 session-resolve↔order-persist:跨 import 只在函数体内使用,不在模块求值期,测试实际加载通过证明安全。✓
    高危模式逐项:无语义漂移、无 fail-fast 变吞错(持久化失败仍 warn-only)、无阈值/时序/输出格式漂移、无 wire/协议/kernel 变更。✓

③ 代码审查 逻辑正确:持久化复刻 affinity-persist 全套机制(debounced atomic fsync-before-rename、LRU+字节预算、fresher-wins 合并避免跨进程整文件覆盖);tag→sha256 让记录不随 system 文本长度膨胀,lane key 仍用 fp16(tag)(纯 tag 函数→重启稳定)。错误处理完整(坏文件降级+下次 flush 自愈)。无 as any/@ts-ignore/console.error;命名达意、无死代码(见下)、无魔法数字。✓

④ 测试有效性 真测试非假测试:F1 走真实持久化往返(flush→模拟重启→hydrate),含 pre-fix flip 特征刻画;F2 用真实 proxy rig 镜像 #2601 suite,断言 cited→owner fork / uncited→recency fallback(带 !includes(CHATTY) 硬断言,bug 回归抓得住)。4/4 过,邻居 issue2944/dsh-persona-fingerprint 21/21 过,本地 typecheck 干净。✓

⑤ diff 整洁度 6 文件每行都服务 F1/F2,无跑题文件、无锁文件 churn、无大段空行重排。干净。✓

我的补充(commit 70b4c32db,已 push): hydrateOrderSkeletons() 里 const parsed = JSON.parse(fs.readFileSync(file)) 是死变量——赋值后用不到,唯一副作用是在坏文件上抛错以触发 warn(直接删会静默丢告警)。改用下方 readDiskEntries() 的 null-vs-[] 契约:unreadable→显式 warn 「snapshot … is unreadable」+return,[]/array→applyOrderSnapshot。行为完全等价(缺失=no-op、坏文件=warn+空+下次 flush 自愈、正常=import),顺带少读一次盘。已验证:typecheck 干净、测试 3 打出新 warn 行、4/4 过。

CI: 原 head 0eb62217e 除一片外全绿;红的 windows-22-1 = not ok 831 retired stall guard … (#1706/#1714),tests/issue1452-socket-hardening.test.ts:405,duration_ms 63372,error 「first chunk should have flowed through」。这是 socket-hardening 的 stall-guard 计时测试(假上游发一个 chunk 后静默,等 2s 断言到达),在负载高的 Windows runner 上 2s 内没送达——纯环境抖动,与本 PR 的 persona/session-order/routing 毫无关系,且是已知 flake:#3259(closed,精确命中「retired-stall-guard 在 Windows node22 间歇失败,重跑即过」)+ #1770/#1697/#1607/#3279 同族。新 head 70b4c32db 的 ubuntu 三片已绿,windows-22-1(含该 flake)+windows-22-2+ubuntu-24 还在跑,预期重跑即过。

八问:

  1. 是什么问题:长 dsh 会话压缩永久失败(「every ref unknown」)而新会话正常——重启把主对话积累在某个 |sub: 上的 refs/blocks 孤儿化了,叠加管理调用被路由到错误 fork。
  2. 什么原因导致(分层):F1 根因=resolve 出的 persona 骨架只存进程内存,每次重启重跑冷启动竞态,主对话 vs 浅 sidecar 谁先到 raw key 翻一次,主对话输了就把历史 refs 落在旧 key;F2 放大=[Bug] dsh 会话反复 model/provider 切换时主对话迁移到 |sub:<fp> persona fork,宿主盖章的 compress/decompress/acp_status 仍解析在陈旧父 id —— ref 跨空间不可解析直至熔断 #2601 无 witness 兜底取「最近活跃」fork,高频 sidecar 每次工具调用都打、永远压过空闲 owner。两者叠加成同一症状家族。
  3. 影响范围与严重程度:所有跨 proxy 重启的长 plugin 模式会话(dsh/opencode/pi 等带 persona sidecar 的宿主)——重启后该会话 compress/decompress 全部永久失败,只能开新会话。严重(特定条件不可用:长会话+发生过重启+sidecar 抢过 raw key)。
  4. 怎么修复的:F1 把 resolve 出的骨架持久化到 <state>/session-order.json(复用 affinity-persist 原子写/LRU/fresher-wins/hydrate/flush 全套,tag 存 sha256 控体积)让解析跨重启稳定;F2 管理调用若 tool args 引用了 mNNNNN,优先路由到 minted ref 空间能容纳这些 refs 的 fork,无引用/无 fit 回退原「最近活跃」选择(字节级不变)。
  5. 是否有回归:无。persona key 从「每次翻硬币」变「跨重启稳定」(要修的缺陷本身,已披露);无 witness 路由在无引用/无 fit 时结构等价 pre-fix(逐行核过);持久化 I/O 失败仍 warn-only 不阻塞;无 wire/协议/kernel/config/env 变更。
  6. 是否破坏缓存:不涉及压缩缓存/重试/增量游标/去重键;persona key 反而更稳 → prefix 更不易被 key 翻转打断。
  7. 是否改了设计方向:否。仍在 session identity / persona fork 既有框架内,只是给 resolver 加持久化底座 + 给 no-witness 兜底加 ref-space 约束,未改边界/数据流方向。
  8. 是否引入新配置:否。无新 env/config/CLI flag;session-order.json 是内部状态文件(best-effort),非用户配置面。

收工判定:可合。 代码正确、根因到位、回归安全、测试有牙、diff 干净;唯一红是无关已知 flake(新 head 重跑中)。按 §7.4 属身份/会话绑定 load-bearing,由人工合——等 windows-22-1 那片转绿即可合(预期绿)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 更新(新 head 70b4c32db,含我的清理 commit): 全绿无失败。此前唯一的红 windows-22-1(socket-hardening stall-guard 计时测试)重跑即过 —— 印证了它是负载抖动而非本 PR 引入的回归(#3259 记录的已知 flake 行为)。现 30 success / 0 failure,仅剩 ubuntu-24 一片在收尾(原 head 上已绿,属例行分片)。

结论维持:可合(人工合)。 代码/回归/测试/diff 均过审,CI 实质全绿。按 §7.4 身份/会话绑定 load-bearing 由人工合即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

交叉备注(来自 #3648 审核):#3648(「active parent 门禁」,已审核可合)把 livePersonaDescendant 的候选准则从新鲜度换成出生顺序——仅当 fork.createdAt > parent.lastSeen(parent 在 fork 诞生后零流量)才允许 follow。本 PR rebase 到 master 后,其 F2 的候选过滤器与 recency fallback(cands[0])应继承该出生顺序门禁:否则 ref-fit 优先逻辑仍会在「active parent + 并行 fork」形状里选出一个不该跟的目标(#3647 事故形)。两者正交可组合:先门控候选集(#3648),再在合格候选内做 cited-ref 命中优先(本 PR)。当前分支与 master 冲突(dirty),rebase 时一并处理即可。

awork added 2 commits October 18, 2026 12:15
…route management calls to the fork that holds the cited refs (#3397)

The session-order resolver's recorded skeletons were process memory, so every proxy restart re-ran the cold-start race: whichever lane arrived first under the host id (the main conversation vs a tagged shallow sidecar request, e.g. dsh's auto-review blob) claimed the raw key, and the winner FLIPPED across restarts. When the main conversation lost, all accumulated compression state (refs/blocks) stayed under the key it lost; resends then cite refs that exist only in the orphaned generation and compress fails forever while brand-new sessions work fine (#3397).

F1: persist the recorded skeletons to session-order.json using the affinity-persist mechanics (debounced atomic write with fsync, merge-with-disk fresher-wins, LRU + byte budget, hydrate on boot, flush on shutdown/in-process restart). Tag comparisons move to sha256 hashes so persisted records stay small regardless of system-text length.

F2: #2601's no-witness management-call follow picked the MOST RECENTLY ACTIVE |sub: descendant. dsh's chatty sidecar persona fires every few seconds while the owner conversation idles, so the follow chased the sidecar's small ref space and died there. When tool args cite refs (mNNNNN), prefer a descendant whose minted ref space can contain them; no citation or no fit keeps the recency pick (byte-identical pre-fix behavior in those cases).

Behavior changes (disclosed):
- persona/conversation key resolution is now restart-stable (was: cold-start race decided it per boot)
- management-call fallback routing: raw-recency pick -> ref-space-fit pick when args cite refs (identical otherwise)
- new persistence file <state>/billion-context/session-order.json; no new config/env surface

Tests: tests/issue3397-persona-restart-stability.test.ts — restart-stability through the real persistence round trip, aux-lane isolation across restart, snapshot hygiene (fresher-wins merge, corrupt-file degradation), and an e2e ref-fit routing rig mirroring #2601.
… redundant parse (#3405 review)

Review clean-up on #3405: hydrateOrderSkeletons() assigned a JSON.parse result
to an unused var whose only effect was throwing on a corrupt file (surfacing the
warn via the catch). Route through readDiskEntries()' null-vs-empty contract so
the corrupt-file warn is explicit and the file is read once instead of twice.
No behavior change: missing=no-op, corrupt=warn+empty (next flush heals), valid=import.
@ranxianglei
ranxianglei force-pushed the 2026-10-16_fix-persona-restart-orphan branch from 70b4c32 to 274470b Compare October 18, 2026 04:18
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Conflict resolved. Rebased 2026-10-16_fix-persona-restart-orphan onto current master (was 195 commits behind), resolved the single textual conflict, force-pushed. New head: 274470b80. GitHub now reports the PR mergeable (checks pending on the new head).

The one conflict hunk (src/plugin.ts, livePersonaDescendant): master's merged #2950 (#2948 ref-less aux-lane guard) and this PR's #3397 both modified the same doc-comment block and signature. Resolved as the union of intent: kept #2948's note (candidates are pre-filtered by holdsRefs in personaDescendantsOf) plus #3397's note and the maxCited?: number parameter. No code-body changes were needed — the function body and all call sites auto-merged cleanly. Everything else (restart.ts / server.ts / session-resolve.ts hooks) auto-merged without conflict.

Verification on the rebased head: npm run typecheck clean · npm run build OK · targeted suites 28/28 pass (issue3397-persona-restart-stability, issue2948-aux-lane-lineage-guard, issue2601-persona-fork-lineage, dsh-persona-fingerprint, dsh-persona-continuity). Full-suite verdict is the CI lanes on 274470b80.


结构化八问

  1. 是什么问题:系统转发的上游 PR 冲突——[PR] fix: persona conversation keys survive proxy restarts; management calls follow the fork holding cited refs (#3397) #3405 分支落后 master 195 个提交且与基线分支文本冲突(merge state: dirty)。
  2. 什么原因导致的:两条并行改动落在同一位置——master 合入的 fix: persona-lineage follow requires candidates to hold refs (#2948) #2950(【Bug】livePersonaDescendant redirects host-stamped management calls to auto-review's aux lane (ref registry always empty) → manual compress of the entire session fails | 【Bug】livePersonaDescendant 把宿主盖章的管理调用重定向到 auto-review 的 aux lane(ref 注册表恒空)→ 手动 compress 整会话失效 #2948:无引用辅助通道守卫,给 personaDescendantsOf 加了 holdsRefs 过滤并扩写了注释)与本 PR 的 Compression fails in long sessions while new sessions work fine | 压缩失败.新会话反而没事 #3397(livePersonaDescendant 增加 maxCited 参数)同时改动了同一个注释块和函数签名。
  3. 影响范围与严重程度:仅本 PR 分支;合入前对用户零影响。严重度=调度阻塞(PR 无法合并),非产品缺陷。
  4. 怎么修复的:rebase 到当前 master;唯一冲突块按「双方意图取并集」手工解——保留 【Bug】livePersonaDescendant redirects host-stamped management calls to auto-review's aux lane (ref registry always empty) → manual compress of the entire session fails | 【Bug】livePersonaDescendant 把宿主盖章的管理调用重定向到 auto-review 的 aux lane(ref 注册表恒空)→ 手动 compress 整会话失效 #2948 的候选过滤说明 + 采纳 Compression fails in long sessions while new sessions work fine | 压缩失败.新会话反而没事 #3397 的注释与签名,函数体无需改动(自动合并正确)。本地定向验证:typecheck、build、5 个相关测试套件 28/28 全绿;全量回归交给推送头部的 CI。
  5. 是否有回归问题:无。冲突解决不触碰任何行为:【Bug】livePersonaDescendant redirects host-stamped management calls to auto-review's aux lane (ref registry always empty) → manual compress of the entire session fails | 【Bug】livePersonaDescendant 把宿主盖章的管理调用重定向到 auto-review 的 aux lane(ref 注册表恒空)→ 手动 compress 整会话失效 #2948 的 holdsRefs 预过滤保持生效,Compression fails in long sessions while new sessions work fine | 压缩失败.新会话反而没事 #3397 的引用匹配选择在无引用时回退到原 recency 选择(字节级同旧行为)。高危模式逐项过:无语义漂移、无阈值/时序/输出格式变化、错误处理路径未动。
  6. 是否破坏缓存:不涉及——解决未触碰任何缓存/重试/游标/去重逻辑。
  7. 是否改了设计方向:不涉及——纯冲突解决,无架构变更。
  8. 是否引入了新的配置:不涉及本次解决。(PR 本身的 session-order.json 持久化文件属原 PR 内容,未因 rebase 改变;无新增 env/config。)

判定:冲突已清,PR 恢复可合并状态;等 274470b80 上 CI 全绿后即可由人合并。

@ranxianglei
ranxianglei merged commit 78e5b58 into master Oct 20, 2026
72 of 111 checks passed
@ranxianglei ranxianglei changed the title fix: persona conversation keys survive proxy restarts; management calls follow the fork holding cited refs (#3397) [PR] fix: persona conversation keys survive proxy restarts; management calls follow the fork holding cited refs (#3397) Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.641-master.78e5b58 (rolling master tag).

npm install -g billion-context@0.0.641-master.78e5b58  # 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.

Compression fails in long sessions while new sessions work fine | 压缩失败.新会话反而没事

1 participant