Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sources): a local_path that aliases the bound root is current, so claim and rebind through it stay no-ops
time-attack5bcbb2ae0961
diff --git a/src/core/persistence/source-lifecycle.ts b/src/core/persistence/source-lifecycle.tsindex 343dd64816..c963820b31 100644--- a/src/core/persistence/source-lifecycle.ts+++ b/src/core/persistence/source-lifecycle.ts@@ -197,7 +197,7 @@ export async function runManagedSourceLifecycle(engine:BrainEngine,input:SourceL`Claim '${input.sourceId}' at the local_path the command in fix reports, or move it to the new directory with gbrain sources set-path ${input.sourceId}; nothing was claimed.`,{fix:sourcesListFix()});const expired=input.expiredOnly?await tx.executeRaw(`SELECT id FROM sources WHERE id=$1 AND ${EXPIRED_ARCHIVE_SQL}`,[input.sourceId]):null;const noop=expired?.length===0 || input.operation==='archive'&&source?.archived || input.operation==='restore'&&!source?.archived- || ['claim','rebind'].includes(input.operation)&&sameBinding&&source?.local_path===root!.source;+ || ['claim','rebind'].includes(input.operation)&&sameBinding&&!!source?.local_path&&nativeFilesystemPath(source.local_path)===nativeFilesystemPath(root!.source);if(noop){await lockTopologyPrincipal(tx,principal);return topologyReceipt(await recordTopologyChange(tx,{principal,requestId,intent,operation:input.operation,sourceId:input.sourceId,incarnation:source!.incarnation,worktrees},diff --git a/test/persistence-source-lifecycle.test.ts b/test/persistence-source-lifecycle.test.tsindex 10195f4303..01eb055c41 100644--- a/test/persistence-source-lifecycle.test.ts+++ b/test/persistence-source-lifecycle.test.ts@@ -1,7 +1,7 @@import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { randomUUID } from 'node:crypto';import { execFileSync } from 'node:child_process';-import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';+import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { basename, join } from 'node:path';import { isPhysicalRootMetadata } from '../src/core/persistence/physical-root.ts';import { tmpdir } from 'node:os';@@ -101,6 +101,18 @@ test('set-path at the bound checkout repairs a stale sources.local_path insteadexpect(again.noop).toBe(true);}));+test('a local_path that is an alias (symlink) of the bound root is current: claim and rebind through it are no-ops',()=>fixture(async(home,source,root)=>{+ const alias=join(home,'alias-root');symlinkSync(realpathSync(root),alias);+ await engine.transaction(async tx=>{+ await tx.executeRaw("SELECT set_config('gbrain.topology_change','on',true)");+ await tx.executeRaw('UPDATE sources SET local_path=$2 WHERE id=$1',[source,alias]);+ });+ for(const operation of ['claim','rebind'] as const){+ expect(await runManagedSourceLifecycle(engine,{operation,sourceId:source,path:alias})).toMatchObject({state:'committed',noop:true});+ expect(await engine.executeRaw('SELECT local_path FROM sources WHERE id=$1',[source])).toEqual([{local_path:alias}]);+ }+}));+test('rebind requires exact manifest including deletion and old path remains fenced',()=>fixture(async(home,source,root)=>{const candidate=join(home,'candidate');cpSync(root,candidate,{recursive:true,filter:path=>!isPhysicalRootMetadata(basename(path))});writeFileSync(join(candidate,'extra.md'),'Unexpected');