Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): a relative local_path never proves anchor ownership; a foreign-OS sync.repo_path is not called relative (#7630)
garrytan2fffad394a03
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.mdindex 1f6d6bdc21..eef5f90237 100644--- a/docs/guides/error-codes.md+++ b/docs/guides/error-codes.md@@ -4157,7 +4157,7 @@ More: [docs/designs/GIT_CANONICAL_MEMORY.md#the-model](../../docs/designs/GIT_CA| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable ||---|---|---|---|---|---|---|-| Sync refused: the source's stored directory (sources.local_path, or sync.repo_path) is a relative path such as ".", which names whatever directory gbrain runs from. | A relative stored path cannot prove which folder is the brain. Before #7630 a sync run from an unrelated folder treated that folder as the brain repo: it Git-initialized it, committed everything in it and imported its markdown. gbrain now refuses before any Git probe or import, and nothing is changed. | Ask the user which directory holds the source, then gbrain sources set-path <id> <absolute-directory>; or clear the pointer with gbrain sources set-path <id> --clear. | user | `repeat the read that failed` | 3 | no |+| Sync refused: the source's stored directory (sources.local_path, or sync.repo_path) is a relative path such as ".", which names whatever directory gbrain runs from. | A relative stored path cannot prove which folder is the brain. Before #7630 a sync run from an unrelated folder treated that folder as the brain repo: it Git-initialized it, committed everything in it and imported its markdown. gbrain now refuses before any Git probe or import, and nothing is changed. | Ask the user which directory holds the source, then gbrain sources set-path <id> <absolute-directory>; or clear the pointer with gbrain sources set-path <id> --clear. A path that is absolute only on another operating system (a Windows drive path read on Linux or macOS) is refused the same way; set-path fixes it and --clear does not apply. | user | `repeat the read that failed` | 3 | no |More: [docs/guides/troubleshooting.md#relative-source-path](../../docs/guides/troubleshooting.md#relative-source-path)diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.mdindex fda64fc8d1..37aac2e35a 100644--- a/docs/guides/troubleshooting.md+++ b/docs/guides/troubleshooting.md@@ -848,6 +848,14 @@ Ask the user which directory holds the source, then do one of:is set again. On a managed brain, a source with a canonical owner refuses`--clear` (`writer_transfer_required`); point it at its directory instead.+A path that is absolute only on another operating system (a Windows drive path+such as `C:\brain-example`, set by another host sharing the brain, read on Linux+or macOS) is refused the same way, as not an absolute path on this host. Use+`set-path` with this host's directory (or `gbrain config set sync.repo_path` for+the legacy key); `--clear` refuses such a path. An explicit absolute `--repo`+passes the refusal, but it never advances the sync position of a source whose+stored path is relative.+Until the path is absolute, the main readers do not treat the folder gbrainruns from as the source either: page and fact writes skip the file and stay inthe database (`repo_not_found`, `no_repo_configured`), a captured file keepsdiff --git a/llms-full.txt b/llms-full.txtindex d2a80e608a..f8ecea6d88 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -11010,6 +11010,14 @@ Ask the user which directory holds the source, then do one of:is set again. On a managed brain, a source with a canonical owner refuses`--clear` (`writer_transfer_required`); point it at its directory instead.+A path that is absolute only on another operating system (a Windows drive path+such as `C:\brain-example`, set by another host sharing the brain, read on Linux+or macOS) is refused the same way, as not an absolute path on this host. Use+`set-path` with this host's directory (or `gbrain config set sync.repo_path` for+the legacy key); `--clear` refuses such a path. An explicit absolute `--repo`+passes the refusal, but it never advances the sync position of a source whose+stored path is relative.+Until the path is absolute, the main readers do not treat the folder gbrainruns from as the source either: page and fact writes skip the file and stay inthe database (`repo_not_found`, `no_repo_configured`), a captured file keepsdiff --git a/src/core/error-registry.ts b/src/core/error-registry.tsindex 8281f27f8c..30bbc17a0f 100644--- a/src/core/error-registry.ts+++ b/src/core/error-registry.ts@@ -688,7 +688,7 @@ export const CODES = {sync_anchor_relative: { class: 'consent', exit: 3, actor: 'user', docs: 'docs/guides/troubleshooting.md#relative-source-path',summary: "Sync refused: the source's stored directory (sources.local_path, or sync.repo_path) is a relative path such as \".\", which names whatever directory gbrain runs from.",why: "A relative stored path cannot prove which folder is the brain. Before #7630 a sync run from an unrelated folder treated that folder as the brain repo: it Git-initialized it, committed everything in it and imported its markdown. gbrain now refuses before any Git probe or import, and nothing is changed.",- suggestion: 'Ask the user which directory holds the source, then gbrain sources set-path <id> <absolute-directory>; or clear the pointer with gbrain sources set-path <id> --clear.' },+ suggestion: 'Ask the user which directory holds the source, then gbrain sources set-path <id> <absolute-directory>; or clear the pointer with gbrain sources set-path <id> --clear. A path that is absolute only on another operating system (a Windows drive path read on Linux or macOS) is refused the same way; set-path fixes it and --clear does not apply.' },sync_not_applicable: { class: 'caller', summary: "Sync does not apply to this source: its directory is not a Git checkout.", why: "Sync imports changes between Git commits. A gbrain-owned content directory (created by init) holds files gbrain manages itself and is not a Git repository, so there is nothing to sync; gbrain never initializes Git on its own.", reasons: ['content_directory'] },// #6712 PR 1: the drain lease (src/core/persistence/sync-lease.ts).sync_admission_restricted: { class: 'host_only', retryable: false, actor: 'user',diff --git a/src/core/sync-anchor.ts b/src/core/sync-anchor.tsindex 5dd5e42753..f325694a74 100644--- a/src/core/sync-anchor.ts+++ b/src/core/sync-anchor.ts@@ -143,6 +143,7 @@ export async function ownsSourceSyncAnchor();const configured = rows[0]?.local_path ?? null;if (configured === null) return { owns: true, configured: null };+ if (!isAbsolute(configured)) return { owns: false, configured };return { owns: sameRepoDir(configured, dir), configured };} catch {return { owns: true, configured: null };@@ -215,6 +216,7 @@ export async function sourceCommitAnchorAllowed(configured = rows[0]?.local_path ?? null;}if (configured === null) return { owns: true, configured: null };+ if (!isAbsolute(configured)) return { owns: false, configured };return { owns: sameOrNestedRepoDir(configured, repoDir), configured };} catch {return { owns: true, configured: null };diff --git a/src/core/sync-applicability.ts b/src/core/sync-applicability.tsindex 1571fc38ba..7c02cf4e4e 100644--- a/src/core/sync-applicability.ts+++ b/src/core/sync-applicability.ts@@ -98,11 +98,12 @@ export function syncAnchorRelativeError(sourceId: string | undefined, anchor: st? `The path is absolute only on another operating system (another host sharing this brain may have set it); on this host it would name a folder inside whatever directory gbrain runs from, so sync cannot use it here. Nothing was changed.`: `A relative path names whatever directory gbrain runs from, not a fixed folder, so it cannot prove which folder is the brain; syncing it from an unrelated folder would Git-initialize that folder, commit everything in it and import its markdown. Nothing was changed.`;if (!sourceId) {- return opError('sync_anchor_relative', `Sync refused: sync.repo_path is the relative path "${anchor}".`,+ const named = foreign ? `sync.repo_path is "${anchor}", which is not an absolute path on this host` : `sync.repo_path is the relative path "${anchor}"`;+ return opError('sync_anchor_relative', `Sync refused: ${named}.`,'Ask the user which directory holds the brain repo, then set it as an absolute path: gbrain config set sync.repo_path <absolute-directory>.',{ why, fix: { argv: ['gbrain', 'config', 'set', 'sync.repo_path', '<dir>'], consent: [], actor: 'user', ask_user: true, requires_exclusive: false,inputs: [{ name: 'dir', how: 'The absolute path of the brain repo, from the user; never the current directory by default.' }],- user_message: `gbrain's brain repo setting (sync.repo_path) is the relative path "${anchor}", so sync cannot tell which folder is the brain. Which directory holds your brain repo?`,+ user_message: `gbrain's brain repo setting (${named}), so sync cannot tell which folder is the brain. Which directory holds your brain repo?`,why: 'Points sync.repo_path at an absolute directory; no file or page changes.', verify: { argv: ['gbrain', 'config', 'get', 'sync.repo_path'] } } });}if (foreign) {diff --git a/test/sync-relative-anchor-refusal-7630.test.ts b/test/sync-relative-anchor-refusal-7630.test.tsindex ae7947e371..7800c37e6f 100644--- a/test/sync-relative-anchor-refusal-7630.test.ts+++ b/test/sync-relative-anchor-refusal-7630.test.ts@@ -544,6 +544,49 @@ for (const backend of testBackends()) {expect(await assertNoOverlappingPath(engine, 'default', folder).then(() => null, (error: { code?: string }) => error.code ?? String(error))).toBeNull();}, 120_000);+ // Value: protects=the foreign-OS cells of both stored-anchor holds: a Windows-absolute legacy sync.repo_path refuses without calling+ // itself relative and keeps the config fix, config set over it stores this host's directory, config set of a Windows path is refused+ // on POSIX with nothing written, and set-path over a Windows-absolute local_path releases the sync refusal; fails_when=the+ // sync.repo_path branch keeps the relative wording beside the foreign why, or either exit (config set, set-path) does not settle the+ // hold; why_new=the foreign cases above cover only sources.local_path refusals; seam=none; no_claim=Windows hosts (rooted, absolute)+ test.skipIf(process.platform === 'win32')('a Windows-absolute sync.repo_path or local_path on POSIX: refusal wording and both exits', async () => {+ await engine.executeRaw("UPDATE sources SET local_path=NULL WHERE id='default'");+ await engine.setConfig('sync.repo_path', 'C:\\brain-example');+ const refused = await sync({}) as { code?: string; message?: string; fix?: { argv?: string[]; user_message?: string } } | null;+ expect(refused?.code).toBe('sync_anchor_relative');+ expect(refused?.message).toContain('not an absolute path on this host');+ expect(refused?.message).not.toContain('relative path');+ expect(refused?.fix?.user_message ?? '').not.toContain('relative path');+ expect(refused?.fix?.argv).toEqual(['gbrain', 'config', 'set', 'sync.repo_path', '<dir>']);+ const { runConfig } = await import('../src/commands/config.ts');+ expect((await cli(() => runConfig(engine, ['set', 'sync.repo_path', folder]))).exit).toBeUndefined();+ expect(await engine.getConfig('sync.repo_path')).toBe(folder);+ expect((await cli(() => runConfig(engine, ['set', 'sync.repo_path', 'C:\\brain-example']))).exit).toBe(1);+ expect(await engine.getConfig('sync.repo_path')).toBe(folder);+ await engine.executeRaw("UPDATE sources SET local_path=$1 WHERE id='default'", ['C:\\brain-example']);+ await cli(async () => {+ const { runSources } = await import('../src/commands/sources.ts');+ await runSources(engine, ['set-path', 'default', folder]);+ });+ expect((await engine.executeRaw<{ local_path: string | null }>("SELECT local_path FROM sources WHERE id='default'"))[0]!.local_path).toBe(folder);+ expect((await sync({ sourceId: 'default' }))?.code).not.toBe('sync_anchor_relative');+ }, 120_000);++ // Value: protects=an explicit absolute --repo that passes the refusal never stamps its HEAD into, or repoints, a source whose stored+ // local_path is relative; fails_when=sourceCommitAnchorAllowed or ownsSourceSyncAnchor resolve "." against the cwd, so a cwd that+ // contains (or is) the --repo directory proves ownership and poisons the source's incremental anchor; why_new=the cases above cover+ // isAnchorOwnedSyncPath only; seam=none; no_claim=the default source's repo_path repoint (ownsGlobalSyncAnchor, follow-up #7646)+ test('a relative local_path proves no ownership to the commit-anchor and repoint guards', async () => {+ await engine.executeRaw("INSERT INTO sources (id, name, local_path) VALUES ('notes-a', 'notes-a', '.')");+ const { ownsSourceSyncAnchor, sourceCommitAnchorAllowed } = await import('../src/core/sync-anchor.ts');+ expect(await sourceCommitAnchorAllowed(engine, 'notes-a', folder)).toEqual({ owns: false, configured: '.' });+ expect(await sourceCommitAnchorAllowed(engine, 'notes-a', join(folder, 'nested'))).toEqual({ owns: false, configured: '.' });+ expect(await ownsSourceSyncAnchor(engine, 'notes-a', folder)).toEqual({ owns: false, configured: '.' });+ await engine.executeRaw("UPDATE sources SET local_path=$1 WHERE id='notes-a'", [folder]);+ expect((await sourceCommitAnchorAllowed(engine, 'notes-a', folder)).owns).toBe(true);+ expect((await ownsSourceSyncAnchor(engine, 'notes-a', folder)).owns).toBe(true);+ }, 120_000);+// Value: protects=the remote sources_resolve_path read and the fence census never treat a relative local_path as the host's cwd;// fails_when=resolveSourcePaths realpaths "." (the cwd's Git repo answers) or the census walks the cwd's files;// why_new=the reader cases above cover write and maintenance roots, not these two reads; seam=none; no_claim=the MCP transport