Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): #6712 PR 4b every pass round reads the pinned commit, never a HEAD that moved during the pass

garrytan46db7f9f0104
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index 97a1760e89..2f34a0c695 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -376,7 +376,7 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
assertActive();
value.telemetry.round = round;
const level = await readShadowLevel(engine, { sourceId, context, workingTree: mode === 'working',
- pass: { episodeFullId: episode?.full_id ?? null, retryConsumed: round > 1 ? retryConsumed : undefined, exclude: opts.exclude, includeHidden: opts.includeHidden, strategy: opts.strategy, bootstrap } });
+ pass: { head, episodeFullId: episode?.full_id ?? null, retryConsumed: round > 1 ? retryConsumed : undefined, exclude: opts.exclude, includeHidden: opts.includeHidden, strategy: opts.strategy, bootstrap } });
assertActive();
if (!level) throw new Error(`Source ${sourceId} became a company-brain source during its sync pass.`);
levelSlugMode = level.slugMode;
diff --git a/src/core/persistence/sync-pass.ts b/src/core/persistence/sync-pass.ts
index 6b25f13214..cd351818a3 100644
--- a/src/core/persistence/sync-pass.ts
+++ b/src/core/persistence/sync-pass.ts
@@ -56,6 +56,8 @@ export interface PassLevelInput {
* stored markers count.
*/
bootstrap?: boolean;
+ /** The commit the pass pinned (design §3.1): every round reads this level, never a HEAD that moved during the pass. */
+ head?: string;
}
/** PGLite's keyset page size (design v3.2 §2.1); Postgres reads `I⋈P` in one statement of its snapshot. */
const PGLITE_KEYSET_ROWS = 2_000;
@@ -285,7 +287,7 @@ export async function readShadowLevel(engine: BrainEngine, input: { sourceId: st
const gitPathOf = memo((origin: string) => { const o = originPath(origin); return slugMode === 'source-root' && scope ? `${scope}/${o}` : o; });
t = timer();
- const head = revParse(gitRoot, 'HEAD');
+ const head = input.pass?.head ?? revParse(gitRoot, 'HEAD');
if (!head) throw new Error(`source ${sourceId}: HEAD does not name a commit, so there is no level to read`);
// Master's rule (sync-discovery.ts): a detached HEAD forces working mode.
const detached = syncGit(gitRoot, ['rev-parse', '--abbrev-ref', 'HEAD']).trim() === 'HEAD';
diff --git a/test/sync-pass-live-6712.test.ts b/test/sync-pass-live-6712.test.ts
index 6c4e36215c..2bd766fc4f 100644
--- a/test/sync-pass-live-6712.test.ts
+++ b/test/sync-pass-live-6712.test.ts
@@ -22,6 +22,7 @@
* - a committed edit under a different uncommitted edit (committed mode) is held worktree_dirty, the page and the local
* file untouched, and the next pass settles instead of counting a not_converged streak; sync.holds=fail stops the run.
* - a page written straight to the database at a new file's slug is never overwritten by the file: held file_drift (side unknown).
+ * - a commit during a pass: every round reads the pinned level (no storage_error from a moved HEAD); the next pass takes the new commit.
* - probe 54: a pass intent keeps what the #6862 FIFO guard reads: a `managed_sync_` kind, the slug and page, and `renameFrom.slug`.
*
* Each test fails on capy/6712-pr4b (8cda2764b), where a non-company source still runs the cursor engine: the fences do not
@@ -303,6 +304,25 @@ describe('#6712 PR 4b live pass fences (pglite)', () => {
expect((await engine.executeRaw<{ source_path: string | null }>("SELECT source_path FROM pages WHERE source_id='default' AND slug IN ('notes/d','notes/e') ORDER BY slug")).map(row => row.source_path)).toEqual([null, null]);
}, { setup }), 180_000);
+ test('a commit landing during a pass: the pass finishes at its pinned level and the next pass imports the new commit', () => managedBrain(async ({ engine, root }) => {
+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
+ const pinned = (writeFileSync(join(root, 'notes/a.md'), note('notes/a', 'A committed change of notes/a.')), commit(root, 'change a'), git(root, 'rev-parse', 'HEAD'));
+ let moved = false;
+ installFaultHook(async (point, detail) => {
+ if (point !== 'consumer:prepared' || moved || detail.operation !== 'submit_job') return;
+ moved = true;
+ writeFileSync(join(root, 'notes/d.md'), note('notes/d', 'A file committed during the pass.')); commit(root, 'add d during the pass');
+ });
+ const during = await performManagedSync(engine, OPTS);
+ installFaultHook(undefined);
+ expect(moved).toBe(true);
+ expect({ status: during.status, to: during.toCommit }).toEqual({ status: 'synced', to: pinned });
+ expect((await engine.readPageSnapshot('notes/a', { sourceId: 'default' }))!.page.compiled_truth).toContain('A committed change of notes/a.');
+ const next = await performManagedSync(engine, OPTS);
+ expect({ status: next.status, to: next.toCommit }).toEqual({ status: 'synced', to: git(root, 'rev-parse', 'HEAD') });
+ expect((await engine.readPageSnapshot('notes/d', { sourceId: 'default' }))!.page.compiled_truth).toContain('A file committed during the pass.');
+ }, { setup }), 180_000);
+
test('probe 54: a pass intent keeps what the #6862 FIFO guard reads, renameFrom included', () => managedBrain(async ({ engine, root }) => {
expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
git(root, 'mv', 'notes/b.md', 'notes/renamed.md'); commit(root, 'rename b');