Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: carry only the refresh fence fix across the owner hop; one in-band failure reporter for both CLI paths
garrytan40fa8de0d1b1
diff --git a/src/cli/cli-error.ts b/src/cli/cli-error.tsindex 3a61258228..a39219066c 100644--- a/src/cli/cli-error.ts+++ b/src/cli/cli-error.ts@@ -10,7 +10,7 @@*/import { cliRenderContext, renderCliError, renderNotice, type Action, type AgentEnvelope, type Notice } from '../core/agent-output.ts';import { renderCliNotices } from '../core/agent-markers.ts';-import { jsonGuardActive, jsonRequested, noteRenderedErrorCode, writeStdoutFinal } from '../core/cli-force-exit.ts';+import { jsonGuardActive, jsonRequested, noteRenderedErrorCode, setCliExitVerdict, writeStdoutFinal } from '../core/cli-force-exit.ts';import { opError, type OpErrorOpts, type OperationError } from '../core/ops/contract.ts';import type { RegistryCode } from '../core/error-registry.ts';import {@@ -195,3 +195,15 @@ export function writeFatalCliError(e: unknown, opts: { argv?: readonly string[];}return writeCliError(e, command, { argv });}++/**+ * #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.+ */+export function reportInBandFailure(result: unknown, command: string): void {+ if (typeof result !== 'object' || result === null || Array.isArray(result) || (result as { status?: unknown }).status !== 'error') return;+ const detail = (result as { error?: unknown }).error;+ console.error(`gbrain ${command}: operation reported status 'error'` + (typeof detail === 'string' && detail ? ` — ${detail}` : '') + '.');+ setCliExitVerdict(1);+}diff --git a/src/cli/main.ts b/src/cli/main.tsindex 57639fe439..537fbc9728 100755--- a/src/cli/main.ts+++ b/src/cli/main.ts@@ -46,7 +46,7 @@ import { printCuratedHelp } from './help/render.ts';import { OWN_EQUALS_PARSERS, READER_ALIASES, findUnknownFlag, splitFlagEquals } from './flag-equals.ts';import { printHelp } from './top-help.ts';import { curatedFlagError } from './help/validate.ts';-import { cliCommandOf, exitCliError, exitOnRepairFailed, unknownFlagError, usageError, writeCliError, writeCliNotice, writeFatalCliError } from './cli-error.ts';+import { cliCommandOf, exitCliError, exitOnRepairFailed, reportInBandFailure, unknownFlagError, usageError, writeCliError, writeCliNotice, writeFatalCliError } from './cli-error.ts';import type { Notice } from '../core/agent-output.ts';import { opError, opOwnsSource } from '../core/ops/contract.ts';import { PAGE_MAX_BYTES } from '../core/page-size-policy.ts';@@ -734,22 +734,7 @@ async function runSharedOperation(command: string, subArgs: string[], cliOpts: C// writeStdoutFinal.if (output) await writeStdoutFinal(output);if (noticeText) process.stderr.write(noticeText);- // #4488: an op that reports failure IN-BAND (`{status: 'error'}` — e.g.- // put_page over unparseable frontmatter) used to print the envelope and- // exit 0, so scripts read a never-written page as success. Echo the error- // to stderr and set the failure verdict. No-op statuses ('skipped',- // 'unchanged', …) stay exit 0 — a no-op is not a failure.- if (- typeof result === 'object' && result !== null && !Array.isArray(result) &&- (result as { status?: unknown }).status === 'error'- ) {- const detail = (result as { error?: unknown }).error;- console.error(- `gbrain ${command}: operation reported status 'error'` +- (typeof detail === 'string' && detail ? ` — ${detail}` : '') + '.',- );- setCliExitVerdict(1);- }+ reportInBandFailure(result, command);markEntityMiss(op.name, result);maybePrintConceptNudge(op.name, params);} catch (e: unknown) {@@ -850,12 +835,7 @@ async function runThinClientRouted(// Awaited delivery (#3423) — same contract as the local-engine path.if (output) await writeStdoutFinal(output);if (stampText) process.stderr.write(stampText);- // GST-1387: an in-band failure (a remember batch with a failed item) exits 1 here too, as on the local path.- if (typeof result === 'object' && result !== null && !Array.isArray(result) && (result as { status?: unknown }).status === 'error') {- const detail = (result as { message?: unknown; error?: unknown }).message ?? (result as { error?: unknown }).error;- console.error(`gbrain ${op.cliHints?.name ?? op.name}: operation reported status 'error'` + (typeof detail === 'string' && detail ? ` — ${detail}` : '') + '.');- setCliExitVerdict(1);- }+ reportInBandFailure(result, op.cliHints?.name ?? op.name);markEntityMiss(op.name, result);maybePrintConceptNudge(op.name, params);} catch (e: unknown) {diff --git a/src/core/persistence/ipc.ts b/src/core/persistence/ipc.tsindex cb3d956372..2dec08a93f 100644--- a/src/core/persistence/ipc.ts+++ b/src/core/persistence/ipc.ts@@ -344,14 +344,14 @@ export class PersistenceIpcTransportError extends Error {/*** GST-1387: a wire error body's recovery contract (canonical code, detail, retryable, fix) restored onto a rebuilt- * OperationError, so a refresh fence stays worktree_refreshing with fix.next wait across the owner hop. A receipt- * error's fix is not carried: this side renders it from the receipt for its own principal.+ * OperationError, so a refresh fence stays worktree_refreshing with fix.next wait across the owner hop. Only the fence's+ * fix (read-only, no consent) is carried: a rendered fix drops `ask_user`, and a receipt's fix is rendered on this side.*/export function restoreRecoveryContract(error: OperationError, body: Record<string, unknown>): void {if (typeof body.code === 'string' && body.code !== error.code) error.canonical = body.code as OperationError['canonical'];if (typeof body.detail === 'string') error.detail = body.detail;if (typeof body.retryable === 'boolean') error.retryable = body.retryable;- if (record(body.fix) && !body.write_request) { const { next: _next, command: _command, ...fix } = body.fix; error.fix = fix as unknown as Action; }+ if (record(body.fix) && body.code === 'worktree_refreshing') { const { next: _next, command: _command, ...fix } = body.fix; error.fix = fix as unknown as Action; }}function remoteOperationError(value: unknown): OperationError {