Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): hold rows never store a declared slug; fail-closed fixtures pin sync.holds=fail (#5988)

garrytan7ffda48ead81
diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsv
index 0242b85705..6dad6be429 100644
--- a/docs/architecture/canonical-writers.tsv
+++ b/docs/architecture/canonical-writers.tsv
@@ -22,6 +22,7 @@ src/commands/sources.ts 10 coordinator Managed add/archive/restore/remove/purge/
src/commands/sync/deletes.ts 1 coordinator Managed Markdown sync routes to immutable page requests and an exhausted-cursor checkpoint; unsupported Git pull, code/image and connector paths refuse early. (Refactor wave 1: moved from src/commands/sync.ts.)
src/commands/sync/preflight.ts 1 coordinator Managed Markdown sync routes to immutable page requests and an exhausted-cursor checkpoint; unsupported Git pull, code/image and connector paths refuse early. (Refactor wave 1: moved from src/commands/sync.ts.)
src/commands/sync/renames.ts 2 coordinator Managed Markdown sync routes to immutable page requests and an exhausted-cursor checkpoint; unsupported Git pull, code/image and connector paths refuse early. (Refactor wave 1: moved from src/commands/sync.ts.)
+src/commands/sync/holds.ts 2 coordinator Legacy sync only: a full walk moves the page of a held rename destination that now screens clean (updateSlug plus source_path, same id) before importing it; managed brains route sync to immutable page requests and never reach it.
src/core/agent-install/setup.ts 1 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication.
src/core/atomic-write.ts 0 filesystem_guard Atomic page replacement checks the managed root before temporary bytes are written.
src/core/backfill-effective-date.ts 1 projection Derived indexing, retrieval telemetry, or source settings; canonical fields remain guarded by SQL triggers.
diff --git a/docs/architecture/system-of-record.md b/docs/architecture/system-of-record.md
index f9ab4a3b50..651b9d4783 100644
--- a/docs/architecture/system-of-record.md
+++ b/docs/architecture/system-of-record.md
@@ -241,6 +241,7 @@ these write with `NULL` attribution):
- `src/commands/extract-conversation-facts.ts` (3): the conversation fact index calls the engine directly through `writeDerivedFacts`.
- `src/commands/extract-timeline-db.ts` (2): `gbrain extract timeline --source db` batch insert.
- `src/commands/extract.ts` (4): `gbrain extract` timeline walks (file, incremental, stale) and the per-entry fallback.
+- `src/commands/sync/holds.ts` (1): legacy full sync moves a held rename's page once its file screens clean (`updateSlug`).
- `src/commands/sync/renames.ts` (1): legacy sync rename (`updateSlug`).
- `src/core/calibration/undo-wave.ts` (1): calibration wave undo of take resolutions.
- `src/core/chronicle/extract-events.ts` (1): event page write.
diff --git a/src/core/persistence/sync-screen.ts b/src/core/persistence/sync-screen.ts
index 38f18feaee..4b1f63abb9 100644
--- a/src/core/persistence/sync-screen.ts
+++ b/src/core/persistence/sync-screen.ts
@@ -11,6 +11,8 @@ import type { BrainEngine } from '../engine.ts';
import { OperationError, opError } from '../ops/contract.ts';
import { loadImportSanityConfig, type ImportSanityConfig } from '../import-screen.ts';
import { RECOVERY_VERSION } from '../markdown.ts';
+import { slugConflictHoldMessage } from '../import-file.ts';
+import { resolveSlugForPath } from '../sync.ts';
import { loadActivePackForEngine } from '../schema-pack/engine-resolution.ts';
import { VERSION } from '../../version.ts';
import { sha256 } from './digest.ts';
@@ -96,7 +98,9 @@ export async function screenFrozenImport(engine: BrainEngine, input: FrozenImpor
why: 'Collects the gbrain version and brain health to attach to the bug report; the sync checkpoint did not advance past this file.' } });
}
}
- return heldEntry(entry, slug, pageId, refusal, content, blob);
+ // The stored hold names the path-derived slug only, never the declared frontmatter value.
+ return heldEntry(entry, slug, pageId, refusal.code === 'frontmatter_slug_conflict'
+ ? { ...refusal, message: slugConflictHoldMessage(entry.path, resolveSlugForPath(entry.sourcePath)) } : refusal, content, blob);
}
/**
diff --git a/test/persistence-sync-failures.serial.test.ts b/test/persistence-sync-failures.serial.test.ts
index 90d7519f1b..d0042269af 100644
--- a/test/persistence-sync-failures.serial.test.ts
+++ b/test/persistence-sync-failures.serial.test.ts
@@ -53,6 +53,8 @@ beforeAll(async () => {
const lite = new PGLiteEngine(); await lite.connect({}); await lite.initSchema(); engines.push(lite);
}
if (backends.includes('postgres')) { const pg = await isolatedPersistencePostgres(process.env.DATABASE_URL!); engines.push(pg.engine); closePostgres = pg.close; }
+ // #5988: these fixtures force failed receipts with unreadable YAML, which sync now holds by default; sync.holds=fail keeps them fail-closed.
+ for (const engine of engines) await engine.setConfig('sync.holds', 'fail');
}, 120_000);
test('withdrawal-conflicted sync resumes only through explicit guarded rediscovery and cannot restore the fact', async () => withEnv(env, async () => {
@@ -310,6 +312,7 @@ test('local single and all-source CLI JSON carry durable diagnostics and fail th
test.skipIf(!backends.includes('pglite'))('a new process reads the same failed receipt from a persisted PGLite brain', async () => withEnv(env, async () => {
const database = join(home, 'restart-db');
const engine = new PGLiteEngine(); await engine.connect({ database_path: database }); await engine.initSchema();
+ await engine.setConfig('sync.holds', 'fail');
let expected: Awaited<ReturnType<typeof performManagedSync>>, sourceId: string;
try {
const f = await fixture(engine, { 'bad.md': '---\ntitle: [broken\n---\nRestart failure fixture.\n' });
diff --git a/test/persistence-sync-holds.test.ts b/test/persistence-sync-holds.test.ts
index 55958226d1..1aab24eb8f 100644
--- a/test/persistence-sync-holds.test.ts
+++ b/test/persistence-sync-holds.test.ts
@@ -115,6 +115,7 @@ test('slug conflicts and files over 5 MB and over the 10 MiB read bound are held
expect(result).toMatchObject({ status: 'first_sync', added: 1, held_count: 3 });
const byPath = Object.fromEntries((await s.holds()).map(hold => [hold.path, hold]));
expect(byPath['notes/slug.md']).toMatchObject({ code: 'frontmatter_slug_conflict' });
+ expect(byPath['notes/slug.md']!.message).not.toContain('elsewhere');
expect(byPath['notes/big.md']).toMatchObject({ code: 'file_too_large' });
expect(byPath['notes/huge.md']).toMatchObject({ code: 'file_too_large', upstream_version: null });
expect(byPath['notes/huge.md']!.meta.blob_oid).toBe(git(s.root, 'rev-parse', 'HEAD:notes/huge.md'));
diff --git a/test/persistence-sync-origin-native.serial.test.ts b/test/persistence-sync-origin-native.serial.test.ts
index 0cde988f5b..cd765ed192 100644
--- a/test/persistence-sync-origin-native.serial.test.ts
+++ b/test/persistence-sync-origin-native.serial.test.ts
@@ -513,7 +513,9 @@ check('an exact recorded origin retains its existing slug on every native platfo
writeFileSync(join(f.root, 'notes/recorded.md'), canonical.replace('slug: notes/example', 'slug: notes/impostor'));
execFileSync('git', ['-C', f.root, 'add', '-A']);
execFileSync('git', ['-C', f.root, 'commit', '-qm', 'Attempt a different canonical identity']);
- expect(await performManagedSync(engine, { ...f.opts, full: false })).toMatchObject({ status: 'blocked_by_failures', managedWrite: { write_error: 'invalid_params' } });
+ // #5988: the conflicting identity is held, never imported, instead of blocking the sync.
+ const held = await performManagedSync(engine, { ...f.opts, full: false });
+ expect(held.held?.map(item => [item.path, item.code])).toEqual([['notes/recorded.md', 'frontmatter_slug_conflict']]);
expect(await engine.readPageSnapshot(f.slug, { sourceId: f.id })).toEqual(f.snapshot);
expect(await engine.getPage('notes/impostor', { sourceId: f.id })).toBeNull();
});
diff --git a/test/sync-frontmatter-slug-conflict.test.ts b/test/sync-frontmatter-slug-conflict.test.ts
index c5481f68b2..c083cd642c 100644
--- a/test/sync-frontmatter-slug-conflict.test.ts
+++ b/test/sync-frontmatter-slug-conflict.test.ts
@@ -57,6 +57,8 @@ test('a frontmatter slug that conflicts with its path is named in sync output an
await engine.executeRaw("INSERT INTO sources(id,name,local_path,config) VALUES($1,$1,$2,'{}')", [id, root]);
await claimWorktree(engine, id, root);
await engine.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');
+ // #5988: sync holds such a file by default; sync.holds=fail keeps the fail-closed receipt this pins.
+ await engine.setConfig('sync.holds', 'fail');
try {
const result = await performManagedSync(engine, { sourceId: id, noPull: true, noEmbed: true, noExtract: true });
expect(result).toMatchObject({ status: 'blocked_by_failures', managedWrite: { write_error: 'invalid_params', message: expected } });
@@ -71,6 +73,7 @@ test('a frontmatter slug that conflicts with its path is named in sync output an
const receipt = await operations.find(op => op.name === 'get_write_request')!.handler(ctx, { request_id: requestId });
expect(receipt).toMatchObject({ request_id: requestId, state: 'failed', write_error: 'invalid_params', write_error_message: expected });
} finally {
+ await engine.unsetConfig('sync.holds');
await disposePersistenceConsumer(engine);
await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
}