Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): #6712 PR 4b a managed file import of the canonical file attests its page revision
garrytan4c882a3793fe
diff --git a/src/core/persistence/sync-pass.ts b/src/core/persistence/sync-pass.tsindex 3d81af04c5..73edd0cb0d 100644--- a/src/core/persistence/sync-pass.ts+++ b/src/core/persistence/sync-pass.ts@@ -151,7 +151,8 @@ async function readPages(exec: Exec, kind: 'postgres' | 'pglite', sourceId: stri/*** `A` for the given pages: whether the page's current revision came from a committed sync write of this incarnation (arm 1)- * and the hash its Git effect expects. A committed request and its effect never change, so this reads by the request id+ * and the hash its Git effect expects, or (a managed file import of the canonical file itself, `inputHash = targetHash`) the+ * hash of the file bytes it imported: either way the revision is file-backed. A committed request and its effect never change, so this reads by the request id* the snapshot returned, after the level is known; the answer is the one the snapshot would have given.*/async function readAttestations(exec: Exec, kind: 'postgres' | 'pglite', sourceId: string, incarnation: string, rows: PageRow[]): Promise<number> {@@ -163,8 +164,9 @@ async function readAttestations(exec: Exec, kind: 'postgres' | 'pglite', sourceIstatements++;const found = await exec.executeRaw<{ page_id: number; arm1: boolean; attested_hash: string | null }>(`SELECT x.page_id,(r.intent->>'kind' = ANY($3::text[]) AND r.source_incarnation::text=$2 AND (r.page_id IS NULL OR r.page_id=x.page_id)) AS arm1,- (SELECT e.data->>'expected_hash' FROM persistence_effects e WHERE e.request_id=r.id AND e.kind='git' AND e.revision=x.revision- AND e.data->>'expected_hash' IS NOT NULL AND (e.data->>'relative_path'=x.source_path OR right(e.data->>'relative_path', length(x.source_path)+1)='/'||x.source_path) LIMIT 1) AS attested_hash+ COALESCE((SELECT e.data->>'expected_hash' FROM persistence_effects e WHERE e.request_id=r.id AND e.kind='git' AND e.revision=x.revision+ AND e.data->>'expected_hash' IS NOT NULL AND (e.data->>'relative_path'=x.source_path OR right(e.data->>'relative_path', length(x.source_path)+1)='/'||x.source_path) LIMIT 1),+ CASE WHEN r.intent->>'kind'='managed_file_import' AND r.intent->>'sourcePath'=x.source_path AND r.intent->>'inputHash'=r.intent->>'targetHash' THEN r.intent->>'targetHash' END) AS attested_hashFROM unnest($4::int[], $5::uuid[], $6::uuid[], $7::text[]) AS x(page_id, request_id, revision, source_path)JOIN persistence_requests r ON r.id=x.request_id AND r.state='committed' AND r.source_id=$1`,[sourceId, incarnation, SYNC_WRITE_KINDS, chunk.map(row => Number(row.id)), chunk.map(row => row.request_id), chunk.map(row => row.revision), chunk.map(row => row.source_path)]);