Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes (trust_apply IPC waits past the release door's wait)

garrytan70dd6dd1870e
diff --git a/src/commands/trust.ts b/src/commands/trust.ts
index 283f6f7443..6125217101 100644
--- a/src/commands/trust.ts
+++ b/src/commands/trust.ts
@@ -220,11 +220,12 @@ export async function maybeDelegateTrust(hostConfig: GBrainConfig | null, args:
const { loadMounts } = await import('../core/brain-registry.ts');
const { maybeDelegateLocalAdministration, persistenceConfigForBrain } = await import('../core/persistence/local-client.ts');
const { inspectLockHolder } = await import('../core/pglite-lock.ts');
+ const { DOOR_WAIT_MS } = await import('../core/trust/release-publish.ts');
const brainId = resolveBrainId(getCliOptions().brain, process.cwd());
const config = persistenceConfigForBrain(hostConfig, brainId, brainId === 'host' ? [] : loadMounts());
if (config?.engine !== 'pglite' || !config.database_path || config.database_url || !inspectLockHolder(config.database_path).held) return false;
- const call = async (operation: 'trust_read' | 'trust_preview' | 'trust_apply', params: Record<string, unknown>): Promise<Record<string, unknown>> => {
- const delegated = await maybeDelegateLocalAdministration(operation, params, config);
+ const call = async (operation: 'trust_read' | 'trust_preview' | 'trust_apply', params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>> => {
+ const delegated = await maybeDelegateLocalAdministration(operation, params, config, { timeoutMs });
if (!delegated.handled) throw opError('owner_unavailable', 'The running serve stopped before the trust action; nothing was changed.', 'Run the same command again.');
return delegated.result as Record<string, unknown>;
};
@@ -232,7 +233,7 @@ export async function maybeDelegateTrust(hostConfig: GBrainConfig | null, args:
review: async filter => await call('trust_read', { view: 'review', filter: { source: filter.sourceId, kind: filter.kind, since: filter.since?.toISOString() } }) as unknown as TrustReview,
explain: async (query, source) => (await call('trust_read', { view: 'explain', query, source })).items as TrustExplanation[],
preview: async input => await call('trust_preview', { input }) as unknown as OwnerActionPreview,
- apply: async (input, binding, confirmed) => await call('trust_apply', { input, binding, ...(confirmed ? { confirmed: 'tty' } : {}) }) as unknown as OwnerActionResult,
+ apply: async (input, binding, confirmed) => await call('trust_apply', { input, binding, ...(confirmed ? { confirmed: 'tty' } : {}) }, DOOR_WAIT_MS + 30_000) as unknown as OwnerActionResult,
};
await runTrustOwnerCommand(backend, sub!, rest);
return true;
diff --git a/src/core/trust/release-publish.ts b/src/core/trust/release-publish.ts
index cbc5adadba..d2fcf42e99 100644
--- a/src/core/trust/release-publish.ts
+++ b/src/core/trust/release-publish.ts
@@ -37,7 +37,7 @@ import { materializedPage } from '../persistence/segmented-apply.ts';
import { getWriteGateHold, releaseWriteGateHold, type WriteGateHold } from '../write-gate-store.ts';
export const TRUST_RELEASE_OPERATION = 'trust_release';
-const DOOR_WAIT_MS = 60_000;
+export const DOOR_WAIT_MS = 60_000;
interface ReleaseIntent { hold_id: number; last_seen_at: string; by: string; mode: 'append' | 'index-existing'; row_num?: number }
diff --git a/test/trust-owner-ipc.test.ts b/test/trust-owner-ipc.test.ts
index 1a3783dc21..be580ee270 100644
--- a/test/trust-owner-ipc.test.ts
+++ b/test/trust-owner-ipc.test.ts
@@ -15,7 +15,7 @@
* Fails if any of those paths opens, or the CLI stops delegating.
* PGLite only (the resident-owner socket is a PGLite topology).
*/
-import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { afterAll, beforeAll, describe, expect, spyOn, test } from 'bun:test';
import { once } from 'node:events';
import { randomUUID } from 'node:crypto';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
@@ -38,6 +38,8 @@ import { __setConfirmationIoForTests } from '../src/core/trust/confirm.ts';
import { getTrustProposal } from '../src/core/trust/proposals.ts';
import { TRUST_ADMIN_OPERATIONS, runTrustAdministration } from '../src/core/trust/owner-ipc.ts';
import { maybeDelegateTrust } from '../src/commands/trust.ts';
+import * as localClient from '../src/core/persistence/local-client.ts';
+import { DOOR_WAIT_MS } from '../src/core/trust/release-publish.ts';
import { reviewedWriterIntent } from './helpers/writer-admin-intent.ts';
import { withEnv } from './helpers/with-env.ts';
import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';
@@ -141,6 +143,25 @@ describe('gbrain trust through the resident owner (DX-2)', () => {
expect((await getTrustProposal(engine, id))!.status).toBe('accepted');
expect(await tier('notes/ipc-two-example')).toBe('user_confirmed');
}, 120_000);
+
+ test('the CLI waits for trust_apply past the release door\'s own wait, so a slow release ends in its receipt, not owner_unavailable', async () => {
+ const { tp } = await loweredPage('notes/ipc-three-example');
+ const input = new PassThrough();
+ const output = new PassThrough();
+ let prompt = '';
+ output.on('data', chunk => { prompt += String(chunk); if (prompt.includes('to confirm')) input.write(`${tp}\n`); });
+ __setConfirmationIoForTests({ probe: { stdinIsTTY: true, stdoutIsTTY: true, env: { GBRAIN_INTERACTIVE: '1' } }, input, output, timeoutMs: 5000 });
+ const delegate = spyOn(localClient, 'maybeDelegateLocalAdministration');
+ const log = console.log;
+ console.log = () => {};
+ try {
+ expect(await withEnv({ GBRAIN_HOME: dir, ...ENV }, () => maybeDelegateTrust(config as never, ['confirm', tp]))).toBe(true);
+ } finally { console.log = log; __setConfirmationIoForTests(null); }
+ const apply = delegate.mock.calls.find(call => call[0] === 'trust_apply');
+ delegate.mockRestore();
+ expect(apply).toBeDefined();
+ expect(apply![3]?.timeoutMs).toBeGreaterThan(DOOR_WAIT_MS);
+ }, 120_000);
});
describe('an MCP session cannot reach the owner actions (ENG-15)', () => {