Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): an unknown snapshot on either side of a window is an unknown verdict (#6781)
garrytan3f2d31c2d228
diff --git a/src/core/persistence/sync-movement.ts b/src/core/persistence/sync-movement.tsindex 0655bdfd66..230bc7c307 100644--- a/src/core/persistence/sync-movement.ts+++ b/src/core/persistence/sync-movement.ts@@ -211,6 +211,7 @@ export function formatSourceMovement(m: SourceMovement): string | null {export type MovementVerdict = 'moved' | 'within_allowance' | 'held' | 'parked' | 'not_moving' | 'nothing_pending' | 'unknown';export function judgeMovement(before: SourceMovement | undefined, after: SourceMovement): MovementVerdict {if (after.movement_state === 'nothing_pending' || after.movement_state === 'unknown') return after.movement_state;+ if (before?.movement_state === 'unknown') return 'unknown';if (!before) return after.movement_state === 'moving' ? 'moved' : after.movement_state;if (after.last_commit_at && (!before.last_commit_at || after.last_commit_at > before.last_commit_at)) return 'moved';if (after.holds.last_hold_at && (!before.holds.last_hold_at || after.holds.last_hold_at > before.holds.last_hold_at)) return 'held';@@ -223,7 +224,9 @@ export function judgeMovement(before: SourceMovement | undefined, after: SourceMexport interface MovementWatch { stop(): void; tick(): Promise<void> }/*** The serve's ticker: reads movement every `everyMs` and logs one notice when a source flips to `not_moving`- * (and one recovery line when it moves again). Read failures are swallowed; the timer never keeps the process alive.+ * (and one recovery line when it moves again). Read failures are swallowed, and a source whose backlog read failed+ * (`unknown`, #6781) keeps its flip state, so a failed read neither repeats nor clears the notice; the timer never keeps+ * the process alive.*/export function startMovementWatch(engine: BrainEngine, opts: { log: (line: string) => void; everyMs?: number; setInterval?: typeof setInterval; clearInterval?: typeof clearInterval } ): MovementWatch {const flipped = new Set<string>();@@ -233,6 +236,7 @@ export function startMovementWatch(engine: BrainEngine, opts: { log: (line: striinflight = true;try {for (const m of await readSourceMovement(engine)) {+ if (m.movement_state === 'unknown') continue;if (m.movement_state === 'not_moving' && !flipped.has(m.source_id)) {flipped.add(m.source_id);opts.log(`[gbrain notice managed_sync_not_moving kind=degraded] ${formatSourceMovement(m)}\nnext: run ${m.writer_status_command} (read-only) and act on the running claim's next step.`);diff --git a/test/sync-movement.test.ts b/test/sync-movement.test.tsindex 149e3c26a0..a62015f8da 100644--- a/test/sync-movement.test.ts+++ b/test/sync-movement.test.ts@@ -419,6 +419,33 @@ describe('#6781: a failed backlog read is unknown, never nothing_pending', () =>} finally { await lock!.release(); await finish(f); }}), 60_000);+ test('a failed read between two not_moving ticks: the window verdict is unknown and the serve watch holds its flip (no false recovery, no repeat notice)', () => withEnv({ GBRAIN_HOME: home }, async () => {+ const f = await managedSource();+ await cursor(f, 2, 7, { progress: { startedAt: Date.now() - 400_000, startIndex: 0, lastAt: Date.now() - 300_000, lastIndex: 2 } });+ await request(f, 'committed', { completedAt: ago(300_000) });+ const flaky = { fail: false };+ const broken = failingBacklog(engine);+ const toggling = new Proxy(engine, { get: (t, prop) => { const src = flaky.fail ? broken : t; const value = Reflect.get(src, prop, src); return typeof value === 'function' ? value.bind(src) : value; } }) as typeof engine;+ const lines: string[] = [];+ const watch = startMovementWatch(toggling, { log: line => lines.push(line), everyMs: 3_600_000 });+ const lock = await tryAcquireDbLock(engine, syncLockId(f.id));+ try {+ const control = (await readSourceMovement(engine, { sourceIds: [f.id] }))[0]!;+ expect(control.movement_state).toBe('not_moving');+ const injected = (await readSourceMovement(broken, { sourceIds: [f.id] }))[0]!;+ expect(judgeMovement(injected, control)).toBe('unknown');+ const mine = () => lines.filter(line => line.includes(f.id));+ await watch.tick();+ expect(mine().filter(line => line.includes('kind=degraded'))).toHaveLength(1);+ flaky.fail = true;+ await watch.tick();+ flaky.fail = false;+ await watch.tick();+ expect(mine().filter(line => line.includes('moving again'))).toEqual([]);+ expect(mine().filter(line => line.includes('kind=degraded'))).toHaveLength(1);+ } finally { watch.stop(); await lock!.release(); await finish(f); }+ }), 60_000);+test('writer movement exits 1 with movement_unknown (never managed_sync_not_moving); --warn-only exits 0', () => withEnv({ GBRAIN_HOME: home }, async () => {const f = await managedSource();await cursor(f, 2, 7);