Repository navigation
fix: flush durable state before spawning self-restart replacement (#1724) - #1742
Conversation
) performSelfRestart (#811 opt-in self-restart) previously spawned the replacement and waited for it to bind the port (i.e. hydrate the shared store) BEFORE flushing this process's durable state in finish() — so the new process hydrated a stale snapshot and the old process's final flush was never read back: the lost-update / prefix-cache-busting race observed across an auto-update restart. Flush conversations + sessions + prefix-affinity to disk after the drain (state frozen: listener closed, in-flight 0) and before spawning the replacement; the port is already released so this adds no handover delay and abort paths are unchanged. Also add the missing flushPrefixAffinity() to defaultFinish (its debounced timer is unref'd, so pending affinity writes were silently dropped on self-restart), aligning the self-restart durable-state set with the normal shutdown path. Behavior change: durable-state flush now precedes the replacement spawn (was: only in finish, post-spawn). Opt-in path only (--auto-restart-on-update); default-OFF behavior unchanged. No wire/message-shape or config-surface change.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1690-pr.1742.48bcdb9This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1742.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review 完成,结论:可以合并。以下是按审查优先级走的完整记录。 核对方式:拉取分支 ① 原 issue 方向关:#1724 的根因是「新进程 hydrate 早于旧进程最终 flush」的重启竞态。本 PR 修的是 bili 完全自控的 #811 自重启路径——把 flush 提前到 spawn 之前,消除该路径上的乱序,是机制级修复(排序),不是症状掩盖。范围边界诚实:issue 观测事故走 ② 回归审查(既有行为清单)——diff 只碰
③ 代码关: ④ 测试有效性:新测试不是假测试——我做了 teeth 验证:把 ⑤ diff 整洁度:2 文件 +60/-0,每一行都和本 PR 目的相关,无跑题/空行/生成物。干净。 自动合并门核对:纯 fix、单模块、有回归测试且已验证有牙、rebased head 上绿、不碰 config schema/persistence/wire/cross-repo/update.ts/kernel pin —— 各项满足;合并动作本身留给你(系统规则禁止 agent merge)。 一句话中文摘要:修复了自动更新自重启(#811)路径上「新进程先 hydrate、旧进程后 flush」的状态丢失竞态——把 durable state flush 提前到 spawn 替换进程之前并补上 defaultFinish 漏掉的 prefix-affinity 持久化,仅影响 opt-in 自重启路径、默认行为不变,回归测试已验证对修复前代码会挂,CI 全绿,可以合并:#1742 |
…ianglei#1724) Record in TECHNICAL-NOTES (en/zh-CN) that all instances share one state dir whose control plane is lane-aware but whose data plane is not partitioned — no per-session owner, no per-lane isolation. State the two consequences (cross-instance session visibility in every instance's web UI; the restart drain race and its ranxianglei#1737/ranxianglei#1742/ranxianglei#405 mitigations) and the current security posture: only the admin loopback gate + filesystem permissions, i.e. no per-session authorization. Sufficient single-user, insufficient multi-user (must partition). Issue direction ranxianglei#5. Docs-only.
Part of #1724 (batch 2 — root-cause fix for the self-restart path). Not closing. Batch 1 (data-layer safety nets) is #1737; web-scoping + state-partitioning follow separately.
What & why
On an auto-update self-restart (
--auto-restart-on-update, #811),performSelfRestartpreviously did: drain → spawn the replacement → wait for it to bind the port → flush this process's durable state infinish(). The replacement hydrates the shared store as soon as it boots, so during that readiness wait it read a stale snapshot, and the old process's final flush was never read back — exactly the lost-update / prefix-cache-busting race in the issue's timeline (new process listening before the old one flushed).This PR flips the order: once the drain has confirmed state is frozen (listener closed, in-flight 0), it now flushes durable state to disk before spawning the replacement. The port is already released post-close, so this adds no handover delay; every abort path is unchanged (the flush is an idempotent write, in-memory state untouched).
Second gap fixed while here:
defaultFinish()omittedflushPrefixAffinity(). Its debounced persist timer isunref()'d, so any affinity writes still inside the debounce window were silently dropped on self-restart. Added — aligning the self-restart durable-state set with what the normal shutdown path persists.Behavior change (flagged)
finish, post-spawn). Opt-in path only (--auto-restart-on-update/ACP_AUTO_RESTART_ON_UPDATE/ configautoRestartOnUpdate); default-OFF behavior is unchanged.preSpawnFlush; reuses existingspawnImpl/finishseam pattern). No acp-kernel pin change.Scope note (honest boundary)
This fixes the one restart path bili fully owns (#811 self-restart). The issue's observed incident logged
parent-gone, i.e. the launcher/watchdog route, where hosts like dsh drive their bundled proxy's lifecycle through their own channel (#991) — that ordering is host-controlled and cannot be fully fixed from inside bili. Those paths are mitigated by the data-layer guards in #1737 (prefix-affinity union) plus the existing #405 session counter guard; a universal cross-host drain barrier needs host coordination and is left as a separate design decision.Pre-flight
27c8774a.performSelfRestart: durable state flush runs before the replacement spawns (#1724)asserts the pre-spawn flush strictly precedes the spawn (fails on the pre-fix code, where the only flush ran infinishafter the child booted).