Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(effects): the Git walk compares a mirrored page with the hash the mirror recorded at that revision, so a segmented file is measured once

garrytana36d82d3e4af
diff --git a/src/core/persistence/effect-journal.ts b/src/core/persistence/effect-journal.ts
index 1106d4d609..287aa66278 100644
--- a/src/core/persistence/effect-journal.ts
+++ b/src/core/persistence/effect-journal.ts
@@ -157,9 +157,10 @@ export function singleFileGitEffect(effect: PersistenceEffect): boolean {
* recovery records each one, `data.published`); a cursor position is no proof,
* since the mirror also passes pages it skipped or found without a file.
* `passed`: pages the mirror moved past without parking or awaiting a retry; it
- * never revisits them.
+ * never revisits them. `files`: the hash of the bytes the mirror wrote to each
+ * published page's file and the revision it rendered (`data.published_files`).
*/
-export interface MirrorGate { state: 'pending' | 'failed' | 'committed'; published: Set<string>; passed: Set<string> }
+export interface MirrorGate { state: 'pending' | 'failed' | 'committed'; published: Set<string>; passed: Set<string>; files: Map<string, { hash: string; revision: string }> }
/**
* Per request id, the gate of its withdrawal mirror: every mirror that has not
@@ -175,7 +176,8 @@ export async function mirrorGates(engine: SqlEngine, requestIds: readonly string
const after = data.after_slug;
const unfinished = new Set([...(data.parked ?? []).flatMap(entry => entry.slug ? [entry.slug] : []), ...(data.retry_slugs ?? [])]);
const passed = (data.targets ?? []).filter(target => after !== undefined && target.slug <= after && !unfinished.has(target.slug)).map(target => target.slug);
- return [request_id, { state: state === 'queued' || state === 'running' ? 'pending' : state, published: new Set(data.published ?? []), passed: new Set(passed) }];
+ return [request_id, { state: state === 'queued' || state === 'running' ? 'pending' : state, published: new Set(data.published ?? []), passed: new Set(passed),
+ files: new Map(Object.entries(data.published_files ?? {})) }];
}));
}
diff --git a/src/core/persistence/effect-model.ts b/src/core/persistence/effect-model.ts
index 478d8403fa..bc5a3a133c 100644
--- a/src/core/persistence/effect-model.ts
+++ b/src/core/persistence/effect-model.ts
@@ -84,7 +84,9 @@ export interface PersistenceEffect {
/** #5396: scan targets passed without a file publication (a sync-skip metafile, or a file with an uncoordinated local edit). */
skipped?: SkippedTarget[];
/** GBRA-130 A-12: pages whose file this withdrawal mirror rewrote, recorded by its recovery with the cursor step. */
- published?: string[] };
+ published?: string[];
+ /** The SHA-256 of the bytes this mirror wrote to each published page's file, at the page revision it rendered. */
+ published_files?: Record<string, { hash: string; revision: string }> };
state: 'queued' | 'running' | 'committed' | 'failed';
execution_token: string | null;
claim_expires_at: string | Date | null;
diff --git a/src/core/persistence/effect-recovery.ts b/src/core/persistence/effect-recovery.ts
index ee1a3da732..9a1a64c65f 100644
--- a/src/core/persistence/effect-recovery.ts
+++ b/src/core/persistence/effect-recovery.ts
@@ -281,10 +281,12 @@ export async function recoverEffectPublication(engine: BrainEngine, effect: Pers
await clearRecovery(tx, current);
// GBRA-130 A-12: the page's file now holds the mirrored bytes; Git may commit only pages recorded here.
const published = [...new Set([...(current.data.published ?? []), record.slug])];
- await tx.executeRaw(`UPDATE persistence_effects SET data=jsonb_set(data,'{published}',$2::text::jsonb) WHERE id=$1`, [current.id, JSON.stringify(published)]);
+ const publishedFiles = { ...current.data.published_files, [record.slug]: { hash: record.afterHash, revision: record.revision } };
+ await tx.executeRaw(`UPDATE persistence_effects SET data=jsonb_set(jsonb_set(data,'{published}',$2::text::jsonb),'{published_files}',$3::text::jsonb) WHERE id=$1`,
+ [current.id, JSON.stringify(published), JSON.stringify(publishedFiles)]);
// One page per transaction/cursor checkpoint bounds work and restart cost;
// a retried parked target is consumed without rewinding the cursor.
- await advanceEffectCursor(tx, { ...current, data: { ...current.data, published } }, record.slug);
+ await advanceEffectCursor(tx, { ...current, data: { ...current.data, published, published_files: publishedFiles } }, record.slug);
await hooks.boundary?.('before_mirror_commit');
}); } finally { releaseCapacity(); }
}
diff --git a/src/core/persistence/effects.ts b/src/core/persistence/effects.ts
index d5f2359b24..c908f9f79e 100644
--- a/src/core/persistence/effects.ts
+++ b/src/core/persistence/effects.ts
@@ -351,10 +351,12 @@ async function publishGitPage(engine: BrainEngine, effect: PersistenceEffect, bi
await finishPage(engine, effect, snapshot, { git: 'skipped', reason: 'db_only' });
return;
}
- // A page the mirror passed is committed only when its raw bytes are the mirror's rendering of the page as it is now.
- // A segmented page's rendering is measured from its segments (unreadPageFile), never held as one string.
- if (verdict === 'evidence' && (snapshot.page.deleted_at
- || persistenceFileHash(path) !== (content === null ? (await unreadPageFile(engine, snapshot, keep)).hash : fileContentHash(content)))) {
+ // A page the mirror passed is committed only when its raw bytes are the mirror's rendering of the page as it is now: the
+ // hash the mirror recorded writing at this revision, else the rendering measured now (a segmented page's from its
+ // segments, unreadPageFile, never held as one string).
+ const mirrored = attempt.gate?.files.get(snapshot.page.slug);
+ if (verdict === 'evidence' && (snapshot.page.deleted_at || persistenceFileHash(path) !== (mirrored?.revision === snapshot.revision ? mirrored.hash
+ : content === null ? (await unreadPageFile(engine, snapshot, keep)).hash : fileContentHash(content)))) {
await skipTarget(engine, effect, snapshot, 'withdrawal_not_mirrored');
return;
}