Skip to content

test: two-live-instance proofs over one sessions dir (#394/#405/#2401) - #2744

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-11_multi-instance-proofs
Oct 11, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-11_multi-instance-proofs

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follow-up to the consumer-path proof audit (m04170 "要搞 最好彻底的搞", big-item B). The multi-instance researcher pass found NO test anywhere spawns two real servers over one BILI_SESSIONS_DIR — the pool (session.ts module map) and SessionStore are per-process singletons, so one-process tests cannot simulate resident divergence. This PR adds that tier.

1. tests/multi-instance-live.test.ts (end-to-end, ~2s)

Spawns two child proxies (tests/fixtures/multi-instance-child.ts, each with its own pool + SessionStore, 30ms debounce) over ONE sessions dir + state dir, mock anthropic upstream, one shared session id. Phases:

  • A warms 3 turns → disk stats.requests === 3
  • B boots (boot-hydration), serves 2 turns → disk 5; B must warn #394 + "another bili instance" at registration
  • stale resident A turns (its counter 4 < disk 5): write REJECTED ("rejected stale snapshot")
  • A converges ([Bug][State] stale-write guard preserves newer disk record but stale resident keeps serving old in-memory fold state #2401) and its next write continues the DISK counter: exactly 6 — not its stale 5
  • B tie-turn end state: equal counters + equal nextBlockId → staleDiskPayload returns null → passthrough; disk stays 6 and stays valid
  • throughout, a 5ms reader loop asserts the envelope parses at every observed moment (atomic tmp+rename) and the counter never decreases; both children stay alive

2. tests/multi-instance-persist.test.ts (unit, two SessionStore over one dir)

  • interleave storm (120 rounds, lagging B writes every 6th): file valid at every sample, final = freshest lineage, stale warns present
  • documented residual pin — counter catch-up re-clobber (persist.ts:81-84): a lagging instance that catches up numerically (tie requests + tie nextBlockId) silently overwrites NEWER content. Pinned as CURRENT contract, explicitly not endorsed — this test turns red on purpose when someone tightens the guard (content fingerprints / writer epochs), forcing a conscious change
  • documented residual pin — content-store companion has no guard (saveContentStore): last writer wins; refs only the other instance stored vanish from disk (degraded retrieves, not main-record corruption)

Verification

  • new: 4/4 green (live ~1.8s, unit ~50ms), typecheck clean, build OK
  • adjacency on this branch: persist-rollback-guard 9/9, instance-governance 14/14, session-lock-concurrency 1/1 — 31/31 total

Config surface

None — no config keys, env vars, or CLI flags added; children use existing BILI_SESSIONS_DIR / XDG_STATE_HOME / BILI_PERSIST_DEBOUNCE_MS.

Kernel boundary

None — kernel/ untouched; host-side tests only.

Refs #394, #405, #2401.

- multi-instance-live: two spawned proxies share BILI_SESSIONS_DIR; pins
  serve-through-interleave, on-disk envelope always-valid + counter
  monotonic under a 5ms reader loop, stale-resident write rejection,
  convergence onto the disk lineage, and the tie-passthrough end state
- multi-instance-persist (unit, two SessionStore over one dir): interleave
  storm never rolls back; documented residual pins for counter catch-up
  re-clobber (persist.ts:81-84) and content-store companion last-writer-wins
  — these flip red intentionally when the guard is tightened
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_multi-instance-proofs (8f16a51)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3000-pr.2744.3c80b3d

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-pr2744.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

[bot] 🏷 收到。这是一个 [PR] review 任务(两实例同 dir 的 live proof + persist 单测)。我先核对分支代码、CI 状态与既有行为回归面,再按八问体例给结论。开始审查。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2744 review 结论:可合(recommend merge)

证据(本地定向验证,非全量——全量交 CI):在 PR tip d438768fc 建临时 worktree,npm ci(暖缓存)+ 构建 kernel/pi-subagents 后,只跑本 PR 的两个目标测试文件 + 直接 tsc --noEmit:

  • 新测试 4/4 绿:live ~3.7s · interleave storm 161ms · catch-up re-clobber pin 6.6ms · content-store pin 4.1ms;
  • typecheck 干净(顺带验证了 fixture 里 as ProxyOptions cast 与 Session shape 成立);
  • live 日志里确实看到跨两个子进程触发的 [persist] rejected stale snapshot … (#405/#2401) warn —— 守卫+收敛路径是被两个真进程打到的,不是 mock。worktree/临时产物已清理,主工作树未动。

结构化八问

  1. 是什么问题:补一个此前缺失的测试层——两个真实 bili proxy 进程共用一个 BILI_SESSIONS_DIR。不是修 bug,是填覆盖空洞。
  2. 什么原因导致的(缺口根因):pool(session.ts module map)与 SessionStore 都是单进程单例,单进程测试模拟不了「常驻实例分叉」;多实例 researcher pass 确认全仓没有任何测试 spawn 过两个真 server 共用一个 dir。ACP_PASSTHROUGH 一键静默关死全部压缩:无日志/无横幅/面板不可见且不可清除,同族 env 旋钮全部生效于无声 #405/[Bug][State] stale-write guard preserves newer disk record but stale resident keeps serving old in-memory fold state #2401/无单实例守卫:多个 bili 代理进程并存共写 sessions 目录,伴随孤儿 ref、有注册表无 transcript、计数自相矛盾的污染簇 #394 的守卫原先只有单进程单测覆盖。
  3. 影响范围与严重程度:纯测试,+493/-0,零生产代码改动 → 用户面零影响;严重度 N/A,只是把双实例守卫契约的信任度钉实。
  4. 怎么修复的:三个纯新增文件——(a) child fixture:spawn 一个可配置 proxy(MI_READY 握手、SIGTERM 优雅退出);(b) e2e live:A 预热→B boot→stale A 写被拒并收敛→A 续接磁盘计数器(3→5→6)→B tie,配 5ms reader loop 断言信封每刻可解析且计数器永不回退;(c) unit:同 dir 两个 SessionStore,interleave storm + 两个「文档化残余」pin(catch-up re-clobber、content-store last-writer-wins)。
  5. 是否有回归问题:无。未碰 src/kernel/wire/persistence/config。逐条核对源码与被测断言一致:staleDiskPayload 平局放行(persist.ts:677-690)、convergeToDisk 原地收敛、saveContentStore last-writer-wins、无单实例守卫:多个 bili 代理进程并存共写 sessions 目录,伴随孤儿 ref、有注册表无 transcript、计数自相矛盾的污染簇 #394 warn 文案(instance.ts:507);测试引用的行号(persist.ts:76-87 / :81-84)与当前源码精确对应,无文档漂移。相邻套件(persist-rollback-guard / instance-governance / session-lock-concurrency):纯测试 PR 未改其依赖的任何源码,故不受影响(作者报告 31/31 绿)。
  6. 是否破坏缓存:不涉及——未触碰任何 cache/retry/增量游标/去重逻辑(live 测试走压缩无关的极小 turn)。
  7. 是否改了设计方向:无。固化的是既有设计(newest-wins 守卫 + 收敛 + 刻意不做 election/lock);两个残余被显式 pin 为「当前契约、非背书」,将来有人收紧守卫(内容指纹/writer epoch)时该测试会故意翻红,强制一次有意识决策。方向未变。
  8. 是否引入新的配置:无。child 复用既有 BILI_SESSIONS_DIR / XDG_STATE_HOME / BILI_PERSIST_DEBOUNCE_MS,未新增任何 config/env/CLI。

判定:方向正确(正是「要搞最好彻底的搞」要点 B 要的那一层)、测试有牙(三个 unit 均非常态恒真断言,live 的 reader loop 是真并发牙)、引用准确、diff 干净(3 个纯新增文件,无跑题/无空行 churn)。建议合并,全量回归交 CI 把关。

@ranxianglei

Copy link
Copy Markdown
Owner Author

The test failures on this PR are not from this change — master itself is red on all four test legs since #2742 (93c53e8, rebase ref-floor pin): that PR's own head shows the same four failures (2 stale assertions in the #2658 rig kept pre-pin ref counts). This PR's diff touches only new files (tests/multi-instance-* + fixture); locally at 93c53e8 the #2658 file fails 2/6 and at its parent 251cb96 it is 6/6 green.

Fix queued in #2747 (2-line count update to the sibling rigs' N + ref-floor convention). Once it merges I'll rebase this branch so CI runs green.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,诊断与我的独立核对一致。

我这边的独立证据(上一轮 review 已核实):本 PR diff 纯新增文件(tests/multi-instance-live.test.ts + tests/multi-instance-persist.test.ts + tests/fixtures/multi-instance-child.ts,+493/-0),不碰任何 src/kernel/wire/persistence/config,也不碰 #2658 那个 rig——结构上就不可能是那四条 test leg 变红的原因。我又在 PR tip d438768fc 上定向跑过本 PR 的两个测试文件(4/4 绿)+ 直接 tsc --noEmit(干净),进一步坐实「红不来自本变更」。

结论维持:代码层面可合;CI 全绿等 #2747(#2658 rig 的 N + ref-floor 计数修正)合入后你 rebase 本分支即可。在此之前那四条 leg 的红是 master 既有状态(#2742 / 93c53e8 起),与本 PR 无关。

我这边待命:#2747 合入 + 你 rebase 之后,若要我复核(rebase 后相邻套件,或再跑一遍 #2658 确认 @93c53e8c 2/6 vs @251cb961 6/6),说一声即可。

@ranxianglei
ranxianglei merged commit b67d7d5 into master Oct 11, 2026
1 check passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.268-master.b67d7d5 (rolling master tag).

npm install -g billion-context@0.0.268-master.b67d7d5  # 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
ranxianglei deleted the 2026-10-11_multi-instance-proofs branch October 15, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant