Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): owner exceptions get their own writer-status hint, never the trigger guess (#6719)

garrytan21593edf8afc
diff --git a/src/core/persistence/connector-errors.ts b/src/core/persistence/connector-errors.ts
index f4c349e275..a43800f4df 100644
--- a/src/core/persistence/connector-errors.ts
+++ b/src/core/persistence/connector-errors.ts
@@ -71,6 +71,15 @@ export const DATABASE_REFUSAL_HINT = 'This is not a content conflict: a gbrain p
+ 'Do not force-write, edit SQL, or disable the guard; ask the user before changing which hosts own the brain.';
/** #5974: another database trigger (named in write_error_detail.raiser) refused the write. */
+/** #6719: an owner exception's recorded identity (class, errno, frame, build) does not name its cause; nothing proves the database refused it. */
+export const ownerExceptionHint = (requestId: string) => 'An unexpected owner exception ended this write and nothing was committed; its cause is unknown from the recorded identity alone. '
+ + `On the brain host run gbrain write-request ${requestId} --json and read error_detail (error_class, errno, frame, attempt.consumer_version) beside the persistence consumer log; `
+ + 'report that identity and the gbrain version on the issue tracker, and upgrade when a fix ships. Do not replay the old intent to diagnose it.';
+
+/** #6719: an origin that names no database refusal (or none at all) stays unknown rather than read as a trigger. */
+export const unknownOriginHint = (requestId: string) => 'The recorded origin of this failure does not name a database refusal, so its cause is not established by this status. '
+ + `On the brain host run gbrain write-request ${requestId} --json and follow its diagnosis.fix; report the receipt's error_code and error_detail if it names no cause.`;
+
export const DATABASE_TRIGGER_HINT = 'A database trigger refused this write and nothing was committed; write_error_detail.raiser names it. '
+ 'On the brain host run gbrain sources writer status --probe --json and compare recent_failures[].error_detail.attempt.consumer_version '
+ 'with the version of every gbrain process sharing this database; upgrade or restart the older one, run gbrain apply-migrations --yes, then retry with a new request ID. '
diff --git a/src/core/persistence/diagnostics.ts b/src/core/persistence/diagnostics.ts
index 6f6e1d114f..6f20c47cfb 100644
--- a/src/core/persistence/diagnostics.ts
+++ b/src/core/persistence/diagnostics.ts
@@ -12,7 +12,7 @@ import { listHostConsumers, type ConsumerPool, type ListedConsumer } from './con
import type { WriteRequestState } from './types.ts';
import { preparationBudgetMs } from './preparation-budget.ts';
import { readWriteSwitchSnapshot } from './switches.ts';
-import { DATABASE_REFUSAL_HINT, DATABASE_TRIGGER_HINT } from './connector-errors.ts';
+import { DATABASE_REFUSAL_HINT, DATABASE_TRIGGER_HINT, ownerExceptionHint, unknownOriginHint } from './connector-errors.ts';
import { readQueuedHeadBlockers } from './head-blocker.ts';
export const WRITER_NEXT_ACTIONS: Record<string, string> = {
@@ -135,6 +135,13 @@ export function capacityDiagnostics(counters: Counter[], limits: JournalLimits)
});
});
}
+/** #6719: the next step a recorded origin supports; only a database origin reads as a database refusal. */
+function recentFailureNextAction(origin: unknown, requestId: string): string {
+ if (origin === 'database_guard') return DATABASE_REFUSAL_HINT;
+ if (origin === 'database_trigger' || origin === 'database') return DATABASE_TRIGGER_HINT;
+ return origin === 'owner_exception' ? ownerExceptionHint(requestId) : unknownOriginHint(requestId);
+}
+
/** Trusted-admin counts only: neither normalized intent nor private paths leave here. */
export async function readWriterDiagnostics(engine: BrainEngine) {
// #6482: writer status is the probe the mode refusal names, so a malformed singleton is reported here, never refused.
@@ -190,7 +197,7 @@ export async function readWriterDiagnostics(engine: BrainEngine) {
: 'The resident consumer of the process that answered this status.' };
return { ...brain, sampled_at: new Date().toISOString(), publication_concurrency: publicationConcurrency(engine),
local_process_ingress, worktrees, counters, queue, effects, limits, capacity: capacityDiagnostics(counters, limits), preparation_policy,
- recent_failures: failures.map(row => ({ ...row, next_action: row.error_detail?.origin === 'database_guard' ? DATABASE_REFUSAL_HINT : DATABASE_TRIGGER_HINT })),
+ recent_failures: failures.map(row => ({ ...row, next_action: recentFailureNextAction(row.error_detail?.origin, row.request_id) })),
backend_visibility: backends.visibility,
blockers: blockers.map(({ id: rowId, claim_phase: _phase, execution_token: _token, claim_lapsed: _lapsed, publication_started: _started, ...row }, index) => {
const health = writeHealth(row);
diff --git a/test/publication-failure-owner-exception.test.ts b/test/publication-failure-owner-exception.test.ts
index 24c7469574..e3bcc3c193 100644
--- a/test/publication-failure-owner-exception.test.ts
+++ b/test/publication-failure-owner-exception.test.ts
@@ -20,6 +20,9 @@ import { claimWorktree } from '../src/core/persistence/ownership.ts';
import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';
import { publicFailureDetail, OWNER_EXCEPTION_MESSAGE } from '../src/core/persistence/publication-failure.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
+import { readWriterDiagnostics } from '../src/core/persistence/diagnostics.ts';
+import { DATABASE_REFUSAL_HINT, DATABASE_TRIGGER_HINT } from '../src/core/persistence/connector-errors.ts';
+import { readTerminalFailureSummary } from '../src/core/persistence/terminal-failures.ts';
import { VERSION } from '../src/version.ts';
import { withEnv } from './helpers/with-env.ts';
@@ -108,3 +111,54 @@ describe('#5929 owner exceptions keep a bounded identity', () => {
expect(receipt.owner_build.fix).toMatchObject({ actor: 'user', verify: { argv: ['gbrain', 'doctor', '--only', 'writer_version', '--json'] } });
});
});
+
+describe('#6719 owner_exception diagnostics', () => {
+ test('writer status recent_failures gives an owner exception its own next_action, never the database-trigger hint', async () => {
+ const { row } = await failingWrite(Object.assign(new Error('cached plan must not change result type'), { code: '0A000' }));
+ expect(row.error_detail).toMatchObject({ origin: 'owner_exception', errno: '0A000' });
+ const status = await withEnv({ GBRAIN_HOME: join(dir, 'home') }, () => readWriterDiagnostics(engine));
+ const failure = status.recent_failures.find(f => f.request_id === row.request_id)!;
+ expect(failure.next_action).not.toContain('database trigger');
+ expect(failure.next_action).toContain('owner exception');
+ expect(failure.next_action).toContain(`gbrain write-request ${row.request_id} --json`);
+ });
+
+ test('an origin that names no database refusal stays unknown instead of guessing a trigger; trigger and guard origins keep their hints', async () => {
+ const { row } = await failingWrite(new RangeError('bad offset'));
+ const failureFor = async (origin: string) => {
+ await engine.executeRaw(`UPDATE persistence_requests SET error_detail=jsonb_set(error_detail,'{origin}',to_jsonb($2::text)) WHERE id=$1::uuid`, [row.id, origin]);
+ const status = await withEnv({ GBRAIN_HOME: join(dir, 'home') }, () => readWriterDiagnostics(engine));
+ return status.recent_failures.find(f => f.request_id === row.request_id)!.next_action;
+ };
+ const unknown = await failureFor('pending_import');
+ expect(unknown).not.toContain('database trigger');
+ expect(unknown).toContain('not established');
+ expect(unknown).toContain(`gbrain write-request ${row.request_id} --json`);
+ expect(await failureFor('database_trigger')).toBe(DATABASE_TRIGGER_HINT);
+ expect(await failureFor('database_guard')).toBe(DATABASE_REFUSAL_HINT);
+ });
+
+ test('a failed checkpoint receipt is historical once a later checkpoint of the source commits (already on master via #6834)', async () => {
+ const receipt = async (state: 'failed' | 'committed') => {
+ await engine.executeRaw(`INSERT INTO persistence_requests(principal_kind,principal_id,request_id,operation,source_id,source_incarnation,slug,digest,authority,intent_bytes,terminal_reservation,
+ state,error_code,error_message,error_detail,intent,completed_at,updated_at,admitter_version)
+ VALUES('local_cli','fixture',$1::uuid,'submit_job',$2,(SELECT incarnation FROM sources WHERE id=$2),'__managed_sync_checkpoint__',$3,'{}'::jsonb,0,0,
+ $4,$5,$6,$7::text::jsonb,'{"kind":"managed_sync_checkpoint"}'::jsonb,now(),now(),$8)`,
+ [randomUUID(), sourceId, randomUUID(), state, state === 'failed' ? 'storage_error' : null, state === 'failed' ? OWNER_EXCEPTION_MESSAGE : null,
+ state === 'failed' ? JSON.stringify({ origin: 'owner_exception', error_class: 'PostgresError', errno: '0A000' }) : null, VERSION]);
+ };
+ const checkpointRows = async () => {
+ const summary = await readTerminalFailureSummary(engine, { sourceIds: [sourceId] });
+ if (summary.status !== 'ok') throw new Error('summary unknown');
+ return summary.sources[0]!.categories.find(c => c.category === 'owner_exception' && c.code === 'storage_error')!;
+ };
+ await receipt('failed');
+ const before = await checkpointRows();
+ expect(before.unresolved).toBeGreaterThanOrEqual(1);
+ await receipt('committed');
+ const after = await checkpointRows();
+ expect(after.unresolved).toBe(before.unresolved - 1);
+ expect(after.historical).toBe(before.historical + 1);
+ });
+});
+