Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

graduation(G3): merge G2b; drop graduation casts, migrate --status/--plan read-only in the contract scanner, drain refusal reason for the exit map

garrytan26c88d3c186f
diff --git a/scripts/check-agent-contract.ts b/scripts/check-agent-contract.ts
index 0df1900963..da1b29affb 100644
--- a/scripts/check-agent-contract.ts
+++ b/scripts/check-agent-contract.ts
@@ -109,7 +109,9 @@ function literalProp(obj: ts.ObjectLiteralExpression, name: string): string | un
/** Read-only invocations a verify step may always name (doctor --only is the canonical one). */
const STATIC_READ_ONLY = new Set(['doctor', 'errors', 'status', 'get', 'search', 'query', 'list', 'write-request', 'write-requests', 'whoami', 'stats']);
/** Read-only subcommands of otherwise-mutating commands. */
-const READ_ONLY_SUBCOMMANDS = new Set(['config get', 'sources list', 'sources status', 'jobs get', 'jobs stats', 'jobs list', 'auth list', 'backup status', 'engine status']);
+const READ_ONLY_SUBCOMMANDS = new Set(['config get', 'sources list', 'sources status', 'jobs get', 'jobs stats', 'jobs list', 'auth list', 'backup status', 'engine status',
+ // Engine graduation: --status and --plan are zero-mutation (pre-connect; no schema migration, no target DDL).
+ 'migrate --status', 'migrate --plan']);
function tsFiles(dir: string): string[] {
if (!existsSync(dir)) return [];
diff --git a/src/core/persistence/graduation-drain.ts b/src/core/persistence/graduation-drain.ts
index 9b65f113bf..3714230c79 100644
--- a/src/core/persistence/graduation-drain.ts
+++ b/src/core/persistence/graduation-drain.ts
@@ -142,7 +142,7 @@ export function drainTimeoutError(blockers: readonly GraduationBlocker[], timeou
return graduationError('graduation_drain_timeout', `The drain did not finish within ${seconds}s; ${blockers.length} item(s) remain.`,
needsPerson ? `Clear ${needsPerson.kind} ${needsPerson.id} first (${needsPerson.argv?.join(' ') ?? 'see detail'}), then resume.` : `Resume with a longer drain: ${resume.join(' ')}.`,
{ why: `Graduation copies only a drained brain; the source is unchanged and still writable. Remaining: ${listed}`,
- detail: listed,
+ detail: listed, reason: needsPerson ? 'blocked' : 'progressing',
fix: needsPerson?.argv
? { argv: [...needsPerson.argv], consent: [], actor: needsPerson.needsUser ? 'user' : 'agent', requires_exclusive: false,
why: `Clears ${needsPerson.kind} ${needsPerson.id}, which the request-only drain cannot finish.`,
diff --git a/src/core/persistence/graduation-target.ts b/src/core/persistence/graduation-target.ts
index 62505e90ad..5f6f3e37b3 100644
--- a/src/core/persistence/graduation-target.ts
+++ b/src/core/persistence/graduation-target.ts
@@ -21,7 +21,6 @@ import { PostgresEngine } from '../postgres-engine.ts';
import { normalizeDirectUrl, isNetworkUnreachableError } from '../connection-manager.ts';
import { redactConnectionInfo } from '../audit/redact-connection-info.ts';
import { opError, type OpErrorOpts, type OperationError } from '../ops/contract.ts';
-import type { RegistryCode } from '../error-registry.ts';
import type { EmbeddingColumn, GraduationBlocker, GraduationErrorCode, TargetIdentity, TargetProbe, TargetRoutes, TriggerBypass } from './engine-graduation.types.ts';
export type ResolvedTargetRoutes = TargetRoutes & { mainUrl: string; ddlUrl: string };
@@ -33,9 +32,9 @@ export const MIN_TARGET_SERVER_VERSION_NUM = 140000;
/** pgvector release that added halfvec (facts.embedding, query_cache.embedding). */
export const MIN_VECTOR_HALFVEC_VERSION = '0.7.0';
-/** Graduation codes are registered by the agent-contract batch; until then they are typed by the shared list. */
+/** A graduation refusal (every GraduationErrorCode has a registry row in src/core/error-registry.ts). */
export function graduationError(code: GraduationErrorCode, message: string, suggestion: string, opts: OpErrorOpts = {}): OperationError {
- return opError(code as RegistryCode, message, suggestion, opts);
+ return opError(code, message, suggestion, opts);
}
export function targetPlanArgv(routes: Pick<TargetRoutes, 'urlEnv'>, to: 'postgres' | 'supabase' = 'postgres'): string[] {
diff --git a/test/migrate-graduation-cli.serial.test.ts b/test/migrate-graduation-cli.serial.test.ts
index 7246685600..ba7715c777 100644
--- a/test/migrate-graduation-cli.serial.test.ts
+++ b/test/migrate-graduation-cli.serial.test.ts
@@ -18,6 +18,7 @@ import type {
GraduationCommandOptions, GraduationPlan, GraduationReceipt, GraduationStatusDoc,
} from '../src/core/persistence/engine-graduation.types.ts';
import { drainTimeoutError, inProgressError } from '../src/core/persistence/graduation-errors.ts';
+import { drainTimeoutError as drainRefusal } from '../src/core/persistence/graduation-drain.ts';
import {
parseGraduationArgs, routesToGraduation, runMigrateGraduation, type GraduationApi,
} from '../src/commands/migrate-graduation.ts';
@@ -222,6 +223,10 @@ describe('runMigrateGraduation', () => {
expect(JSON.parse(drain.stdout).resume_command).toEqual(['gbrain', 'migrate', '--resume', '--drain-timeout', '120']);
const blocked = await run(['--resume', '--json'], fakeApi({ resumeGraduation: async () => { throw drainTimeoutError({ timeoutSec: 60, blockers: [{ kind: 'writer_admin_lock', id: 'l', detail: 'locked', argv: ['gbrain', 'sources', 'writer', 'unlock'], needsUser: true }] }); } }));
expect(blocked.code).toBe(1);
+ const orchestratorBlocked = await run(['--resume', '--json'], fakeApi({ resumeGraduation: async () => { throw drainRefusal([{ kind: 'dangling_reference', id: 'oauth_clients.c1', detail: 'bound to a missing source', argv: ['gbrain', 'auth', 'revoke-client', 'c1'], needsUser: true }], 60_000); } }));
+ expect(orchestratorBlocked.code).toBe(1);
+ const orchestratorProgressing = await run(['--resume', '--json'], fakeApi({ resumeGraduation: async () => { throw drainRefusal([{ kind: 'request', id: 'r', detail: 'running', needsUser: false }], 60_000); } }));
+ expect(orchestratorProgressing.code).toBe(11);
const busy = await run(['--resume', '--json'], fakeApi({ resumeGraduation: async () => { throw inProgressError({ pid: 9 }); } }));
expect(busy.code).toBe(75);
const ctrl = new AbortController();