Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Opt-in and MCP train: the automatic first-write claim refuses a missing or moved checkout without a path

garrytan2458310a4f4e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 52ba70ee30..3b1a584dee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -73,10 +73,10 @@ A moved brain folder (#8950):
- `src/core/persistence/physical-root-record.ts`: `describeMovedPhysicalRoot` (read-only file evidence: the stamp's recorded root is gone, and the reservation of that root, beside it or beside the new root after a parent rename, carries the stamp's token, brain and worktree; `sameDirectory` from device, inode and birth time), `physicalRootMovedError` (path-free) and `physicalRootMovedRefusal` (the local CLI refusal with an `ask_user` fix chain in argv form, paths shell-quoted in the prose). An ownership stamp other users can read at the new path now refuses `ownership_record_not_private` instead of the generic error.
- `src/core/persistence/physical-root.ts`: `movedPhysicalRoot` accepts the evidence only for this brain, a worktree this host owns and a host binding still at the recorded root; `reservePhysicalRoot` raises the path-free refusal on its copied-marker branch.
-- `src/core/persistence/source-lifecycle.ts`, `topology-locks.ts`, `administration.ts`: `add`, `claim`, `rebind` and `writer claim` build the full refusal (never for the automatic first-write claim); their dry runs predict it, and a rebind dry run of a missing checkout refuses `source_checkout_missing` like the real run.
+- `src/core/persistence/source-lifecycle.ts`, `topology-locks.ts`, `administration.ts`: `add`, `claim`, `rebind` and `writer claim` build the full refusal (never for the automatic first-write claim); their dry runs predict it, and a rebind dry run of a missing checkout refuses `source_checkout_missing` like the real run. When the automatic first-write claim finds a missing or moved checkout under the source's folder, it now refuses path-free too (`physical_root_moved`, or the path-free `source_checkout_missing`). Before this, a remote page write in that layout was told the checkout's host path.
- `src/core/persistence/verb-errors.ts`, `src/core/error-registry.ts`: the `physical_root_moved` reason and its explanation; `docs/guides/error-codes.md` regenerated.
- Docs: `docs/architecture/topologies.md#moved-root`, `docs/guides/write-refusals.md#moved-root`.
-- Tests: `test/physical-root-moved-8625.test.ts` (PGLite and Postgres: leaf and parent moves, bound and removed sources, Git and plain directories, a copy on a new inode, two sources in one worktree, `writer claim --dry-run`, five lookalikes that keep the generic refusal, a readable stamp, the classic keyless set-path, and a remote `put_page` whose refusal carries no path or worktree id).
+- Tests: `test/physical-root-moved-8625.test.ts` (PGLite and Postgres: leaf and parent moves, bound and removed sources, Git and plain directories, a copy on a new inode, two sources in one worktree, `writer claim --dry-run`, five lookalikes that keep the generic refusal, a readable stamp, the classic keyless set-path, and a remote `put_page` whose refusal carries no path or worktree id, before activation and on an activated brain with a moved checkout under the unbound source's folder).
## [0.60.657.0] - 2026-11-11
diff --git a/src/core/persistence/source-lifecycle.ts b/src/core/persistence/source-lifecycle.ts
index 1fcbdb2a34..ec2c544850 100644
--- a/src/core/persistence/source-lifecycle.ts
+++ b/src/core/persistence/source-lifecycle.ts
@@ -25,7 +25,8 @@ import { managedFilesystemDatastorePath, refreshManagedFilesystemRoots } from '.
import { canonicalFilesystemPath, nativeFilesystemPath } from './root-registry.ts';
import { flushTopologyDirectory } from './topology-filesystem.ts';
import { claimPhysicalRoot, movedPhysicalRootRefusal } from './physical-root.ts';
-import { inspectRelocatedPhysicalRoot, relocatePhysicalRoot } from './physical-root-record.ts';
+import { inspectRelocatedPhysicalRoot, physicalRootMovedError, relocatePhysicalRoot } from './physical-root-record.ts';
+import { sourceCheckoutMissingRefusal } from './verb-errors.ts';
import { assertWriterAdminState, WRITER_INSPECTION_HINT } from './admin-intent.ts';
import { assertWriterAdminUnlocked } from './admin-lock.ts';
import { rebindContentReceipts } from '../shared-skills/receipt-root.ts';
@@ -203,7 +204,10 @@ export async function runManagedSourceLifecycle(engine:BrainEngine,input:SourceL
if(input.operation==='add'&&input.createDirectory&&path===root?.worktree)continue;
// #5219: retiring may skip a vanished checkout; the transaction proves the source is empty and its sole member.
if(retire&&!root){missingCheckout=path;continue;}
- throw (root&&await movedPhysicalRootRefusal(engine,root.worktree,exit,hostIdFor(engine),path))||missingCheckoutError(input.sourceId,path);
+ const moved=root&&await movedPhysicalRootRefusal(engine,root.worktree,exit,hostIdFor(engine),path);
+ // #8625: the automatic first-write claim stays path-free, since a remote page write can reach it.
+ if(input.automaticClaim) throw moved?physicalRootMovedError():sourceCheckoutMissingRefusal(input.sourceId,null);
+ throw moved||missingCheckoutError(input.sourceId,path);
}
if(!manifestRequired)continue;
const manifest=worktreeManifest(path,{progress:humanManifestProgress()});
diff --git a/test/physical-root-moved-8625.test.ts b/test/physical-root-moved-8625.test.ts
index c9843be0d0..72c0204d64 100644
--- a/test/physical-root-moved-8625.test.ts
+++ b/test/physical-root-moved-8625.test.ts
@@ -291,3 +291,34 @@ if (testBackends().includes('pglite')) describe('#8625 a remote page write never
});
}, 120_000);
});
+
+if (testBackends().includes('pglite')) describe('#8625 a remote page write never sees the moved checkout\'s paths (pglite, activated brain)', () => {
+ const directory = realpathSync.native(mkdtempSync(join(tmpdir(), 'gbrain-moved-remote-active-')));
+ let engine: PGLiteEngine;
+ beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); }, 120_000);
+ afterAll(async () => { await engine.disconnect(); rmSync(directory, { recursive: true, force: true }); });
+
+ test('remote put_page to an unbound source above a moved bound checkout refuses without a path or worktree id', async () => {
+ const home = join(directory, 'home'), parent = join(directory, 'brains', 'a'), root = join(parent, 'brain'), aside = join(directory, 'brains', 'aside');
+ mkdirSync(root, { recursive: true }); writeFileSync(join(root, 'alice-example.md'), '# Alice Example\n\nA note.\n');
+ await withEnv({ GBRAIN_HOME: home, GBRAIN_BRAIN_ID: 'host', GBRAIN_SOURCE: undefined }, async () => {
+ try {
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['source-a', root]);
+ const worktreeId = (await claimWorktree(engine, 'source-a', root)).worktree_id;
+ await engine.executeRaw('INSERT INTO sources(id,name,local_path) VALUES($1,$1,$2)', ['source-b', parent]);
+ await engine.setConfig('sync.write_through', 'true');
+ await engine.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');
+ await registerLocalWriter(engine, 'cli');
+ renameSync(root, aside); rmSync(parent, { recursive: true }); renameSync(aside, parent);
+ const result = await dispatchToolCall(engine, 'put_page', { slug: 'notes/alice-example', content: '---\ntype: note\ntitle: Alice Example\n---\n# Alice Example\n' },
+ { remote: true, transport: 'stdio', sourceId: 'source-b', admissionOrigin: 'interactive' });
+ expect(result.isError).toBe(true);
+ const text = result.content[0]!.text;
+ expect(JSON.parse(text)).toMatchObject({ code: 'recovery_required' });
+ for (const secret of [directory, root, parent, worktreeId]) expect(text).not.toContain(secret);
+ expect(existsSync(join(parent, 'notes'))).toBe(false);
+ } finally { await disposePersistenceConsumer(engine); }
+ });
+ }, 120_000);
+});