Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: a partial extraction-review batch exits 1 on the CLI
garrytan7c4accca6657
diff --git a/src/cli/cli-error.ts b/src/cli/cli-error.tsindex a39219066c..c8debbd4d5 100644--- a/src/cli/cli-error.ts+++ b/src/cli/cli-error.ts@@ -199,11 +199,14 @@ export function writeFatalCliError(e: unknown, opts: { argv?: readonly string[];/*** #4488 / GST-1387: an op that reports failure in-band (`{status: 'error'}`, e.g. put_page over unparseable frontmatter* or a remember batch with a failed item) is echoed to stderr and exits 1 on every CLI path, never read as success.- * No-op statuses ('skipped', 'unchanged', …) stay exit 0: a no-op is not a failure.+ * No-op statuses ('skipped', 'unchanged', …) stay exit 0: a no-op is not a failure. An extraction-review batch with a+ * failed decision reports 'partial' and exits 1 too.*/export function reportInBandFailure(result: unknown, command: string): void {- if (typeof result !== 'object' || result === null || Array.isArray(result) || (result as { status?: unknown }).status !== 'error') return;+ if (typeof result !== 'object' || result === null || Array.isArray(result)) return;+ const status = (result as { status?: unknown }).status;+ if (status !== 'error' && !(status === 'partial' && command === 'extraction-review')) return;const detail = (result as { error?: unknown }).error;- console.error(`gbrain ${command}: operation reported status 'error'` + (typeof detail === 'string' && detail ? ` — ${detail}` : '') + '.');+ console.error(`gbrain ${command}: operation reported status '${status}'` + (typeof detail === 'string' && detail ? ` — ${detail}` : '') + '.');setCliExitVerdict(1);}diff --git a/test/cli-op-error-status-exit.test.ts b/test/cli-op-error-status-exit.test.tsindex 7da0297ac1..26e9316904 100644--- a/test/cli-op-error-status-exit.test.ts+++ b/test/cli-op-error-status-exit.test.ts@@ -98,3 +98,26 @@ describe('#4488 in-band {status:error} → CLI exit 1', () => {expect(second.stdout).toContain('skipped');}, 480_000);});++describe('extraction-review with a failed decision → CLI exit 1', () => {+ test('a partial batch exits 1 although the other decisions landed', async () => {+ const { createEngine } = await import('../src/core/engine-factory.ts');+ const { withCoordinatedWrite } = await import('../src/core/persistence/context.ts');+ const { TEST_WRITE_ATTRIBUTION } = await import('./helpers/write-attribution.ts');+ const engineConfig = { engine: 'pglite' as const, database_path: join(home, '.gbrain', 'brain.pglite') };+ const engine = await createEngine(engineConfig);+ await engine.connect(engineConfig);+ const fence = '<!--- gbrain:facts:begin -->\n| # | claim | kind | confidence | visibility | notability | valid_from | valid_until | source | context |\n'+ + '|---|---|---|---|---|---|---|---|---|---|\n| 1 | Batchrowzq5 likes tea | fact | 1.0 | world | medium | 2026-01-02 |\n<!--- gbrain:facts:end -->\n';+ try {+ for (const [slug, body] of [['people/exit-good-example', 'Came up in a call.'], ['people/exit-broken-example', `Came up twice.\n\n${fence}`]]) {+ await engine.transaction(tx => withCoordinatedWrite(tx, ['default'], () => tx.putPage(slug,+ { type: 'person', title: 'Exit Example', compiled_truth: body, timeline: '', frontmatter: { provenance: 'auto-extracted', status: 'unverified' } }), TEST_WRITE_ATTRIBUTION));+ }+ } finally { await engine.disconnect(); }+ const r = run(['extraction-review', 'promote', '--slugs', 'people/exit-good-example,people/exit-broken-example', '--json']);+ expect(JSON.parse(r.stdout)).toMatchObject({ status: 'partial', results: [{ slug: 'people/exit-good-example', status: 'promoted' }, { slug: 'people/exit-broken-example', status: 'failed' }] });+ expect(r.status).toBe(1);+ expect(r.stderr).toContain("status 'partial'");+ }, 480_000);+});