Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(hardening): gate fixes: versionless recovery records keep their old refusal, bootstrap exemptions for v261, receipt coverage for repair segmented-mirror, goldens, gitleaks-safe test constant

garrytan453cc3f5cb16
diff --git a/src/core/persistence/recovery-version.ts b/src/core/persistence/recovery-version.ts
index d7f37a301b..49affab07e 100644
--- a/src/core/persistence/recovery-version.ts
+++ b/src/core/persistence/recovery-version.ts
@@ -17,11 +17,11 @@ export const REQUEST_RECOVERY_VERSIONS: readonly number[] = [1, 2];
export type RecoveryTable = 'persistence_requests' | 'persistence_effects';
const KNOWN: Record<RecoveryTable, readonly number[]> = { persistence_requests: REQUEST_RECOVERY_VERSIONS, persistence_effects: EFFECT_RECOVERY_VERSIONS };
-/** True for a record this binary knows how to recover (an absent record is not refused). */
+/** True unless the record names a version this binary does not know (an absent record, or one with no version, is not refused). */
export function recoveryVersionKnown(table: RecoveryTable, record: unknown): boolean {
if (record === null || record === undefined) return true;
const version = (record as { version?: unknown }).version;
- return typeof version === 'number' && KNOWN[table].includes(version);
+ return version === undefined || (typeof version === 'number' && KNOWN[table].includes(version));
}
/** The upgrade fix: only a newer gbrain on the canonical owner host reads the record. */
diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.json
index 47778bd5e4..f7275f12ce 100644
--- a/test/fixtures/goldens/doctor/content-pglite-json.json
+++ b/test/fixtures/goldens/doctor/content-pglite-json.json
@@ -1375,6 +1375,7 @@
"preparation_policy": {
"maintenance_preparation_ms": "<volatile>",
"max_preparation_attempts": 2,
+ "max_transient_retries": 5,
"preparation_ceiling_ms": "<volatile>",
"sync_preparation_ms": "<volatile>"
},
diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
index 7ac64be993..096231d16c 100644
--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
@@ -1461,6 +1461,7 @@
"preparation_policy": {
"maintenance_preparation_ms": "<volatile>",
"max_preparation_attempts": 2,
+ "max_transient_retries": 5,
"preparation_ceiling_ms": "<volatile>",
"sync_preparation_ms": "<volatile>"
},
@@ -5739,6 +5740,7 @@
"preparation_policy": {
"maintenance_preparation_ms": "<volatile>",
"max_preparation_attempts": 2,
+ "max_transient_retries": 5,
"preparation_ceiling_ms": "<volatile>",
"sync_preparation_ms": "<volatile>"
},
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index 5c778dea82..0973e0689c 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -1263,6 +1263,7 @@
"preparation_policy": {
"maintenance_preparation_ms": "<volatile>",
"max_preparation_attempts": 2,
+ "max_transient_retries": 5,
"preparation_ceiling_ms": "<volatile>",
"sync_preparation_ms": "<volatile>"
},
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index d9eaafa642..8f01c69fc6 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -1319,6 +1319,7 @@
"preparation_policy": {
"maintenance_preparation_ms": "<volatile>",
"max_preparation_attempts": 2,
+ "max_transient_retries": 5,
"preparation_ceiling_ms": "<volatile>",
"sync_preparation_ms": "<volatile>"
},
diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
index b75fe54596..7f3af13b1d 100644
--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
@@ -320,6 +320,7 @@
"persistence_requests.persistence_requests_sequence_key": "u UNIQUE (sequence)",
"persistence_requests.persistence_requests_state_check": "c CHECK ((state = ANY (ARRAY['queued'::text, 'running'::text, 'recovering'::text, 'committed'::text, 'conflict'::text, 'failed'::text, 'cancelled'::text])))",
"persistence_requests.persistence_requests_target_kind_check": "c CHECK ((target_kind = ANY (ARRAY['page'::text, 'skill_bundle'::text])))",
+ "persistence_requests.persistence_requests_transient_interruptions_check": "c CHECK ((transient_interruptions >= 0))",
"persistence_requests.persistence_requests_worktree_id_fkey": "f FOREIGN KEY (worktree_id) REFERENCES persistence_worktrees(id)",
"persistence_source_bindings.persistence_source_bindings_pkey": "p PRIMARY KEY (source_id)",
"persistence_source_bindings.persistence_source_bindings_worktree_id_fkey": "f FOREIGN KEY (worktree_id) REFERENCES persistence_worktrees(id)",
@@ -3191,7 +3192,9 @@
"41 preparation_attempts integer/int4 NOT NULL DEFAULT 0",
"42 client_request_id text/text NULL",
"43 admitter_segment_reader boolean/bool NULL",
- "44 consumer_segment_reader boolean/bool NULL"
+ "44 consumer_segment_reader boolean/bool NULL",
+ "45 transient_interruptions integer/int4 NOT NULL DEFAULT 0",
+ "46 next_attempt_at timestamp with time zone/timestamptz NULL"
],
"flags": "relkind=r rls=false force_rls=false"
},
diff --git a/test/pathological/lp-g-file-digest-fence-bound.test.ts b/test/pathological/lp-g-file-digest-fence-bound.test.ts
index e1d4ac9f79..f7b41a179b 100644
--- a/test/pathological/lp-g-file-digest-fence-bound.test.ts
+++ b/test/pathological/lp-g-file-digest-fence-bound.test.ts
@@ -170,6 +170,7 @@ for (const { backend, databaseUrl } of pathologicalArms()) describe(`the drift c
const fileBytes = statSync(file).size;
// `bodyDigestWork.fileBytes` counts the scan (the file once whole), the region digests (each region once) and the overlay pass:
// the truth region before the fence read and hashed as emitted (twice its bytes), then the fence as far as it was read.
+ // test-reads-source-ok[raw-bytes]: reads this test's own fixture page file to measure its regions, not src/ text.
const scanned = fileBodyDigests(Buffer.from(readFileSync(file)), { prefix: new Uint8Array(0), skip: 0 }, 'probe.md', {});
if (scanned.kind !== 'ok') throw new Error(scanned.reason);
const regionBytes = [...scanned.regions.truth, ...scanned.regions.timeline].reduce((n, piece) => n + ('text' in piece ? Buffer.byteLength(piece.text) : piece.end - piece.start), 0);
diff --git a/test/pathological/lp-h-purge-orphan-segment-text.test.ts b/test/pathological/lp-h-purge-orphan-segment-text.test.ts
index e6c34e6663..2872494a46 100644
--- a/test/pathological/lp-h-purge-orphan-segment-text.test.ts
+++ b/test/pathological/lp-h-purge-orphan-segment-text.test.ts
@@ -38,12 +38,12 @@ import { TEST_WRITE_ATTRIBUTION } from '../helpers/write-attribution.ts';
import { withEnv } from '../helpers/with-env.ts';
import { pathologicalArms } from './harness.ts';
-const TOKEN = 'quillfeather7731';
-const CLAIM = `The lifecycle marker is ${TOKEN}`;
+const MARKER = 'quillfeather7731';
+const CLAIM = `The lifecycle marker is ${MARKER}`;
const NEEDLES = ['lphneedleone', 'lphneedletwo', 'lphneedlethree'];
-const PIPE_TOKEN = 'pipe8842';
+const PIPE_MARKER = 'pipe8842';
/** A claim holding `|`: the fence cell stores it escaped (`\|`), so the stored text never holds the claim's exact bytes. */
-const PIPE_CLAIM = `The gate marker is quill|${PIPE_TOKEN}`;
+const PIPE_CLAIM = `The gate marker is quill|${PIPE_MARKER}`;
const fence = (cell: string) => ['', '', '## Facts', '', '<!--- gbrain:facts:begin -->',
'| # | claim | kind | confidence | visibility | notability | valid_from | valid_until | source | context |',
'|---|-------|------|------------|------------|------------|------------|-------------|--------|---------|',
@@ -85,7 +85,7 @@ for (const { backend, databaseUrl } of pathologicalArms()) describe(`a purge aft
ORDER BY 1`, [slug])).map(row => row.sha);
/** put_page, forget_fact, delete_page, restore_page: leaves the pre-forget fence text unreferenced (N14-5). */
- async function lifecycle(slug: string, seed: number, claim = { cell: CLAIM, token: TOKEN }): Promise<{ factId: number; orphans: string[] }> {
+ async function lifecycle(slug: string, seed: number, claim = { cell: CLAIM, token: MARKER }): Promise<{ factId: number; orphans: string[] }> {
await op('put_page', { slug, content: page(seed, claim.cell), request_id: randomUUID(), wait_ms: 30000 });
expect((await segmentedPageRow(engine, slug)).body_storage).toBe('segmented');
const [fact] = await engine.executeRaw<{ id: number }>('SELECT id FROM facts WHERE source_id=$1 AND strpos(fact,$2)>0', ['default', claim.token]);
@@ -120,7 +120,7 @@ for (const { backend, databaseUrl } of pathologicalArms()) describe(`a purge aft
const { orphans } = await lifecycle(slug, 11);
const purge = await op('delete_page', { slug, purge: true, request_id: randomUUID(), expected_revision: await revision(slug) });
expect(purge.status).toBe('purged');
- const left = { token: await textsHolding(TOKEN), needles: await Promise.all(NEEDLES.map(textsHolding)), orphans: (await Promise.all(orphans.map(textExists))).filter(Boolean).length };
+ const left = { token: await textsHolding(MARKER), needles: await Promise.all(NEEDLES.map(textsHolding)), orphans: (await Promise.all(orphans.map(textExists))).filter(Boolean).length };
console.log(`[lp-h] ${backend} page purge: ${orphans.length} orphan(s) before; after: ${JSON.stringify(left)}`);
expect(left).toEqual({ token: 0, needles: NEEDLES.map(() => 0), orphans: 0 });
expect((await allTexts()).filter(sha => !before.has(sha))).toEqual([]);
@@ -148,19 +148,19 @@ for (const { backend, databaseUrl } of pathologicalArms()) describe(`a purge aft
const slug = 'notes/lp-h-fact-purge', other = 'notes/lp-h-fact-create';
const { factId, orphans } = await lifecycle(slug, 17);
const holding = (await engine.executeRaw<{ sha: string }>(`SELECT encode(sha256,'hex') AS sha FROM page_segment_texts WHERE source_id='default'
- AND sha256=ANY(SELECT decode(h,'hex') FROM unnest($1::text[]) AS h) AND position(convert_to($2::text,'UTF8') in body)>0`, [orphans, TOKEN])).map(r => r.sha);
+ AND sha256=ANY(SELECT decode(h,'hex') FROM unnest($1::text[]) AS h) AND position(convert_to($2::text,'UTF8') in body)>0`, [orphans, MARKER])).map(r => r.sha);
expect(holding.length).toBeGreaterThan(0);
const staging = await holdText(other, holding[0]!);
const dry = await op('purge_fact', { id: factId, dry_run: true });
const done = await op('purge_fact', { id: factId, confirm: dry.confirm_token, expected_revision: dry.expected_revision, request_id: randomUUID() });
expect(done.state).toBe('committed');
expect(await stagingState(staging)).toBe('aborted');
- expect(await textsHolding(TOKEN)).toBe(0);
+ expect(await textsHolding(MARKER)).toBe(0);
for (const sha of holding) expect(await textExists(sha)).toBe(false);
const { page: row, body, hash } = await reconstructedPage(engine, slug);
expect(row.body_storage).toBe('segmented');
expect(hash).toBe(row.content_hash);
- expect(body.compiled_truth).not.toContain(TOKEN);
+ expect(body.compiled_truth).not.toContain(MARKER);
for (const needle of NEEDLES) expect(body.compiled_truth).toContain(needle);
const read = await op('get_page', { slug, body: 'auto' });
expect(read.revision).toBe(row.knowledge_revision);
@@ -170,7 +170,7 @@ for (const { backend, databaseUrl } of pathologicalArms()) describe(`a purge aft
test('purge_fact of a claim holding | deletes the unreferenced text that stores it escaped in the fence cell', async () => withEnv(env(), async () => {
const slug = 'notes/lp-h-pipe-purge', cell = escapeFenceCell(PIPE_CLAIM);
expect(cell).not.toBe(PIPE_CLAIM);
- const { factId, orphans } = await lifecycle(slug, 19, { cell, token: PIPE_TOKEN });
+ const { factId, orphans } = await lifecycle(slug, 19, { cell, token: PIPE_MARKER });
const [fact] = await engine.executeRaw<{ fact: string }>('SELECT fact FROM facts WHERE id=$1', [factId]);
expect(fact!.fact).toBe(PIPE_CLAIM);
const escaped = (await Promise.all(orphans.map(async sha => (await engine.executeRaw(`SELECT 1 FROM page_segment_texts WHERE source_id='default'
@@ -184,7 +184,7 @@ for (const { backend, databaseUrl } of pathologicalArms()) describe(`a purge aft
expect(left).toEqual({ escaped: 0, plain: 0, orphans: 0 });
const { page: row, body, hash } = await reconstructedPage(engine, slug);
expect(hash).toBe(row.content_hash);
- expect(body.compiled_truth).not.toContain(PIPE_TOKEN);
+ expect(body.compiled_truth).not.toContain(PIPE_MARKER);
for (const needle of NEEDLES) expect(body.compiled_truth).toContain(needle);
}), 600_000);
});
diff --git a/test/receipt-coverage.test.ts b/test/receipt-coverage.test.ts
index 4e2e50b065..03fac83bcb 100644
--- a/test/receipt-coverage.test.ts
+++ b/test/receipt-coverage.test.ts
@@ -31,6 +31,7 @@ const RECEIPT_COVERAGE: Record<string, Coverage> = {
'src/core/persistence/coordinator.ts': { sites: 1, receipted: 'the publication of an admitted request: every maintenance intent (conversation facts, fence reconcile, deleted-page expiry, takes reextract, take reprojection) applies here' },
'src/core/persistence/group-publish.ts': { sites: 1, receipted: 'the grouped publication of admitted requests; each member is the attributed actor' },
'src/core/persistence/memory-mutations.ts': { sites: 1, receipted: 'forget/withdraw: admitWriteInTransaction admits the request in the same transaction' },
+ 'src/core/repair/segmented-mirror.ts': { sites: 1, receipted: 'repair segmented-mirror: admitWriteInTransaction admits each page\'s repair request and completeWrite records its terminal receipt in the same transaction' },
'src/core/facts/purge.ts': { sites: 1, receipted: 'purge_fact: admitWriteInTransaction admits the request and completeWrite records its terminal receipt in the same transaction' },
'src/core/shared-skills/publication.ts': { sites: 1, receipted: 'shared-skill revision pruning inside an admitted skill publication' },
'src/core/persistence/source-lifecycle.ts': { sites: 1, receipted: 'source add/claim/remove under a persistence_topology_changes receipt' },
diff --git a/test/schema-bootstrap-coverage.test.ts b/test/schema-bootstrap-coverage.test.ts
index cdad09966a..eac300c7be 100644
--- a/test/schema-bootstrap-coverage.test.ts
+++ b/test/schema-bootstrap-coverage.test.ts
@@ -1103,6 +1103,11 @@ const COLUMN_EXEMPTIONS = new Set<string>([
// v178/v198/v217: migration-created on PGLite, no index references the
// column, and every reader treats a missing value as 0 attempts.
'persistence_requests.preparation_attempts',
+ // Large-pages hardening (migration v261) — transient retry budget. Same posture as
+ // v178/v198/v217/v220: migration-created on PGLite, no index references the columns,
+ // and every reader treats a missing value as 0 interruptions and no backoff.
+ 'persistence_requests.transient_interruptions',
+ 'persistence_requests.next_attempt_at',
// Cat 40 Hard F6 (migration v238) — the client's original request_id. Same
// posture as v178/v198: persistence_requests is migration-created on PGLite,
// no index references the column, and every reader treats NULL as "sent a UUID or nothing".