Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(GBRA-130 A-28): a repair kind that throws during sync unblock --apply skips its holds instead of aborting
garrytan181e7617188c
diff --git a/src/core/persistence/sync-status.ts b/src/core/persistence/sync-status.tsindex 5f6b541a08..5a4bf9eef3 100644--- a/src/core/persistence/sync-status.ts+++ b/src/core/persistence/sync-status.ts@@ -596,8 +596,14 @@ export async function unblockSync(engine: BrainEngine, sourceId: string, opts: Uconst kinds = CONTENT_REPAIR_KINDS.filter(kind => repairs.has(kind));const paths = [...repairs.values()].flat().map(hold => hold.path);const startedAt = Date.now();- const lane = await runContentLane(engine, await resolveRepairScope(engine, sourceId), { apply: true, kinds, only: paths, noLlm: opts.noLlm, maxLlmUsd: opts.maxLlmUsd,- deadline: Date.now() + UNBLOCK_REPAIR_BUDGET_MS, sourceFlag: sourceId, logger: quiet, ...(opts.registry ? { registry: opts.registry } : {}) });+ // GBRA-130 A-28: a lane that throws skips its holds (repair_error) instead of aborting the unblock; the re-screens below still run.+ const lane = await resolveRepairScope(engine, sourceId).then(scope => runContentLane(engine, scope, { apply: true, kinds, only: paths, noLlm: opts.noLlm, maxLlmUsd: opts.maxLlmUsd,+ deadline: Date.now() + UNBLOCK_REPAIR_BUDGET_MS, sourceFlag: sourceId, logger: quiet, ...(opts.registry ? { registry: opts.registry } : {}) }))+ .catch((error: unknown) => ({ results: [] as RepairResult[], stopped: kinds.map(kind => ({ kind, reason: 'repair_error',+ message: `gbrain repair ${kind} failed (${String((error as { code?: unknown } | null)?.code ?? 'storage_error')}); run gbrain repair content --source ${sourceId} to see the error.` })) }));+ const repairError = lane.results.length === 0 && lane.stopped.some(s => s.reason === 'repair_error');+ const contentPreview: Action = { argv: ['gbrain', 'repair', 'content', '--source', sourceId], consent: [], actor: 'agent', requires_exclusive: false, verify,+ why: 'The content-repair lane failed during this unblock; its preview (writes nothing) shows the error and the plan for each held file.' };const after = new Map((((await readGitSourceHolds(engine, { sourceIds: [sourceId] }))[0]?.holds ?? [])).map(hold => [hold.path, hold]));const syncNext: Action = { argv: ['gbrain', 'sync', ...resume], consent: [], actor: 'agent', requires_exclusive: false, verify, why: 'Re-imports the repaired file and clears or re-screens its hold.' };for (const [kind, records] of repairs) {@@ -623,7 +629,7 @@ export async function unblockSync(engine: BrainEngine, sourceId: string, opts: Udetail: outcome === 'repaired' ? `repaired by gbrain repair ${kind}${typeof detail?.tier === 'string' ? ` (${detail.tier})` : ''}; scheduled for a re-screen`: `${outcome} (${reason})${message ? `: ${message}` : !item && stop ? `: ${stop.message}` : ''}`,repair: { kind, outcome, ...(reason ? { reason } : {}), ...(typeof detail?.tier === 'string' ? { tier: detail.tier } : {}), ...(llmUsd !== undefined ? { llm_usd: llmUsd } : {}),- ...(receiptOf(detail) ? { receipt: receiptOf(detail) } : {}), next: outcome === 'repaired' ? syncNext : outcome === 'skipped' && (!item || stop) ? unblockApply : fix } });+ ...(receiptOf(detail) ? { receipt: receiptOf(detail) } : {}), next: outcome === 'repaired' ? syncNext : repairError ? contentPreview : outcome === 'skipped' && (!item || stop) ? unblockApply : fix } });}}}diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txtindex cde1c8f706..085739453a 100644--- a/test/postgres-unit-arms.txt+++ b/test/postgres-unit-arms.txt@@ -315,6 +315,7 @@ test/sync-prescreen-drift-6712.test.tstest/sync-slug-root-mode-6694.test.tstest/sync-staged-catchup.test.tstest/sync-status-failure-detail-6513.test.ts+test/sync-unblock-repair-error-gbra130.test.tstest/sync-waiver-budget.test.tstest/sync-waiver-run-imports.test.tstest/take-resolution-survives-publish.test.tsdiff --git a/test/sync-unblock-repair-error-gbra130.test.ts b/test/sync-unblock-repair-error-gbra130.test.tsnew file mode 100644index 0000000000..8852254e30--- /dev/null+++ b/test/sync-unblock-repair-error-gbra130.test.ts@@ -0,0 +1,59 @@+/**+ * GBRA-130 A-28 (#6712 PR 4b): `sync unblock --apply` ran the content-repair lane for its repair-class holds with no catch,+ * so one unexpected throw from a repair kind aborted the whole unblock: no outcome was returned and the re-screens of the+ * other holds (`requestGitHoldRetry`) never ran.+ *+ * Protects (red before: unblock --apply rejects with the kind's error and schedules nothing): with the fences kind+ * stubbed to throw `OperationError('storage_error')`, the fence hold is reported `skipped` with reason `repair_error`+ * and `gbrain repair content --source <id>` as its next step, and the other hold (a `preparation_stalled` retry) is+ * still scheduled for its re-screen. Runs on PGLite and, with DATABASE_URL, on Postgres.+ */+import { describe, expect, test } from 'bun:test';+import { execFileSync } from 'node:child_process';+import { mkdirSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { OperationError } from '../src/core/ops/contract.ts';+import { performManagedSync } from '../src/core/persistence/sync-run.ts';+import { unblockSync } from '../src/core/persistence/sync-status.ts';+import { readGitHoldRetryPaths, writeGitHold } from '../src/core/persistence/sync-holds.ts';+import { REPAIR_REGISTRY } from '../src/core/repair/registry.ts';+import { managedBrain } from './helpers/managed-brain.ts';+import { testBackends } from './helpers/test-backends.ts';+import { withEnv } from './helpers/with-env.ts';++const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();+const commit = (root: string, message: string) => { git(root, 'add', '-A'); git(root, '-c', 'user.name=Example', '-c', '[email protected]', 'commit', '-qm', message); };+const FB = '<!--- gbrain:facts:begin -->', FBE = '<!--- gbrain:facts:end -->';+/** A facts fence with rows and no header: an `invalid_fence` hold the fences kind repairs. */+const noHeader = `---\ntitle: Model\n---\nA synthetic page.\n\n${FB}\n| 1 | Example ships quarterly | fact | 0.9 | private | high | 2026-01-01 | | chat | ctx |\n${FBE}\n`;+const OPTS = { sourceId: 'default', noPull: true, noEmbed: true, noExtract: true };+const setup = ({ root }: { root: string }) => {+ mkdirSync(join(root, 'notes'), { recursive: true }); git(root, 'init', '-q');+ writeFileSync(join(root, 'notes/a.md'), '---\ntitle: A\n---\nAlpha.\n');+ commit(root, 'seed');+};+const throwingRegistry = REPAIR_REGISTRY.map(spec => spec.kind !== 'fences' ? spec+ : { ...spec, handler: { ...spec.handler, plan: async () => { throw new OperationError('storage_error', 'The fences kind failed unexpectedly.', 'Run gbrain repair content to see it.'); } } });++for (const backend of testBackends()) describe(`[${backend}] GBRA-130 A-28: a repair kind that throws during sync unblock --apply`, () => {+ const databaseUrl = backend === 'postgres' ? process.env.DATABASE_URL : undefined;+ test('the fence hold is skipped repair_error with the content-lane preview as next, and the other hold is still scheduled', () => managedBrain(async ({ engine, root }) => {+ await withEnv({ OPENAI_API_KEY: undefined, ANTHROPIC_API_KEY: undefined, VOYAGE_API_KEY: undefined }, async () => {+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');+ mkdirSync(join(root, 'people'), { recursive: true });+ writeFileSync(join(root, 'people/model.md'), noHeader); commit(root, 'a malformed fence');+ const synced = await performManagedSync(engine, OPTS);+ expect(synced.held?.map(hold => [hold.path, hold.code])).toEqual([['people/model.md', 'invalid_fence']]);+ const [{ incarnation }] = await engine.executeRaw<{ incarnation: string }>("SELECT incarnation::text AS incarnation FROM sources WHERE id='default'");+ // A second hold whose safe action is a plain re-screen.+ await writeGitHold(engine, { source_id: 'default', incarnation, path: 'notes/stalled.md', source_path: 'notes/stalled.md', slug: 'notes/stalled', page_id: null,+ code: 'preparation_stalled', message: 'notes/stalled.md: its import could not finish preparing, so it is held and the rest of the source synced.', upstream_version: null,+ observed_at: new Date().toISOString(), run_id: null, mode: 'managed', meta: { recovery_version: 1 } });+ const outcome = await unblockSync(engine, 'default', { apply: true, noLlm: true, registry: throwingRegistry });+ const fence = outcome.applied.find(entry => entry.path === 'people/model.md');+ expect(fence).toMatchObject({ action: 'repair', repair: { kind: 'fences', outcome: 'skipped', reason: 'repair_error', next: { argv: ['gbrain', 'repair', 'content', '--source', 'default'] } } });+ expect(outcome.applied.find(entry => entry.path === 'notes/stalled.md')).toMatchObject({ action: 'retry' });+ expect(await readGitHoldRetryPaths(engine, 'default', incarnation)).toEqual(['notes/stalled.md']);+ });+ }, { databaseUrl, setup }), 180_000);+});