Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

wip(#6712 PR 4b lane A): the pass row started_at comes from the database clock at pin (lane S effective)

garrytan0d8b8eae4be9
diff --git a/src/core/persistence/sync-pass-run.ts b/src/core/persistence/sync-pass-run.ts
index 0a7133b613..34af068cd2 100644
--- a/src/core/persistence/sync-pass-run.ts
+++ b/src/core/persistence/sync-pass-run.ts
@@ -265,12 +265,13 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
assertActive();
await assertDrainLease(tx, sourceId);
await tx.executeRaw('UPDATE sources SET last_sync_at=now() WHERE id=$1 AND incarnation=$2::uuid', [sourceId, incarnation]);
+ value.telemetry.started_at = await databaseNow(tx);
await writePassRow(tx, value, { pin: true });
}, principalAttribution(authority.writer.principal)));
await clearPassFailures(engine, sourceId, incarnation);
return { ...empty('up_to_date'), toCommit: remote ? '' : head, ...(inherited.length ? { inherited_options: inherited } : {}) };
}
- await engine.transaction(async tx => { await assertDrainLease(tx, sourceId); await writePassRow(tx, value, { pin: true }); });
+ await engine.transaction(async tx => { await assertDrainLease(tx, sourceId); value.telemetry.started_at = await databaseNow(tx); await writePassRow(tx, value, { pin: true }); });
assertActive();
const counts = { added: 0, modified: 0, deleted: 0, renamed: 0, chunks: 0, waivedImports: 0, waivedDeletes: 0, held: 0, pausedDeletes: 0, collisions: 0 };
@@ -436,6 +437,15 @@ export async function runSyncPass(engine: BrainEngine, input: SyncPassInput): Pr
}
}
+/**
+ * The pin's start time from the database clock: `sync.admission`'s `effective` compares it with `set_at` (the database's
+ * `clock_timestamp()`), so a host clock running ahead cannot make a restriction look effective early.
+ */
+async function databaseNow(tx: Pick<BrainEngine, 'executeRaw'>): Promise<string> {
+ const [row] = await tx.executeRaw<{ at: string | Date }>('SELECT now() AS at');
+ return new Date(row!.at).toISOString();
+}
+
/** A converged or idle pass clears what earlier stops recorded: the pass row's failure key and the incarnation's cursor key. */
async function clearPassFailures(engine: BrainEngine, sourceId: string, incarnation: string): Promise<void> {
await clearManagedSyncFailureAfterSuccess(engine, passFingerprint(sourceId, incarnation));