Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
persistence: writer activate on an already-managed brain reports reason already_enabled and the owner-process hint (#5514)
garrytand8ce172f12b5
diff --git a/src/core/persistence/activation.ts b/src/core/persistence/activation.tsindex 09da8d7fa5..4a2aa7da06 100644--- a/src/core/persistence/activation.ts+++ b/src/core/persistence/activation.ts@@ -31,7 +31,14 @@ export interface ActivationReport {* until `gbrain sources writer git-durability <source> --enable` runs.*/git_durability?: Array<{ source_id: string; state: 'on' | 'off' | 'unknown'; enable_command: string | null }>;+ /** #5514: `activated: false` with `enabled: true` says why, so a no-op is not read as a silent failure. */+ reason?: 'already_enabled';+ next_action?: string;}+/** #5514: the brain was managed before the command ran; activation changes nothing and cannot start an owner process. */+const ALREADY_ENABLED = { reason: 'already_enabled', next_action: 'Managed persistence was already enabled before this command, so nothing changed. '+ + 'If writes are accepted but never published (writer status shows ingress not_running or a null heartbeat), no owner process is running: '+ + 'start gbrain serve or the autopilot on the owner host, then check gbrain sources writer status --probe --json.' } as const;const gitDurabilityListing = (bindings: WorktreeBinding[]): NonNullable<ActivationReport['git_durability']> => bindings.map(binding => {const state = gitDurabilityState(binding);return { source_id: binding.source_id, state, enable_command: state === 'on' ? null : `gbrain sources writer git-durability ${binding.source_id} --enable --dry-run` };@@ -113,7 +120,7 @@ export async function activatePersistence(engine: BrainEngine, opts: { confirmQuif (brain?.enabled && opts.expectedState === undefined) {const [count] = await engine.executeRaw<{ count: number }>(`SELECT COUNT(*)::integer AS count FROM persistence_source_bindings bJOIN sources s ON s.id=b.source_id AND s.incarnation=b.source_incarnation WHERE NOT s.archived`);- return { enabled: true, activated: false, filesystem_sources: count.count, native_lock: native };+ return { enabled: true, activated: false, filesystem_sources: count.count, native_lock: native, ...ALREADY_ENABLED };}const hostId = opts.dryRun ? existingLocalHostId() : localHostId();const sources = await configuredSources(engine);@@ -147,7 +154,7 @@ export async function activatePersistence(engine: BrainEngine, opts: { confirmQuawait assertWriterAdminState(tx, opts.expectedState);const [current] = await tx.executeRaw<{ enabled: boolean }>('SELECT enabled FROM persistence_brain WHERE singleton=1 FOR UPDATE');await assertWriterAdminUnlocked(tx);- if (current?.enabled) return { enabled: true, activated: false, filesystem_sources: initial.length, native_lock: native };+ if (current?.enabled) return { enabled: true, activated: false, filesystem_sources: initial.length, native_lock: native, ...ALREADY_ENABLED };const currentSources = await configuredSources(tx, true);const bindings = await validatedBindings(tx, currentSources, hostId, true);const identity = (rows: WorktreeBinding[]) => JSON.stringify(rows.map(row => [row.source_id,row.source_incarnation,row.worktree_id,row.owner_host_id,diff --git a/test/persistence-activation.test.ts b/test/persistence-activation.test.tsindex 726d76f4e4..59d7108708 100644--- a/test/persistence-activation.test.ts+++ b/test/persistence-activation.test.ts@@ -85,7 +85,12 @@ test('activation fsyncs source and selected datastore refusal records before becexpect(JSON.parse(readFileSync(join(root, '.gbrain-managed'), 'utf8'))).toMatchObject({ managed: true, version: 1 });expect(await managedPersistenceEnabled(engine)).toBe(true);await expect(engine.putPage('legacy', { type: 'note', title: 'Example', compiled_truth: 'Unsupported legacy write', timeline: '', frontmatter: {} }, { sourceId })).rejects.toThrow('writer_coordinator_required');- expect(await activatePersistence(engine, { confirmQuiesced: true })).toMatchObject({ enabled: true, activated: false });+ // #5514: a second activation says why it changed nothing and where the missing owner process is.+ const again = await activatePersistence(engine, { confirmQuiesced: true });+ expect(again).toMatchObject({ enabled: true, activated: false, reason: 'already_enabled' });+ expect(again.next_action).toContain('gbrain serve');+ expect(again.next_action).toContain('writer status --probe');+ expect(await activatePersistence(engine, { confirmQuiesced: true, expectedState: (await reviewedWriterIntent(engine, "writer_activate")).expected_state })).toMatchObject({ enabled: true, activated: false, reason: "already_enabled" });const later = join(home, 'later-canonical'); mkdirSync(later);await claimWorktree(engine, `${sourceId}-later`, later);expect(registeredManagedRoots()).toContain(later);