Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#7630): doctor finds an absolute owner beside a relative sibling and drops the healthy fallback text; canonical reconcile keeps the sync retry; v0.11.0 wedge test for a relative path

garrytan23886a710ce8
diff --git a/src/commands/doctor/checks/default-source-path.ts b/src/commands/doctor/checks/default-source-path.ts
index a51e8e77e8..551b1a2808 100644
--- a/src/commands/doctor/checks/default-source-path.ts
+++ b/src/commands/doctor/checks/default-source-path.ts
@@ -57,11 +57,8 @@ export async function defaultSourceLocalPathCheck(engine: BrainEngine): Promise<
}
// Mirror resolvePageWriteTarget's #2018 leak guard: sync.repo_path
// being another source's own working tree silently skips the write.
- collidingSourceId = await otherSourceOwning(engine, 'default', repoPath);
- if (collidingSourceId && relative.some(row => row.id === collidingSourceId)) {
- blockedByRelative = true;
- collidingSourceId = null;
- }
+ blockedByRelative = relative.length > 0;
+ collidingSourceId = await otherSourceOwning(engine, 'default', repoPath, false);
if (collidingSourceId) {
const [shared] = await engine.executeRaw<{ n: number }>(
`SELECT COUNT(*)::int AS n FROM pages a
@@ -92,6 +89,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: relativeNote ? [relativeNote, assessment.message].filter(Boolean).map(part => /[.!?]$/.test(part) ? part : `${part}.`).join(' ') : assessment.message,
+ message: relativeNote ? [relativeNote, blockedByRelative && assessment.status === 'ok' ? '' : assessment.message].filter(Boolean).map(part => /[.!?]$/.test(part) ? part : `${part}.`).join(' ') : assessment.message,
};
}
diff --git a/src/core/persistence/terminal-classify.ts b/src/core/persistence/terminal-classify.ts
index 8ceb28dd1c..0a66935838 100644
--- a/src/core/persistence/terminal-classify.ts
+++ b/src/core/persistence/terminal-classify.ts
@@ -349,6 +349,9 @@ const RESUBMITTED_WRITES = new Set(['put_page', 'put_pages', 'capture', 'delete_
*/
function faultAction(code: string, input: TerminalInput): Action {
const v = classifySyncFault({ code });
+ if (v.safe_actions[0] === 'retry' && input.intent_kind === 'canonical_reconcile') {
+ return syncRetry(input.source_id, `The canonical reconcile recorded ${code} (${v.class}); the next sync re-admits a keep_db reconcile, and a \`gbrain sources reconcile\` run is retried by running it again.`);
+ }
if (v.safe_actions[0] === 'retry' && input.operation !== 'submit_job' && !RESUBMITTED_WRITES.has(input.operation)) {
return inspect(input.source_id, `The ${input.operation} operation ended ${code}; it was not part of a sync, so a sync does not retry it. Writer status names what holds it, read-only.`, v.human_reason);
}
diff --git a/src/core/write-through.ts b/src/core/write-through.ts
index 6cd10fbf09..58360aea71 100644
--- a/src/core/write-through.ts
+++ b/src/core/write-through.ts
@@ -284,9 +284,10 @@ export async function scannerSlugRootMode(engine: BrainEngine, sourceId: string,
* #2018/#7203: the other source whose own working tree is `path` or contains
* it, compared by filesystem identity, so a symlink, a trailing slash, or a
* macOS case or /private alias still matches. A spelling that cannot be
- * resolved counts as a match: the leak guard fails closed.
+ * resolved counts as a match: the leak guard fails closed. `relativeOwns: false`
+ * leaves out live relative rows, for doctor to find an absolute owner beside them.
*/
-export async function otherSourceOwning(engine: BrainEngine, sourceId: string, path: string): Promise<string | null> {
+export async function otherSourceOwning(engine: BrainEngine, sourceId: string, path: string, relativeOwns = true): Promise<string | null> {
const rows = await engine.executeRaw<{ id: string; local_path: string; archived: boolean }>(
`SELECT id, local_path, archived IS TRUE AS archived FROM sources WHERE id <> $1 AND local_path IS NOT NULL AND local_path <> '' ORDER BY id`,
[sourceId],
@@ -295,7 +296,7 @@ export async function otherSourceOwning(engine: BrainEngine, sourceId: string, p
const target = identity(path);
return rows.find(row => {
// #7630: a live source's relative local_path names no known tree, so like any unresolvable spelling it counts as a match.
- if (!isAbsolute(msysToNativePath(row.local_path))) return !row.archived;
+ if (!isAbsolute(msysToNativePath(row.local_path))) return relativeOwns && !row.archived;
const other = identity(row.local_path);
if (target === null || other === null) return true;
const rel = relative(other, target);
diff --git a/test/apply-migrations-safety.serial.test.ts b/test/apply-migrations-safety.serial.test.ts
index 5515805093..b8fd014f08 100644
--- a/test/apply-migrations-safety.serial.test.ts
+++ b/test/apply-migrations-safety.serial.test.ts
@@ -407,6 +407,18 @@ console.log('CHECK=' + JSON.stringify(autopilotInstallPendingCheck()));
});
}, 60_000);
+ for (const brain of [{ syncRepoPath: '.' }, { syncRepoPath: '.', defaultSourcePath: '.' }]) test(`install-only partials on a brain whose stored path is relative (${JSON.stringify(brain)}) are cleared and the migration completes`, async () => {
+ await postgresBrain(brain, async ({ ledger, calls, apply }) => {
+ const partial = (n: number) => JSON.stringify({ version: '0.11.0', ts: `2026-10-0${n}T00:00:00.000Z`, status: 'partial', phases: phaseRows(OLD_REFUSAL) });
+ writeFileSync(ledger, [partial(1), partial(2), partial(3)].join('\n') + '\n');
+ const run = apply(['--yes', '--migration', '0.11.0']);
+ expect(run.exitCode, run.stderr).toBe(0);
+ expect(run.stderr).toContain('Cleared the v0.11.0 wedge');
+ expect(entries(ledger).map(row => row.status)).toEqual(['partial', 'partial', 'partial', 'retry', 'complete']);
+ expect(calls()).not.toContain('autopilot');
+ });
+ }, 60_000);
+
for (const [label, row, brain] of [
['partials that carry no phases', { status: 'partial' }, {}],
['partials that also failed another phase', { status: 'partial', phases: [...phaseRows(OLD_REFUSAL).slice(0, 4), { name: 'host', status: 'failed', detail: 'boom' }, ...phaseRows(OLD_REFUSAL).slice(5)] }, {}],
diff --git a/test/sync-relative-anchor-refusal-7630.test.ts b/test/sync-relative-anchor-refusal-7630.test.ts
index 7aec1ab898..865487b53f 100644
--- a/test/sync-relative-anchor-refusal-7630.test.ts
+++ b/test/sync-relative-anchor-refusal-7630.test.ts
@@ -529,7 +529,12 @@ for (const backend of testBackends()) {
expect(check?.message).toContain('source "notes-a" has the relative local_path "."');
expect(check?.message).toContain('default-source pages are saved to the database only');
expect(check?.message).not.toContain('own working tree');
+ expect(check?.message).not.toContain('write through sync.repo_path');
expect(check?.message).not.toContain('notes-b');
+ await engine.executeRaw("INSERT INTO sources (id, name, local_path) VALUES ('z-abs', 'z-abs', $1)", [repo]);
+ const both = await defaultSourceLocalPathCheck(engine);
+ expect(both?.message).toContain('source "notes-a" has the relative local_path "."');
+ expect(both?.message).toContain('"z-abs"\'s own working tree');
} finally {
rmSync(repo, { recursive: true, force: true });
}
@@ -574,4 +579,12 @@ describe('#7630: a stalled write\'s diagnosis matches its operation', () => {
expect(classifyRecordedFault({ source_id: 'default', code: 'preparation_stalled' }).action.argv?.slice(0, 2)).toEqual(['gbrain', 'sync']);
expect(receipt('submit_job').action.argv?.slice(0, 2)).toEqual(['gbrain', 'sync']);
});
+
+ test('a stalled canonical reconcile (a sync pass keep_db admission, stored as put_page) keeps the sync retry and names the manual rerun', () => {
+ const verdict = classifyTerminal({ request_id: '11111111-2222-4333-8444-555555555555', source_id: 'default', slug: 'notes/example', operation: 'put_page',
+ state: 'failed', error_code: 'preparation_stalled', error_detail: null, recovery: null, blocked_reason: null, compacted: false, intent_kind: 'canonical_reconcile' })!;
+ expect(verdict.action.argv?.slice(0, 2)).toEqual(['gbrain', 'sync']);
+ expect(verdict.action.why).toContain('gbrain sources reconcile');
+ expect(verdict.action.why).not.toContain('new request_id');
+ });
});