Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test: hot-check goldens check the rows-behind checkpoint against the fixture HEAD; classify the #8073 rollback write (#8071 #8073)

garrytana56b738889db
diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsv
index 40e24be55b..7f9a2f792a 100644
--- a/docs/architecture/canonical-writers.tsv
+++ b/docs/architecture/canonical-writers.tsv
@@ -54,6 +54,7 @@ src/core/company-brain/profile.ts 2 engine_guard Company-profile legacy deletes
src/core/company-brain/runtime.ts 1 projection Only source policy metadata advances under the company-source lock and brain/source row locks; the same transaction validates immutable approval and creates a receipt with source-incarnation and managed owner/topology fences, without source-file writes.
src/core/cycle/drift.ts 1 coordinator A managed brain preflights maintenance authority before judge spend and publishes the report through publishMaintenancePage; the unmanaged putPage stays behind the canonical table trigger.
src/core/cycle/extract-atoms.ts 1 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication.
+src/core/cycle/derived-write-through.ts 1 engine_guard #8073: when a derived batch commit is refused, the rollback clears only the source_path its own write bound (compare-and-set on that path, live rows only) so the next backfill rewrites the file; write-through runs only on unmanaged brains, and the canonical table trigger refuses the SQL on a managed brain.
src/core/cycle/extract-facts.ts 7 coordinator Managed and unmanaged reconciliation key rows by fence row number, update matched rows in place, expire and detach removed rows instead of deleting them, and expire fence-owned rows of soft-deleted pages; on a managed brain each changed page publishes a managed_maintenance_fence_facts request and each soft-deleted page a managed_maintenance_deleted_page_facts_expire request, whose preparers replan or recheck the deletion under the page key inside the coordinator publication.
src/core/cycle/extract-takes.ts 4 coordinator On a managed brain the DB-source walk publishes each fenced page that needs a change as a managed_maintenance_takes_reextract request whose preparer re-reads the page under its key and writes the canonical projection's superseded_by while leaving resolution columns untouched; the file walk and unmanaged brains keep direct SQL, which the trigger refuses on managed brains. Stale-row pruning deletes only takes whose rows left a cleanly parsed fence on a live page in the same source.
src/core/cycle/grade-takes.ts 1 coordinator A managed brain applies auto-resolutions through the coordinated takes_resolve page mutation; the unmanaged resolveTake stays behind the canonical table trigger.
diff --git a/test/doctor-hot-checks-golden.test.ts b/test/doctor-hot-checks-golden.test.ts
index 35ca8b1822..0ca84093c8 100644
--- a/test/doctor-hot-checks-golden.test.ts
+++ b/test/doctor-hot-checks-golden.test.ts
@@ -16,7 +16,7 @@ import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { defineNormalizer, expectGolden, expectNormalizerStable } from './helpers/golden.ts';
import { doctorJsonNormalizer, makeDoctorHome, networkAttempts, runGbrain, type DoctorHome, type GbrainRun } from './helpers/doctor-json-golden.ts';
-import { buildHotCheckFixture, editHotCheckFixture, HOT_CHECK_CLOCK, pgliteSql } from './helpers/doctor-hot-checks-fixture.ts';
+import { buildHotCheckFixture, editHotCheckFixture, HOT_CHECK_CLOCK, pgliteSql, stampFixtureHead } from './helpers/doctor-hot-checks-fixture.ts';
const DOCTOR = doctorJsonNormalizer();
const homes: DoctorHome[] = [];
@@ -39,6 +39,7 @@ async function capture(): Promise<Captures> {
await editHotCheckFixture(h, sql);
const second = await runGbrain(h, ['doctor', '--json', '--skills-dir', h.skillsDir]);
expect(networkAttempts(h)).toEqual([]);
+ for (const run of [first, second]) run.json = stampFixtureHead(run.json, h);
return { first, second };
}
diff --git a/test/e2e/doctor-hot-checks-golden.test.ts b/test/e2e/doctor-hot-checks-golden.test.ts
index 82f0e472d2..c4aca402a0 100644
--- a/test/e2e/doctor-hot-checks-golden.test.ts
+++ b/test/e2e/doctor-hot-checks-golden.test.ts
@@ -16,7 +16,7 @@ import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';
import { defineNormalizer, expectGolden, expectNormalizerStable } from '../helpers/golden.ts';
import { doctorJsonNormalizer, makeDoctorHome, networkAttempts, runGbrain, type DoctorHome, type GbrainRun } from '../helpers/doctor-json-golden.ts';
import { FENCE_TREND_OP } from '../../src/core/fence-repair/census-store.ts';
-import { buildHotCheckFixture, editHotCheckFixture, stampSoakDays, stampSyncDay, type Sql } from '../helpers/doctor-hot-checks-fixture.ts';
+import { buildHotCheckFixture, editHotCheckFixture, stampFixtureHead, stampSoakDays, stampSyncDay, type Sql } from '../helpers/doctor-hot-checks-fixture.ts';
import { SOAK_COUNTERS_OP } from '../../src/core/persistence/soak-counters.ts';
const DATABASE_URL = process.env.DATABASE_URL;
@@ -84,7 +84,7 @@ async function capture(adminUrl: string): Promise<PgCaptures> {
]).finally(() => db.end());
expect(stamped.length).toBe(1);
const day = stamped[0]!.day as string;
- for (const run of [first, second]) run.json = stampSoakDays(stampSyncDay(run.json, day, syncDays), soak.map(r => String(r.fingerprint)));
+ for (const run of [first, second]) run.json = stampFixtureHead(stampSoakDays(stampSyncDay(run.json, day, syncDays), soak.map(r => String(r.fingerprint))), h);
return { first, second, url, name };
}
diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
index 3cb4c27dc1..b979583551 100644
--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
@@ -3791,7 +3791,7 @@
},
{
"behind": 0,
- "checkpoint": "1c068d3facec1879b1763dd6f98d3849133473da",
+ "checkpoint": "<fixture-head>",
"complete": true,
"counts": {
"current": 18,
@@ -8672,7 +8672,7 @@
},
{
"behind": 0,
- "checkpoint": "1c068d3facec1879b1763dd6f98d3849133473da",
+ "checkpoint": "<fixture-head>",
"complete": true,
"counts": {
"current": 18,
diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
index c0791353ad..2a1c4acc2c 100644
--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
@@ -3794,7 +3794,7 @@
},
{
"behind": 0,
- "checkpoint": "1c068d3facec1879b1763dd6f98d3849133473da",
+ "checkpoint": "<fixture-head>",
"complete": true,
"counts": {
"current": 18,
@@ -8676,7 +8676,7 @@
},
{
"behind": 0,
- "checkpoint": "1c068d3facec1879b1763dd6f98d3849133473da",
+ "checkpoint": "<fixture-head>",
"complete": true,
"counts": {
"current": 18,
diff --git a/test/helpers/doctor-hot-checks-fixture.ts b/test/helpers/doctor-hot-checks-fixture.ts
index 80e6dfd817..d7b7c8e598 100644
--- a/test/helpers/doctor-hot-checks-fixture.ts
+++ b/test/helpers/doctor-hot-checks-fixture.ts
@@ -191,6 +191,28 @@ export function stampSyncDay(report: unknown, stamped: string, syncDays: readonl
return copy;
}
+export const FIXTURE_HEAD = '<fixture-head>';
+
+/**
+ * The fixture pins its commits' dates and identity, but a host's git can still rewrite the identity or append a
+ * trailer, so the commit id differs between machines. Doctor `sync_rows_behind_checkpoint` reports the source's
+ * checkpoint, which is that commit: this replaces exactly that field, and only after checking that each non-null
+ * `details.sources[].checkpoint` equals the fixture checkout's HEAD.
+ */
+export function stampFixtureHead(report: unknown, h: DoctorHome): unknown {
+ const head = execFileSync('git', ['-C', join(h.home, 'notes-src'), 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
+ const copy = structuredClone(report) as { checks?: Array<{ name: string; details?: { sources?: Array<{ checkpoint: string | null }> } }> };
+ for (const check of copy.checks ?? []) {
+ if (check.name !== 'sync_rows_behind_checkpoint') continue;
+ for (const source of check.details?.sources ?? []) {
+ if (source.checkpoint === null) continue;
+ if (source.checkpoint !== head) throw new Error(`sync_rows_behind_checkpoint checkpoint ${source.checkpoint} is not the fixture checkout's HEAD (${head})`);
+ source.checkpoint = FIXTURE_HEAD;
+ }
+ }
+ return copy;
+}
+
export const SOAK_DAY = '<soak-day>';
/**