Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

holds: route preparation_stalled on every surface (#6278 B5)

garrytan59248225f094
diff --git a/src/commands/sync/args.ts b/src/commands/sync/args.ts
index 2e9e8fe9ec..abee269db0 100644
--- a/src/commands/sync/args.ts
+++ b/src/commands/sync/args.ts
@@ -29,7 +29,12 @@ frontmatter fix with 'gbrain repair frontmatter --source <id>'. A fence hold
preview it with 'gbrain repair fences --source <id>' (read-only, no model
call), which prints the apply command, or the exact edit for a fence gbrain
will not guess. A source a file blocked before this release recovers on its
-next sync ('--no-pull' on a managed brain).
+next sync ('--no-pull' on a managed brain). On a managed brain a write whose
+preparation never finishes within its attempts is held as
+preparation_stalled: the file is fine, so no repair applies; inspect the
+writer with 'gbrain sources writer status --source <id> --json', fix what it
+names, then 'gbrain sources retry-held <id>' and the same sync. Many such
+stalls in one run stop it with outcome blocked / preparation_systemic.
'gbrain config set sync.holds fail' restores fail-closed blocking.
Options:
@@ -160,7 +165,11 @@ See also:
gbrain sources status <id> Held files with their next command.
gbrain repair frontmatter --source <id> Preview the fix for frontmatter holds.
gbrain repair fences --source <id> Preview the repair of fence holds.
+ gbrain sources writer status --source <id> --json
+ What a stalled write was doing (preparation_stalled holds).
docs/guides/repair.md#held-files Walkthrough.
+ docs/guides/troubleshooting.md#catch-up-stuck
+ Catch-up stuck / held N files runbook.
`);
}
diff --git a/test/held-files-walkthrough.test.ts b/test/held-files-walkthrough.test.ts
index 9f8a6bc1d9..0ee78ff55b 100644
--- a/test/held-files-walkthrough.test.ts
+++ b/test/held-files-walkthrough.test.ts
@@ -12,12 +12,32 @@
* Protects: the documented recovery path (post-upgrade notice, in-place
* conversion, sources status, two-pass hash-bound repair with --skip/--only,
* clean sync, doctor). Serial: it spawns about twenty CLI processes.
+ *
+ * #6278: the second test walks a source holding a frontmatter hold, a fence
+ * hold and a preparation-stalled hold at once through every hold surface in
+ * process (sync result, sources status lines, doctor, retry-held, read
+ * notices, the remote relay) and checks each routes the three kinds apart:
+ * frontmatter repair, fence repair, and writer status then retry-held and the
+ * option-preserving sync. Never frontmatter repair for a stalled hold.
*/
import { afterAll, expect, test } from 'bun:test';
-import { spawnSync } from 'node:child_process';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { randomUUID } from 'node:crypto';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { OperationError } from '../src/core/ops/contract.ts';
+import { claimWorktree } from '../src/core/persistence/ownership.ts';
+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
+import { performManagedSync } from '../src/core/persistence/sync-run.ts';
+import { installFaultHook } from '../src/core/persistence/fault-points.ts';
+import { holdRepairSteps, readGitSourceHolds } from '../src/core/persistence/sync-holds.ts';
+import { coverageRoute, fileHeldField, heldFilesNotice, hostOperatorFix, readHeldCoverage, readHeldPages } from '../src/core/persistence/held-reads.ts';
+import { gitHoldStatusLines, readGitHoldStatuses } from '../src/core/persistence/connector-status.ts';
+import { gitHeldFilesCheck } from '../src/commands/doctor/checks/git-holds.ts';
+import { retryHeld } from '../src/commands/sources-retry-held.ts';
+import { withEnv } from './helpers/with-env.ts';
const REPO = join(import.meta.dir, '..');
const work = mkdtempSync(join(tmpdir(), 'gbrain-held-walkthrough-'));
@@ -115,3 +135,83 @@ test('docs/guides/repair.md "Held files": every command runs and prints every li
}
expect(run(['git', '-C', checkout, 'status', '--porcelain']).out).toBe('');
}, 600_000);
+
+test('#6278: a source holding frontmatter, fence and preparation-stalled files routes each kind apart on every surface', () => withEnv({ GBRAIN_HOME: join(work, 'mixed-home'), GBRAIN_SYNC_FAILURES_DIR: join(work, 'mixed-home') }, async () => {
+ const engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema();
+ const id = `mixed-${randomUUID().replace(/-/g, '').slice(0, 12)}`, root = join(work, id);
+ const git = (...args: string[]) => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
+ try {
+ mkdirSync(join(root, 'notes'), { recursive: true }); git('init', '-q'); git('config', 'user.name', 'Example'); git('config', 'user.email', '[email protected]');
+ const T = '<!--- gbrain:takes:begin -->', TE = '<!--- gbrain:takes:end -->';
+ writeFileSync(join(root, 'notes/clean.md'), '---\ntitle: Clean\n---\nA synthetic note.\n');
+ writeFileSync(join(root, 'notes/frontmatter.md'), '---\ntitle: Standup with acme-example\nthe team agreed to ship on Friday\n---\nDaily standup notes.\n');
+ writeFileSync(join(root, 'notes/fence.md'), `---\ntitle: Fence\n---\nA synthetic page.\n\n${T}\n| # | claim | kind | who | weight | since | source |\n|---|---|---|---|---|---|---|\n| 1 | Synthetic take | take | Nobody Example | 0.7 | 2026-01 | chat |\n${TE}\n`);
+ writeFileSync(join(root, 'notes/stalled.md'), '---\ntitle: Stalled\n---\nA synthetic note whose write stalls.\n');
+ git('add', '-A'); git('commit', '-qm', 'fixture');
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+ 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');
+ installFaultHook(async (point, detail) => {
+ if (point !== 'consumer:prepared' || detail.sourceId !== id || !detail.requestId) return;
+ const [row] = await engine.executeRaw<{ path: string | null }>("SELECT intent->>'path' AS path FROM persistence_requests WHERE request_id=$1::uuid", [detail.requestId]);
+ if (row?.path === 'notes/stalled.md') throw new OperationError('preparation_stalled', 'Preparation did not finish within its attempts (forced probe).', 'Inspect the writer.');
+ });
+ const result = await performManagedSync(engine, { sourceId: id, noPull: true, noEmbed: true, noExtract: true });
+ expect(result).toMatchObject({ status: 'first_sync', added: 1, held_count: 3, holds_outstanding: 3 });
+ const byPath = new Map(result.held!.map(hold => [hold.path, hold]));
+ expect(byPath.get('notes/frontmatter.md')).toMatchObject({ code: 'invalid_frontmatter', fix: { argv: ['gbrain', 'repair', 'frontmatter', '--source', id, '--include-ambiguous'] } });
+ expect(byPath.get('notes/fence.md')).toMatchObject({ code: 'invalid_fence', fix: { argv: ['gbrain', 'repair', 'fences', '--source', id, '--only', 'notes/fence.md'] } });
+ expect(byPath.get('notes/stalled.md')).toMatchObject({ code: 'preparation_stalled', fix: { argv: ['gbrain', 'sources', 'writer', 'status', '--source', id, '--json'],
+ then: { argv: ['gbrain', 'sources', 'retry-held', id], then: { argv: ['gbrain', 'sync', '--source', id, '--no-pull', '--no-embed', '--no-extract'] } } } });
+ expect(JSON.stringify(byPath.get('notes/stalled.md'))).not.toContain('repair frontmatter');
+ // The source-level route names all three; its first command is the frontmatter preview (it covers the most holds), and the stalled step never is a repair.
+ const coverage = (await readHeldCoverage(engine, { sourceId: id }))[0]!;
+ expect(coverageRoute(coverage)).toEqual({ fences: 1, others: 1, stalled: 1 });
+ const steps = holdRepairSteps(id, coverageRoute(coverage));
+ expect(steps.commands).toEqual([`gbrain repair frontmatter --source ${id}`, `gbrain repair fences --source ${id}`, `gbrain sources writer status --source ${id} --json`,
+ `gbrain sources status ${id} --json`, `gbrain sources retry-held ${id}`, `gbrain sync --source ${id} --no-pull`]);
+ expect(steps.text).toContain('preparation-stalled hold(s) are not file problems and need no repair');
+ expect(result.holds_fix!.why).toContain('the 1 preparation-stalled hold(s) are not file problems and need no repair');
+ // sources status lists each hold with its own step.
+ const status = (await readGitHoldStatuses(engine, [id])).get(id)!;
+ const lines = gitHoldStatusLines(id, status).join('\n');
+ expect(lines).toContain('notes/stalled.md');
+ expect(lines).toContain(`gbrain sources writer status --source ${id} --json`);
+ expect(status.items.find(item => item.path === 'notes/stalled.md')!.fix.argv).toEqual(['gbrain', 'sources', 'writer', 'status', '--source', id, '--json']);
+ // doctor: one finding, three kinds, the stalled one routed to writer status.
+ const check = await gitHeldFilesCheck(engine, [id]);
+ expect(check.status).toBe('warn');
+ expect(check.details).toMatchObject({ held: 3, sources: [{ source_id: id, fences: 1, stalled: 1, held: 3 }] });
+ expect(check.message).toContain(`gbrain sources writer status --source ${id} --json`);
+ expect(check.message).toContain('gbrain repair fences');
+ expect(check.message).toContain('gbrain repair frontmatter');
+ // retry-held schedules all three and keeps the run's options on the follow-up sync.
+ const retry = await retryHeld(engine, id);
+ expect(retry.scheduled).toBe(3);
+ expect(retry.fix!.argv).toEqual(['gbrain', 'sync', '--source', id, '--no-pull', '--no-embed', '--no-extract']);
+ expect(retry.next_action).toContain('preparation-stalled hold(s) are not file problems');
+ // Read notices: local and remote, no path for the remote relay, writer status named for the stalled kind.
+ const notice = heldFilesNotice([coverage], false)!;
+ expect(notice.fix.argv).toEqual(['gbrain', 'repair', 'frontmatter', '--source', id]);
+ expect(notice.fix.why).toContain('writer status');
+ const relay = hostOperatorFix([{ source_id: id, route: coverageRoute(coverage) }], 'why');
+ expect(relay.user_message).toContain(`'gbrain sources writer status --source ${id} --json'`);
+ expect(relay.user_message).toContain('the files themselves are fine');
+ expect(relay.user_message).not.toContain('notes/stalled.md');
+ const held = [...(await readGitSourceHolds(engine, { sourceIds: [id] }))[0]!.holds];
+ const stalled = held.find(record => record.code === 'preparation_stalled')!;
+ expect(stalled.page_id).toBeNull();
+ // A stale page's file_held field for a stalled hold (built from the record directly: the held file here is new, so no page carries it).
+ const field = fileHeldField({ record: { ...stalled, page_id: 1 }, revision: 'r1' }, true);
+ expect(field.fix.actor).toBe('host_admin');
+ expect(JSON.stringify(field)).not.toContain('notes/stalled.md');
+ expect(field.fix.user_message).toContain('writer status');
+ expect(fileHeldField({ record: { ...stalled, page_id: 1 }, revision: 'r1' }, false).fix.argv).toEqual(['gbrain', 'sources', 'writer', 'status', '--source', id, '--json']);
+ expect(await readHeldPages(engine, [1])).toBeInstanceOf(Map);
+ } finally {
+ installFaultHook(undefined);
+ await disposePersistenceConsumer(engine);
+ await engine.disconnect();
+ }
+}), 180_000);