Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): a classic full import notes committed progress per imported page (GBRA-133 PR 3a)

garrytana9d7b989106c
diff --git a/src/commands/sync/full.ts b/src/commands/sync/full.ts
index ff214858e1..bffbcca8b3 100644
--- a/src/commands/sync/full.ts
+++ b/src/commands/sync/full.ts
@@ -38,6 +38,7 @@ import {
type SlugRootMode,
} from '../../core/sync-anchor.ts';
import { buildPartialResult } from '../../core/sync-lock.ts';
+import { noteCommittedProgress } from '../../core/forward-progress.ts';
import {
MASS_RECONCILE_RATIO,
planReconcileDeletes,
@@ -131,7 +132,10 @@ export async function performFullSync(
// #5988: content refusals are held, not failed (never gating the bookmark).
onFileResult: async (path, filePath, fileResult) => {
noteScreenedImport(holds, path, fileResult);
- return await holdRefusedImport(engine, holds, path, filePath, fileResult) ? 'held' : undefined;
+ if (await holdRefusedImport(engine, holds, path, filePath, fileResult)) return 'held';
+ // GBRA-133 PR 3a: an imported page is committed work, so the sync deadline extends while a full import lands pages.
+ if (fileResult.status === 'imported') noteCommittedProgress();
+ return undefined;
},
});
if (opts.signal?.aborted) throw new ImportAbortError('interrupted', 1, result);
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 5f8e6dd80d..734da9c9bf 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -414,6 +414,7 @@ test/sync-exits-l4-6712.test.ts
test/sync-freshness-6858.test.ts
test/sync-frontmatter-recovery.test.ts
test/sync-frontmatter-slug-conflict.test.ts
+test/sync-full-committed-progress-gbra133.test.ts
test/sync-full-cursor-slices-6349.test.ts
test/sync-full-untracked-import-5459.test.ts
test/sync-group-member-order.test.ts
diff --git a/test/sync-full-committed-progress-gbra133.test.ts b/test/sync-full-committed-progress-gbra133.test.ts
new file mode 100644
index 0000000000..3ee2d9f092
--- /dev/null
+++ b/test/sync-full-committed-progress-gbra133.test.ts
@@ -0,0 +1,66 @@
+/**
+ * GBRA-133 PR 3a: a classic full sync (first sync, or --full) commits through runImport, so it must note committed
+ * progress for each page it imports. The sync hard deadline extends only on committed progress; without these notes a
+ * first sync of a large checkout that is importing steadily stopped at its deadline as `sync_deadline_stalled`.
+ * Protects: a full sync that imports pages notes committed progress once per imported page, and a full re-sync of an
+ * unchanged checkout notes none. Synthetic content only.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { execFileSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../src/core/engine.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { performSync } from '../src/commands/sync.ts';
+import { onCommittedProgress } from '../src/core/forward-progress.ts';
+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
+import { testBackends } from './helpers/test-backends.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
+const home = mkdtempSync(join(tmpdir(), 'gbrain-full-progress-'));
+const engines = new Map<string, BrainEngine>();
+let closePostgres: (() => Promise<void>) | undefined;
+
+beforeAll(async () => {
+ for (const backend of testBackends()) {
+ if (backend === 'pglite') { const pglite = new PGLiteEngine(); await pglite.connect({}); await pglite.initSchema(); engines.set(backend, pglite); }
+ else { const pg = await isolatedPersistencePostgres(process.env.DATABASE_URL!); engines.set(backend, pg.engine); closePostgres = pg.close; }
+ }
+ for (const engine of engines.values()) await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+}, 120_000);
+afterAll(async () => {
+ for (const engine of engines.values()) if (engine.kind === 'pglite') await engine.disconnect();
+ await closePostgres?.();
+ rmSync(home, { recursive: true, force: true });
+});
+
+for (const backend of testBackends()) {
+ describe(`a classic full sync notes committed progress per imported page (${backend})`, () => {
+ test('a first sync of 12 files notes 12 commits; a full re-sync of the unchanged checkout notes none', () => withEnv({ GBRAIN_HOME: home }, async () => {
+ const engine = engines.get(backend)!;
+ const repoPath = mkdtempSync(join(home, `repo-${backend}-`));
+ mkdirSync(join(repoPath, 'notes'), { recursive: true });
+ git(repoPath, 'init', '-q');
+ for (let i = 0; i < 12; i++) writeFileSync(join(repoPath, `notes/n${i}.md`), `---\ntype: concept\ntitle: Note ${i}\n---\n\nThe body of note ${i}.\n`);
+ git(repoPath, 'add', '-A');
+ git(repoPath, '-c', 'user.name=Example', '-c', '[email protected]', 'commit', '-qm', 'notes');
+ const sourceId = `full-${backend}`;
+ // One worker: parallel import workers connect to the configured database, not this test's isolated one.
+ const opts = { repoPath, sourceId, noPull: true, noEmbed: true, noExtract: true, concurrency: 1 };
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', [sourceId, repoPath]);
+ let commits = 0;
+ const off = onCommittedProgress(() => { commits++; });
+ try {
+ const first = await performSync(engine, opts as never);
+ expect(first.status).toBe('first_sync');
+ expect(first.added).toBe(12);
+ expect(commits).toBe(12);
+ commits = 0;
+ await performSync(engine, { ...opts, full: true } as never);
+ expect(commits).toBe(0);
+ } finally { off(); }
+ }), 120_000);
+ });
+}