From 6f780f093c7bb60037014fc2f8264f3fcd7b60ed Mon Sep 17 00:00:00 2001 From: awork Date: Fri, 16 Oct 2026 12:32:44 +0800 Subject: [PATCH] fix(tests): pin AC12 restart shape with a synchronous persist barrier The simulated-restart strips mutated session memory directly while debounced saves were still armed; whichever snapshot a timer found at fire time became the record the next boot read. When the phase-2 boot adoption's debounce fired before the strip (event-loop span > debounce window, e.g. CI load), the child loaded WITH blocks at final boot and legally adopted the grandchild, closing its gate and tripping the derivedBlocksAdopted assertion. flushSync after each strip cancels the timer, writes the stripped record now, and bumps the commit fence against stale in-flight writes. Test-only; no runtime behavior change. --- tests/lineage-reconcile-boot.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/lineage-reconcile-boot.test.ts b/tests/lineage-reconcile-boot.test.ts index ad33f5db4e..6262f58107 100644 --- a/tests/lineage-reconcile-boot.test.ts +++ b/tests/lineage-reconcile-boot.test.ts @@ -7,7 +7,7 @@ import os from "node:os"; import path from "node:path"; import { defaultConfig } from "acp-kernel"; import { startServer } from "../src/server.ts"; -import { SessionStore, _setStoreForTest } from "../src/persist.ts"; +import { SessionStore, _setStoreForTest, getStore } from "../src/persist.ts"; import { listSessions } from "../src/session.ts"; import type { ProxyOptions } from "../src/config.ts"; import { _setForTest as setRegistryForTest } from "../src/registry.ts"; @@ -235,6 +235,12 @@ async function setupForkOnDisk(resumeInheritance?: boolean): Promise for (const b of child.state.blocks) child.blockContents.delete(b.blockId); child.state.blocks.length = 0; delete child.metadata.derivedBlocksAdopted; + // Pin the post-strip shape synchronously (#3336): an armed debounce + // timer from the request above would otherwise fire later and persist + // whichever in-memory snapshot it finds at fire time, leaking pre-strip + // state into the simulated restart below. Same for the parent's ledger. + assert.ok(getStore().flushSync(child), "post-strip persist of the fork child must land"); + assert.ok(getStore().flushSync(parent), "parent's folded ledger must be on disk before the restart"); return { run, @@ -446,6 +452,11 @@ test("AC12: a multi-hop grandchild stays eligible when its intermediate parent h for (const b of s.state.blocks) s.blockContents.delete(b.blockId); s.state.blocks.length = 0; delete s.metadata.derivedBlocksAdopted; + // Same #3336 pin as in setupForkOnDisk: the boot reconcile above + // adopted the child from the root and armed its debounce; without a + // sync flush here the final boot below could load the child WITH + // blocks and legally adopt the grandchild, closing its gate. + assert.ok(getStore().flushSync(s), `post-strip persist of ${id} must land`); } } finally { await close(proxy);