Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): note why a trailing-commit skip may advance the checkpoint (#5777)
garrytan1b94fbe85cd4
diff --git a/src/core/persistence/sync-prepare.ts b/src/core/persistence/sync-prepare.tsindex a07c80f98d..3d88620623 100644--- a/src/core/persistence/sync-prepare.ts+++ b/src/core/persistence/sync-prepare.ts@@ -204,6 +204,7 @@ export async function prepareManagedSyncMutation(engine: BrainEngine, row: Write// working tree before its Git effect lands. When the newer working-tree bytes are the// current page itself, there is nothing to import and nothing to protect; the commit that// carries them is imported as a no-op by a later run.+ // The checkpoint may advance past the pinned commit's bytes because the working tree wins, as for any local edit.const working = renamed ? null : readSyncFile(root, p.path);if (!working || sha256(working) !== p.rawHash|| !sameCanonicalImport(base, parseMarkdown(working.toString('utf8'), row.slug, { activePack }))) {diff --git a/test/persistence-managed-sync.test.ts b/test/persistence-managed-sync.test.tsindex 2968365775..e8e1b8016e 100644--- a/test/persistence-managed-sync.test.ts+++ b/test/persistence-managed-sync.test.ts@@ -108,6 +108,27 @@ test('a pinned import that trails the current page and its working-tree bytes is}}),120_000);+test('after a trailing-commit skip, the commit that carries the page bytes imports as a no-op', async () => withEnv({ GBRAIN_HOME: home }, async () => {+ for (const engine of engines) {+ const current = '---\ntitle: Trailing note\n---\nThe page body the coordinator already published.\n';+ const pinned = '---\ntitle: Trailing note\n---\nThe body an earlier commit still carries.\n';+ const f = await fixture(engine, { 'notes/trailing.md': current });+ expect((await performManagedSync(engine, { sourceId: f.id, noPull: true })).status).toBe('first_sync');+ const path = join(f.root, 'notes/trailing.md');+ writeFileSync(path, pinned); commit(f.root, 'commit that trails the page'); writeFileSync(path, current);+ const before = await engine.readPageSnapshot('notes/trailing', { sourceId: f.id });+ expect((await performManagedSync(engine, { sourceId: f.id, noPull: true })).status).not.toBe('blocked_by_failures');+ const carried = commit(f.root, 'the queued Git effect lands');+ const result = await performManagedSync(engine, { sourceId: f.id, noPull: true });+ expect(result.status).not.toBe('blocked_by_failures'); expect(result.managedWrite).toBeUndefined();+ expect((await engine.executeRaw<{ last_commit: string }>('SELECT last_commit FROM sources WHERE id=$1', [f.id]))[0].last_commit).toBe(carried);+ const after = await engine.readPageSnapshot('notes/trailing', { sourceId: f.id });+ expect(after?.revision).toBe(before?.revision);+ expect(after?.page.compiled_truth).toContain('already published');+ expect(loadSyncFailures().filter(row => row.source_id === f.id)).toHaveLength(0);+ }+}),120_000);+test('interrupted cursor resumes its pinned target before a newer HEAD and never advances early', async () => withEnv({ GBRAIN_HOME: home }, async () => {for (const engine of engines) {const f = await fixture(engine, {'a.md':'First stable observation about engineering.\n','b.md':'Original second observation about engineering.\n'});