Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Conversion evidence reads a file as written, so a retyped page the database then edited still adopts; bench seeds carry the current drift screen and a real database edit (GST-2568)

garrytanbc2b9fedd00d
diff --git a/scripts/bench/sync-convergence-seeded.ts b/scripts/bench/sync-convergence-seeded.ts
index 443326fe82..1069a3e419 100644
--- a/scripts/bench/sync-convergence-seeded.ts
+++ b/scripts/bench/sync-convergence-seeded.ts
@@ -35,7 +35,7 @@ import { preparePageAdmission, submitPageMutation } from '../../src/core/persist
import { declarePersistenceProtocol } from '../../src/core/persistence/protocol.ts';
import { disposePersistenceConsumer } from '../../src/core/persistence/service.ts';
import { performManagedSync } from '../../src/core/persistence/sync-run.ts';
-import { clearGitHold, readGitSourceHolds, SYNC_IMPORT_PROVENANCE_OP, writeGitHold } from '../../src/core/persistence/sync-holds.ts';
+import { clearGitHold, FILE_DRIFT_VERSION, readGitSourceHolds, SYNC_IMPORT_PROVENANCE_OP, writeGitHold } from '../../src/core/persistence/sync-holds.ts';
import { readShadowLevel, SYNC_ORIGIN_DELETED_OP, type ShadowLevel } from '../../src/core/persistence/sync-pass.ts';
import { buildConvergenceReceipt, type ConvergenceClassKey, type ConvergenceReceipt } from '../../src/core/persistence/sync-convergence.ts';
import type { SyncPathAction } from '../../src/core/persistence/sync-classify.ts';
@@ -285,7 +285,7 @@ export async function seedMix(brain: MixBrain): Promise<SeededCase[]> {
await engine.transaction(tx => writeGitHold(tx, { source_id: 'default', incarnation, path, source_path: path, slug: page.page.slug, page_id: Number(page.page.id), code,
message: `Synthetic ${code} hold.`, upstream_version: sha256(Buffer.from(note(titleOf(path), `A committed edit of ${titleOf(path)}.`))),
observed_at: new Date().toISOString(), run_id: null, mode: 'managed',
- meta: { recovery_version: RECOVERY_VERSION, blob_oid: oidAt(path), page_revision: page.revision, ...(code === 'file_drift' ? { sides: 'both' as const } : {}) } }));
+ meta: { recovery_version: RECOVERY_VERSION, blob_oid: oidAt(path), page_revision: page.revision, ...(code === 'file_drift' ? { sides: 'both' as const, drift_version: FILE_DRIFT_VERSION } : {}) } }));
}
// Stage 3f: open work. With the consumer stopped an admitted request stays queued (nothing after this awaits a write).
diff --git a/scripts/bench/sync-pass-memory.ts b/scripts/bench/sync-pass-memory.ts
index d1c1981d6a..a4a7070f39 100644
--- a/scripts/bench/sync-pass-memory.ts
+++ b/scripts/bench/sync-pass-memory.ts
@@ -138,7 +138,7 @@ async function seed(): Promise<void> {
await tx.executeRaw("INSERT INTO page_versions (page_id,compiled_truth,frontmatter,knowledge_revision,timeline,title,type,tags,is_deleted,source_path) "
+ "SELECT p.id,p.compiled_truth,p.frontmatter,p.knowledge_revision,p.timeline,p.title,p.type,(SELECT COALESCE(jsonb_agg(t.tag ORDER BY t.tag),'[]'::jsonb) FROM tags t WHERE t.page_id=p.id),false,p.source_path "
+ "FROM pages p WHERE p.id IN (" + ahead + ") AND COALESCE(p.body_storage,'inline')='inline'", [AHEAD]);
- const ids = await tx.executeRaw<{ id: string }>("UPDATE pages SET type='concept', frontmatter=frontmatter || jsonb_build_object('type','concept','legacy_type',type,'subtype','imported'), "
+ const ids = await tx.executeRaw<{ id: string }>("UPDATE pages SET type='concept', frontmatter=frontmatter || jsonb_build_object('type','concept','legacy_type',type,'subtype','imported','probe_label','database-ahead'), "
+ "knowledge_revision=gen_random_uuid(), revision_write_request_id=NULL WHERE source_id='default' AND id IN (" + ahead + ") RETURNING id::text", [AHEAD]);
await tx.executeRaw("DELETE FROM op_checkpoints WHERE op='sync-import-provenance' AND split_part(fingerprint, ':', 3) = ANY($1::text[])", [ids.map(row => row.id)]);
// Pages an older gbrain imported: equal to their files, with no import record.
diff --git a/src/core/persistence/git-gap.ts b/src/core/persistence/git-gap.ts
index 1d4f346c32..8fd1f93e0b 100644
--- a/src/core/persistence/git-gap.ts
+++ b/src/core/persistence/git-gap.ts
@@ -137,8 +137,12 @@ export function compareInlineExportFile(raw: Buffer, importPath: string, snapsho
return { state: 'differs', paths: classifyDrift(file.canonical, database).paths.map(p => p.path) };
}
-/** A committed file parsed the way reconcile parses a canonical file, aligned with the stored page (the census contract's file side). */
-function canonicalFile(raw: Buffer, importPath: string, page: ExportSnapshot['page']): { state: 'parsed'; canonical: ReturnType<typeof reconcileCanonical> }
+/**
+ * A committed file parsed the way reconcile parses a canonical file, aligned with the stored page (the census contract's file side).
+ * GST-2568: `retypeStamp` false reads a file naming the type a retype replaced as written, which content evidence needs: it
+ * compares the file with the page's older versions, and those predate the retype's stamp.
+ */
+function canonicalFile(raw: Buffer, importPath: string, page: ExportSnapshot['page'], retypeStamp = true): { state: 'parsed'; canonical: ReturnType<typeof reconcileCanonical> }
| { state: 'differs'; paths: string[] } | { state: 'unparseable'; reason: UnparseableReason } {
const text = raw.toString('utf8');
if (!Buffer.from(text).equals(raw)) return { state: 'unparseable', reason: 'not_utf8' };
@@ -146,7 +150,7 @@ function canonicalFile(raw: Buffer, importPath: string, page: ExportSnapshot['pa
const parsed = parseMarkdown(reading.content, `${page.slug}.md`, { validate: true, expectedSlug: page.slug });
if (parsed.errors?.some(e => !['MISSING_OPEN', 'EMPTY_FRONTMATTER'].includes(e.code))) return { state: 'unparseable', reason: 'frontmatter' };
if (parsed.slug !== page.slug) return { state: 'differs', paths: ['/slug'] };
- alignWithStored(parsed, page, reading.inferred);
+ alignWithStored(parsed, page, reading.inferred, retypeStamp);
return { state: 'parsed', canonical: reconcileCanonical(parsed, parsed.tags) };
}
@@ -496,7 +500,7 @@ export async function readDirectionEvidence(engine: BrainEngine, input: { source
const key = `${subject.id}:${blob.oid}`;
if (fileDigests.has(key) || !blobs?.has(blob.oid)) continue;
if (blob.oid !== subject.blob.oid && !older(subject).list.some(entry => entry.oid === blob.oid)) continue;
- const file = canonicalFile(blobs.get(blob.oid)!, subject.importPath, page);
+ const file = canonicalFile(blobs.get(blob.oid)!, subject.importPath, page, false);
fileDigests.set(key, file.state === 'parsed' ? digest(file.canonical) : null);
}
}