Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): writer status reports a failed movement read as not_read (GBRA-130 A-59)

garrytan8b7927597ab4
diff --git a/src/core/persistence/administration.ts b/src/core/persistence/administration.ts
index eb88e02358..14464b2b9a 100644
--- a/src/core/persistence/administration.ts
+++ b/src/core/persistence/administration.ts
@@ -282,7 +282,10 @@ export async function runPersistenceAdministration(engine: BrainEngine, operatio
host: { host_id: existingLocalHostId(), ...await (await import('./consumer-diagnostics.ts')).hostConsumersReport(engine, existingLocalHostId()) },
worktree_refreshes: await (await import('./worktree-refresh.ts')).activeWorktreeRefreshes(engine, params.source_id as string | undefined),
// #6317 (B4): per managed source, whether sync data moves (shares the reader of sources status, doctor and writer movement).
- movement: await (await import('./sync-movement.ts')).readSourceMovement(engine, params.source_id === undefined ? {} : { sourceIds: [source(params.source_id)] }).catch(() => []) };
+ // GBRA-130 A-59: a failed read says so (not_read with its code), never an empty list that reads as no movement.
+ movement: await (await import('./sync-movement.ts')).readSourceMovement(engine, params.source_id === undefined ? {} : { sourceIds: [source(params.source_id)] })
+ .catch((error: unknown) => ({ status: 'not_read' as const, code: String((error as { code?: unknown } | null)?.code ?? 'storage_error'),
+ fix: readFix('Reads source movement on its own, read-only.', { argv: ['gbrain', 'sources', 'writer', 'movement', ...(params.source_id === undefined ? [] : [String(params.source_id)]), '--json'] }) })) };
}
if (operation === 'writer_claim') {
keys(params, ['source_id', 'path', 'dry_run', 'admin_intent', 'expected_state']);
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index ff0fc95fea..e3a97e5ef8 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -331,4 +331,5 @@ test/vector-manifest-probe-bound.test.ts
test/withdrawal-overlay-concurrency.test.ts
test/withdrawal-publication-file.test.ts
test/worktree-refresh-recovery-row-gbra130.test.ts
+test/writer-status-movement-not-read-gbra130.test.ts
test/writer-status-owner-backends.test.ts
diff --git a/test/writer-status-movement-not-read-gbra130.test.ts b/test/writer-status-movement-not-read-gbra130.test.ts
new file mode 100644
index 0000000000..0fbb36fe90
--- /dev/null
+++ b/test/writer-status-movement-not-read-gbra130.test.ts
@@ -0,0 +1,36 @@
+/**
+ * GBRA-130 A-59 (#6712 PR 4b): `sources writer status` read source movement with `.catch(() => [])`, so a failed read
+ * reported `movement: []`, which reads as "no managed source has anything to move" exactly when the reader could not tell.
+ *
+ * Protects (red before: `movement` is `[]`): with the movement reader failing, `movement` is
+ * `{ status: 'not_read', code, fix }` naming the read-only movement command; with it working it stays the per-source list.
+ * Runs on PGLite and, with DATABASE_URL, on Postgres.
+ */
+import { afterEach, describe, expect, spyOn, test } from 'bun:test';
+import { execFileSync } from 'node:child_process';
+import { writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { runPersistenceAdministration } from '../src/core/persistence/administration.ts';
+import * as movement from '../src/core/persistence/sync-movement.ts';
+import { managedBrain } from './helpers/managed-brain.ts';
+import { testBackends } from './helpers/test-backends.ts';
+
+const setup = ({ root }: { root: string }) => {
+ execFileSync('git', ['-C', root, 'init', '-q']);
+ writeFileSync(join(root, 'a.md'), '---\ntitle: A\n---\nAlpha.\n');
+ execFileSync('git', ['-C', root, 'add', '-A']);
+ execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]', 'commit', '-qm', 'seed']);
+};
+
+for (const backend of testBackends()) describe(`[${backend}] GBRA-130 A-59: writer status when the movement read fails`, () => {
+ const databaseUrl = backend === 'postgres' ? process.env.DATABASE_URL : undefined;
+ let spy: { mockRestore(): void } | undefined;
+ afterEach(() => { spy?.mockRestore(); spy = undefined; });
+ test('movement is not_read with its code and the movement command, never an empty list', () => managedBrain(async ({ engine }) => {
+ const ok = await runPersistenceAdministration(engine, 'writer_status', { source_id: 'default' });
+ expect(Array.isArray(ok.movement)).toBe(true);
+ spy = spyOn(movement, 'readSourceMovement').mockImplementation(async () => { throw Object.assign(new Error('canceling statement due to statement timeout'), { code: '57014' }); });
+ const status = await runPersistenceAdministration(engine, 'writer_status', { source_id: 'default' });
+ expect(status.movement).toMatchObject({ status: 'not_read', code: '57014', fix: { argv: ['gbrain', 'sources', 'writer', 'movement', 'default', '--json'] } });
+ }, { databaseUrl, setup }), 120_000);
+});