Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(crash-robot): count sync round seams in round slots so a requested fault is always reachable (#7124)

garrytan0563fa18d128
diff --git a/scripts/persistence/crash-robot.ts b/scripts/persistence/crash-robot.ts
index 7cd5dc236b..f1b1bcc893 100644
--- a/scripts/persistence/crash-robot.ts
+++ b/scripts/persistence/crash-robot.ts
@@ -207,11 +207,29 @@ const PER_REQUEST_SEAMS: ReadonlySet<FaultPoint> = new Set<FaultPoint>(['consume
* are claimed one after another, and `finish` waits for a claim pass after its probe, the last request (#6957), so
* every slot the count role saw comes again in the run.
*/
-/** How far this pass advances the seam's count: 1, 0 for a repeat of the same request at a per-request seam, the epochs passed at the claim seam. */
+/**
+ * #7124: a sync pass makes as many rounds as the schedule's races dictate: a direct write still in flight when round 1
+ * reads its level defers that page to a round of its own, so the same schedule makes 2 or 3 rounds per pass (a count role
+ * saw 7 `sync:level_chunk`, a cold run made 6 and its fault at #7 went unreached). These seams count in round slots: in
+ * each pass, the first time a seam (a chunk: of each Git read) is reached in round 1, and the first time in a later
+ * round. Every pass that made a round 1 with work makes a later round, its confirm round at least, so every slot comes
+ * again; `sync:batch_entries` counts in round 1 alone, since a later round has entries only when the race deferred one.
+ */
+const ROUND_SEAMS: ReadonlySet<FaultPoint> = new Set<FaultPoint>(['sync:round_start', 'sync:level_chunk', 'sync:level_result', 'sync:level_take',
+ 'sync:level_read', 'sync:confirm_parallel', 'sync:level_narrow', 'sync:batch_entries']);
+/** How far this pass advances the seam's count: 1, 0 for a repeat of the same request at a per-request seam or of a round slot, the epochs passed at the claim seam. */
export function seamCounter(): (point: FaultPoint, detail: FaultDetail) => number {
const seen = new Set<string>(), prepared = new Set<string>();
- let claimSlots = 0;
+ let claimSlots = 0, pass = 0, round = 0;
return (point, detail) => {
+ if (point === 'sync:round_start') { round = Number(detail.round); if (round === 1) pass++; }
+ if (ROUND_SEAMS.has(point)) {
+ if (point === 'sync:batch_entries' && round > 1) return 0;
+ const key = `${point}\u0000${pass}\u0000${round > 1 ? 'later' : 'first'}\u0000${detail.read ?? ''}`;
+ if (seen.has(key)) return 0;
+ seen.add(key);
+ return 1;
+ }
const request = detail.writeId ?? detail.requestId;
if (point === 'consumer:preparing' && request) prepared.add(request);
if (point === 'consumer:claiming') {
diff --git a/test/persistence-crash-robot.test.ts b/test/persistence-crash-robot.test.ts
index 72b808c3f0..a4af2fd110 100644
--- a/test/persistence-crash-robot.test.ts
+++ b/test/persistence-crash-robot.test.ts
@@ -432,6 +432,49 @@ process.stdout.write('{"event":"continued"}\\n');
} finally { child.kill('SIGKILL'); await child.exited; rmSync(dir, { recursive: true, force: true }); }
}, 90_000);
+ test('#7124: sync round seams count in round slots, so a run whose pass makes one round fewer still reaches every slot the count role saw', async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-crash-robot-rounds-'));
+ const path = join(dir, 'rounds.ts');
+ // Count role: the direct write lands mid-pass, so pass 1 defers its page to round 2 and confirms in round 3. Run: it
+ // lands before the pass, so pass 1 confirms in round 2. Pass 2 is the same in both. A large read arrives in two chunks.
+ writeFileSync(path, `import { faultPoint, installFaultHook } from ${JSON.stringify(join(import.meta.dir, '../src/core/persistence/fault-points.ts'))};
+import { robotFaultHook, seamCounter } from ${JSON.stringify(join(import.meta.dir, '../scripts/persistence/crash-robot.ts'))};
+const counted = seamCounter(); const counts: Record<string, number> = {};
+installFaultHook((point, detail) => { const advanced = counted(point, detail); if (advanced) counts[point] = (counts[point] ?? 0) + advanced; });
+const round = async (n: number, reads: string[], work: boolean) => {
+ await faultPoint('sync:round_start', { sourceId: 'robot-0', round: n });
+ for (const read of reads) await faultPoint('sync:level_chunk', { read });
+ await faultPoint('sync:level_read', { sourceId: 'robot-0', round: n });
+ if (work) await faultPoint('sync:batch_entries', { sourceId: 'robot-0' });
+};
+const pass = async (rounds: boolean[]) => { for (const [i, work] of rounds.entries()) await round(i + 1, i ? ['ls-files'] : ['ls-tree', 'ls-tree', 'ls-files'], work); };
+await pass([true, true, false]); await pass([true, false]);
+process.stdout.write(JSON.stringify({ event: 'counts', counts }) + '\\n');
+installFaultHook(robotFaultHook({ point: 'sync:level_chunk', nth: counts['sync:level_chunk'] }));
+await pass([true, false]); await pass([true, false]);
+process.stdout.write('{"event":"continued"}\\n');
+`);
+ const child = Bun.spawn([process.execPath, '--no-env-file', path], { stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' });
+ try {
+ const lines: Record<string, unknown>[] = [];
+ const reader = child.stdout.getReader(); const decoder = new TextDecoder(); let pending = '';
+ const deadline = Date.now() + 60_000;
+ while (lines.length < 2 && Date.now() < deadline) {
+ const chunk = await Promise.race([reader.read(), Bun.sleep(deadline - Date.now()).then(() => null)]);
+ if (!chunk || chunk.done) break;
+ pending += decoder.decode(chunk.value, { stream: true });
+ for (let newline = pending.indexOf('\n'); newline >= 0; newline = pending.indexOf('\n')) {
+ lines.push(JSON.parse(pending.slice(0, newline))); pending = pending.slice(newline + 1);
+ }
+ }
+ reader.releaseLock();
+ expect(lines).toEqual([
+ { event: 'counts', counts: { 'sync:round_start': 4, 'sync:level_chunk': 6, 'sync:level_read': 4, 'sync:batch_entries': 2 } },
+ { event: 'fault', point: 'sync:level_chunk', nth: 6, detail: { read: 'ls-files' } },
+ ]);
+ } finally { child.kill('SIGKILL'); await child.exited; rmSync(dir, { recursive: true, force: true }); }
+ }, 90_000);
+
test('#6957: finish waits for the claim pass after its probe, so the last claim epoch a count role sees is reached in every run', async () => {
await robotBrain(async ({ world }) => {
const counted = seamCounter(); const prepared = new Set<string>(); let slots = 0;