Repository navigation
fix: reject stale in-memory snapshots that would roll back persisted session state (#405) - #517
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-517Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr517.tgz
npm install -g packageThis comment is automatically updated on each push. |
收到。这是 #514 拆出的 persist 半边(拒绝回档快照),按规范先审核再下结论:先在 clean master 上核实回档问题真实存在、再逐行审 diff、跑完整 pre-flight(typecheck / test / build),结论稍后回贴。合并仍由人工操作。 |
审核通过(LGTM)。按规范先验证后下结论,过程与证据如下。 1. 问题审核:真实存在,且描述即根因
2. 方案评估:打到核心,且优于原建议#405 原建议比较 3. 逐点核查(均对照 acp-kernel 0.0.51 源码验证,非只看 diff)
4. Pre-flight(PR head b5bd813 本地实测)
5. 小问题(仅报告,不阻塞,按规范不另开 issue)
结论问题属实、根因判断正确、实现打到核心且设计优于原建议,pre-flight 全绿。LGTM,等人工 merge(合并是人工操作):#517 |
|
Review vs master 3cd85b6: ✅ concept sound + tests good — needs rebase (conflicts with #587's rewrite of Findings from the review pass:
Rebase notes (for me): (tracking: #598) |
…session state Dual-instance rollback guard (#405 fix #4, tracked in #598): when two bili processes share BILI_SESSIONS_DIR, the instance holding an older in-memory copy must not overwrite the fresher on-disk state. Monotonic signals (stats.requests, state.nextBlockId) prove staleness; a stale save is turned into a content-identical rewrite of the disk payload (keeping the newer state) with a throttled one-minute warn. Rebased onto master (v0.1.92 era): loadEnvelope() probe extracted from loadSync keeps the #408 negative-clamp reload path; constructor unifies this.log with the #373 PersistEpermAlert baseLog. Fixes #598
b5bd813 to
85f0780
Compare
|
Rebased onto master (single commit
Pre-flight: typecheck ✓ · persist suites 34/34 (rollback-guard 8, tail 5, eperm 11, proxy-persist 10) ✓ · full suite 1231/1233 (2 known plugin-agent env fails) ✓ · build ✓. Fixes #598 (rollback guard tracked there since the #405 split). |
[bot] 🏷 On it — re-verifying the rebased head |
[bot] 🏷 Re-verification of rebased head Structure: compare API confirms exactly 1 commit ahead of master, 0 behind; diff is precisely 2 files (+191/−21): Union resolutions verified against source:
A diff-of-diffs (pre-rebase contribution vs post-rebase contribution) shows only those two union points changed; Local pre-flight at One minor non-blocking note: your quoted counts don't reproduce from the pushed artifact — |
Closes #598 — tracking issue for this PR.
Split from #514 (fix 5 of 5, the other piece still unique — see review there). Addresses the dual-instance count fork (计数分叉) symptom at the heart of #403/#394 — persist-side only; the write-side was already fixed by the instance registry (#419). (Note: #514's body cited #405, but that issue is the unrelated ACP_PASSTHROUGH observability bug; no auto-close intended.)
Problem
When two proxy processes share
BILI_SESSIONS_DIR(the misconfiguration #394 warns about), whoever saves last wins. An instance holding a stale in-memory copy silently rolls the monotonic counters back — e.g. diskrequests: 3gets overwritten withrequests: 2, and block cursors regress the same way. Restarting the healthy instance then loads the regressed state.Fix
Every write entry point (
scheduleSave/writeNow/flushSyncin src/persist.ts) now builds throughguardedBuild:staleDiskPayloadloads the current disk record via the same envelope probe asloadSync(namespaced path,_unknown/fallback, kernel flat-legacy probe) and compares the two monotonic signals:stats.requests(v1 flat fallback included), thenstate.nextBlockIdon a tie. Either being strictly smaller proves the in-memory copy is stale.STALE_WARN_THROTTLE_MS).flushSyncof a stale snapshot still returnstrue: the disk already holds newer state, so memory eviction stays safe.Read paths are factored through a shared
loadEnvelopehelper so the guard andloadSynccan never disagree about where the record lives.Tests
tests/persist-rollback-guard.test.ts (6 tests): stale writeNow keeps disk + warns; tie-on-requests with older
nextBlockIdrejected; fresh snapshots pass through with no warning; staleflushSyncreturns true; warning throttled to once per window; debouncedscheduleSaveguarded too.Pre-flight
typecheck ✅ · full suite 1036/1038 (2 known plugin-agent env fails, unchanged baseline; +6 new tests) · build ✅