Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes, cycle 3 (#7630)
garrytan126c1e8ac1b8
diff --git a/src/commands/brainstorm.ts b/src/commands/brainstorm.tsindex 3ec13e1990..4f10a9e2e7 100644--- a/src/commands/brainstorm.ts+++ b/src/commands/brainstorm.ts@@ -491,7 +491,7 @@ export function formatSaveOutcome(}if (dbSaved && writeThrough.skipped === 'repo_not_found') {return {- stdout: `\n_Saved to DB page \`${ctx.slug}\` (the source directory, \`sources.local_path\` or \`sync.repo_path\`, is not an absolute directory — skipped file write)._`,+ stdout: `\n_Saved to DB page \`${ctx.slug}\` (the source directory, \`sources.local_path\` or \`sync.repo_path\`, is relative or not a directory — skipped file write)._`,stderr,exitCode: 0,};diff --git a/src/commands/doctor/checks/default-source-path.ts b/src/commands/doctor/checks/default-source-path.tsindex c8f90b2949..8c11dc6104 100644--- a/src/commands/doctor/checks/default-source-path.ts+++ b/src/commands/doctor/checks/default-source-path.ts@@ -86,6 +86,6 @@ export async function defaultSourceLocalPathCheck(engine: BrainEngine): Promise<return {name: 'default_source_local_path',status: relative.length > 0 || assessment.status === 'skip' ? 'warn' : assessment.status,- message: [assessment.message, relativeNote].filter(Boolean).join(' '),+ message: [relativeNote, assessment.message].filter(Boolean).map(part => /[.!?]$/.test(part) ? part : `${part}.`).join(' '),};}diff --git a/src/commands/migrations/v0_11_0-install.ts b/src/commands/migrations/v0_11_0-install.tsindex d85de30b28..d505881f7d 100644--- a/src/commands/migrations/v0_11_0-install.ts+++ b/src/commands/migrations/v0_11_0-install.ts@@ -106,14 +106,14 @@ async function readRepoPaths(config: GBrainConfig | null): Promise<{ syncRepoPatfunction skipWithoutRepo(defaultSourcePath: string | null): OrchestratorPhaseResult {if (autopilotInstalledForBrain()) {- return { name: 'install', status: 'skipped', reason: 'autopilot_already_installed', detail: 'sync.repo_path is unset and an autopilot is already installed for this brain; left as is' };+ return { name: 'install', status: 'skipped', reason: 'autopilot_already_installed', detail: 'sync.repo_path is unset or relative and an autopilot is already installed for this brain; left as is' };}recordSkippedAutopilotInstall(defaultSourcePath);const command = autopilotInstallCommand(defaultSourcePath);- console.log(`No autopilot was installed: sync.repo_path is unset. Install it when you want background maintenance: ${command} `+ console.log(`No autopilot was installed: sync.repo_path is unset or relative. Install it when you want background maintenance: ${command} `+ `(recorded in ${pendingHostWorkPath()}; gbrain doctor shows it until an autopilot is installed)`);return {- name: 'install', status: 'skipped', reason: 'no_repo_path', detail: `sync.repo_path is unset, so the upgrade installed no autopilot. Install it: ${command}`,+ name: 'install', status: 'skipped', reason: 'no_repo_path', detail: `sync.repo_path is unset or relative, so the upgrade installed no autopilot. Install it: ${command}`,...(defaultSourcePath ? { argv: autopilotInstallArgv(defaultSourcePath) } : {}),};}@@ -164,7 +164,7 @@ export async function clearRepoPathWedge(completed: readonly CompletedMigrationEconst repo = await readRepoPaths(config).catch(() => null);if (!repo || repo.syncRepoPath) return false;appendCompletedMigration({ version: '0.11.0', status: 'retry', reason: 'phase_f_no_repo_path' });- console.error('Cleared the v0.11.0 wedge: every partial run failed only the autopilot install, and sync.repo_path is unset. '+ console.error('Cleared the v0.11.0 wedge: every partial run failed only the autopilot install, and sync.repo_path is unset or relative. '+ 'This version skips that install, so the migration runs again now.');return true;}diff --git a/src/core/persistence/terminal-classify.ts b/src/core/persistence/terminal-classify.tsindex 9d707ca959..8ceb28dd1c 100644--- a/src/core/persistence/terminal-classify.ts+++ b/src/core/persistence/terminal-classify.ts@@ -339,7 +339,7 @@ function schemaMissingVerdict(input: TerminalInput, code: string, origin: string}/** #7630: the caller-submitted page and memory writes a caller resubmits; no sync replays them. */-const RESUBMITTED_WRITES = new Set(['put_page', 'put_pages', 'capture', 'delete_page', 'restore_page', 'revert_version', 'edit_page', 'append_page', 'remember', 'forget',+const RESUBMITTED_WRITES = new Set(['put_page', 'put_pages', 'capture', 'delete_page', 'restore_page', 'revert_version', 'edit_page', 'append_page', 'remember', 'forget', 'forget_fact','add_tag', 'remove_tag', 'add_link', 'remove_link', 'add_timeline_entry', 'takes_add', 'takes_update', 'takes_supersede', 'takes_resolve', 'takes_remove']);/**diff --git a/src/core/persistence/terminal-failures.ts b/src/core/persistence/terminal-failures.tsindex ad19d324b6..ce16287aa3 100644--- a/src/core/persistence/terminal-failures.ts+++ b/src/core/persistence/terminal-failures.ts@@ -290,6 +290,8 @@ export interface TerminalFailureRow {}export interface TerminalFailureGroup {code: string; origin: string | null; category: TerminalCategory; public_category: PublicCategory; rows: number; class: string; needs_human: boolean; human_reason?: string;+ /** #7630: a sync fault's fix depends on its operation (a sync retries submit_job; a caller resubmits its own write), so those groups split by it. */+ operation?: string;filter: { code: string; origin: string | null; category: TerminalCategory }; drill_down: string[]; fix: Action; samples: Array<Pick<TerminalFailureRow, 'request_id' | 'slug' | 'state' | 'ended_at' | 'inspect'>>;}export type TerminalFailureListing = {@@ -369,11 +371,12 @@ export async function readTerminalFailures(engine: BrainEngine, q: TerminalFailu}const groups = new Map<string, TerminalFailureGroup>();for (const row of out) {- const key = `${row.code}\0${row.origin ?? ''}\0${row.category}`;+ const operation = row.category === 'sync_fault' && row.operation !== 'submit_job' ? row.operation : undefined;+ const key = `${row.code}\0${row.origin ?? ''}\0${row.category}${operation === undefined ? '' : `\0${operation}`}`;let g = groups.get(key);if (!g) {const filter = { code: row.code, origin: row.origin, category: row.category };- groups.set(key, g = { code: row.code, origin: row.origin, category: row.category, public_category: row.public_category, rows: 0, class: row.class, needs_human: row.needs_human,+ groups.set(key, g = { code: row.code, origin: row.origin, category: row.category, ...(operation === undefined ? {} : { operation }), public_category: row.public_category, rows: 0, class: row.class, needs_human: row.needs_human,...(row.human_reason ? { human_reason: row.human_reason } : {}), filter, fix: row.fix, samples: [],drill_down: terminalFailuresArgv({ sourceId: q.sourceId, state: q.state, sinceDays: q.sinceDays, category: row.category, code: row.code, origin: row.origin ?? NO_ORIGIN }) });}diff --git a/test/sync-relative-anchor-refusal-7630.test.ts b/test/sync-relative-anchor-refusal-7630.test.tsindex 0814f510f9..4146be0e9b 100644--- a/test/sync-relative-anchor-refusal-7630.test.ts+++ b/test/sync-relative-anchor-refusal-7630.test.ts@@ -526,7 +526,7 @@ describe('#7630: a stalled write\'s diagnosis matches its operation', () => {operation, state: 'failed', error_code: 'preparation_stalled', error_detail: null, recovery: null, blocked_reason: null, compacted: false, intent_kind: null })!;const mcp = { transport: 'stdio' as const, isCallable: () => false, preapproved: () => false };- for (const operation of ['remember', 'put_page', 'add_tag', 'add_link', 'add_timeline_entry', 'takes_add']) {+ for (const operation of ['remember', 'put_page', 'add_tag', 'add_link', 'add_timeline_entry', 'takes_add', 'forget_fact']) {test(`a foreground ${operation} that ended preparation_stalled inspects the writer and resubmits, never a sync`, () => {const verdict = receipt(operation);expect(verdict.action.argv).toEqual(['gbrain', 'sources', 'writer', 'status', '--source', 'default', '--json']);diff --git a/test/terminal-failures-6650.test.ts b/test/terminal-failures-6650.test.tsindex 9a781aaba0..8b290b1e85 100644--- a/test/terminal-failures-6650.test.ts+++ b/test/terminal-failures-6650.test.ts@@ -393,6 +393,25 @@ for (const kind of testBackends()) describe(`the aggregate, doctor and the drillexpect(filtered.rows!.map(r => r.request_id)).toEqual([opaque]);});+ // #7630: a stalled sync receipt retries through sync while a stalled foreground write is resubmitted by its caller, so the+ // grouped view splits a sync-fault group by operation and every group's fix fits each of its rows.+ test('a preparation_stalled group splits sync receipts from foreground writes, each with its own fix', async () => {+ await seed({ slug: 'notes/s', operation: 'submit_job', state: 'failed', code: 'preparation_stalled' });+ await seed({ slug: 'notes/p', operation: 'put_page', state: 'failed', code: 'preparation_stalled' });+ await seed({ slug: 'notes/r', operation: 'remember', state: 'failed', code: 'preparation_stalled' });+ const grouped = await readTerminalFailures(engine, { sourceId: SOURCE, groupBy: 'category' });+ if (grouped.status !== 'ok') throw new Error('unknown');+ const stalled = grouped.groups!.filter(g => g.code === 'preparation_stalled');+ expect(stalled.map(g => g.operation ?? null).sort()).toEqual([null, 'put_page', 'remember'].sort());+ expect(stalled.find(g => g.operation === undefined)!.fix.argv?.slice(0, 2)).toEqual(['gbrain', 'sync']);+ for (const op of ['put_page', 'remember']) {+ const g = stalled.find(x => x.operation === op)!;+ expect(g.rows).toBe(1);+ expect(g.fix.argv).toEqual(['gbrain', 'sources', 'writer', 'status', '--source', SOURCE, '--json']);+ expect(g.fix.why).toContain(`resubmit the same ${op}`);+ }+ });+test('a read past its statement deadline is unknown, and doctor says health is unknown', async () => {await seed({ slug: 'notes/x', state: 'failed', code: 'storage_error', compacted: true });const slow = new Proxy(engine, { get(target, key) {