Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(sync): the cost gate never prices a relative stored path; relative-anchor refusals carry their code and no stored path

garrytan46e90f0c94c1
diff --git a/src/commands/sync/run.ts b/src/commands/sync/run.ts
index a811ead8a5..d37223ebd9 100644
--- a/src/commands/sync/run.ts
+++ b/src/commands/sync/run.ts
@@ -867,7 +867,7 @@ async function runSingleSourceSync(
if (gateRows.length > 0) {
const gate = await resolveSingleSyncEmbedPlan(engine, {
sourceId,
- local_path: gateRows[0].local_path ?? repoPath ?? null,
+ local_path: (gateRows[0].local_path && isAbsolute(gateRows[0].local_path) ? gateRows[0].local_path : null) ?? repoPath ?? null,
config: gateRows[0].config ?? {},
last_commit: gateRows[0].last_commit,
chunker_version: gateRows[0].chunker_version,
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 12940fbc3a..a5efcd8c06 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1303,8 +1303,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.460.0', text: '`gbrain repair duplicate-facts` keeps the copy that is a row of a page\'s `## Facts` table over an older database-only copy of the same fact, so the legacy copy is superseded onto the fence row instead of holding it (which left the legacy row unfenced and its page out of fact reconciliation). With no fenced copy it still keeps the oldest row. It stays preview-first and explicit.' },
{ since: '0.60.460.0', text: 'Dream consolidation on a managed brain now closes a fenced fact in its page: the closing `valid_until` is written into the fact\'s row in the entity page\'s `## Facts` fence, published with the take, and the database row takes its value from that cell, so a later sync or re-import keeps the fact closed. Before, only the database row was closed and the next re-import of the page reopened it. A fact with no fence row is still closed in the database. A fenced fact whose fence row is on another page is left open. Facts an earlier release closed in the database only are not changed (GBRA-190).' },
// GBRA-207 (#7630). `since` is stamped at the merge slot.
- { since: 'TBD', id: 'sync_refuses_relative_anchor', text: 'A sync whose source directory (`sources.local_path`) or legacy `sync.repo_path` is a relative path such as `.` now refuses `sync_anchor_relative` (exit 3) before any Git probe or import, instead of treating whatever folder it ran from as the brain repo (Git init, a baseline commit of the whole folder, an import of its markdown). `gbrain sources set-path <id> <absolute-directory>` sets the path, `gbrain sources set-path <id> --clear` now also clears a relative path on any source, and doctor\'s `default_source_local_path` warns on any source with a relative path, and `gbrain config set sync.repo_path` refuses one. Until the path is set, page and fact writes skip the file (database only), matching a folder to its source ignores it, the dream, autopilot and maintenance cycles run only database phases (a cycle whose directory matches no source refuses its sync phase while `default`\'s path is relative), fence repair edits stored pages instead of files, managed activation refuses it, `autopilot --install` needs `--repo`, a remote `submit_job` is refused and a managed brain records no managed root there. A few other local commands may still read it from the folder they run in, so set the path before relying on them.' },
- { since: 'TBD', text: 'A foreground write (`remember`, `put_page`, `add_tag`, `takes_add` and the other caller-submitted page mutations) that ends with a retryable fault such as `preparation_stalled` now carries a diagnosis that inspects the writer read-only (`gbrain sources writer status --source <id> --json`) and says to resubmit the same write with a new request_id, instead of telling the user to run `gbrain sync`. A managed write (an import, repair, quarantine clear or grandfather) says to rerun its command, an operation such as `extract_facts` or writer administration gets the read-only inspect alone, and a canonical reconcile, a maintenance job (stored as `submit_job`) and a recorded sync fault keep their sync retry. `gbrain sources writer failures --group-by category` splits these by operation, and `--operation` narrows a listing to one.' },
+ { since: 'TBD', id: 'sync_refuses_relative_anchor', text: 'A sync whose source directory (`sources.local_path`) or legacy `sync.repo_path` is a relative path such as `.` now refuses `sync_anchor_relative` (exit 3) before any Git probe or import, instead of treating whatever folder it ran from as the brain repo (Git init, a baseline commit of the whole folder, an import of its markdown). `gbrain sources set-path <id> <absolute-directory>` sets the path, `gbrain sources set-path <id> --clear` now also clears a relative path on any source, and doctor\'s `default_source_local_path` warns on any source with a relative path, and `gbrain config set sync.repo_path` refuses one. Until the path is set, page and fact writes skip the file (database only), and so do page writes of any other source without its own path that write under `sync.repo_path` (that relative path could name this tree), matching a folder to its source ignores it, the dream, autopilot and maintenance cycles run only database phases (a cycle whose directory matches no source refuses its sync phase while `default`\'s path is relative), fence repair edits stored pages instead of files, managed activation refuses it, `autopilot --install` needs `--repo`, a remote `submit_job` is refused and a managed brain records no managed root there. A few other local commands may still read it from the folder they run in, so set the path before relying on them.' },
+ { since: 'TBD', text: 'A foreground write (`remember`, `put_page`, `add_tag`, `takes_add` and the other caller-submitted page mutations) that ends with a retryable fault such as `preparation_stalled` now carries a diagnosis that inspects the writer read-only (`gbrain sources writer status --source <id> --json`) and says to resubmit the same write with a new request_id, instead of telling the user to run `gbrain sync`. A managed write (an import, repair, quarantine clear or grandfather) says to rerun its command, an operation such as `extract_facts` or writer administration gets the read-only inspect alone, and a canonical reconcile, a maintenance job (stored as `submit_job`) and a recorded sync fault keep their sync retry. `gbrain sources writer failures --group-by category` splits these by operation, and `--operation` narrows a listing to one; a row for a reconcile or managed `put_page` now reads `canonical_reconcile` or its `managed_*` intent in `operation`.' },
// GBRA-95 RLS backfill. `since` is stamped at the merge slot.
{ since: '0.60.463.0', id: 'rls_backfill_unguarded_tables', text: 'On Postgres, a schema migration now enables row-level security on every gbrain table still without it. A table could be left without RLS because its RLS came only from a full schema replay, which `gbrain apply-migrations --yes` does not run (the four incremental-derivation tables, `page_segment_derivations`, `page_derivation_spend` and the two purge tables), or only from the auto-RLS event trigger, which needs a superuser and is absent on many managed brains. Supabase gives public tables anon and authenticated grants, so with the Data API on such a table was reachable with the anon key. Only a table still without RLS changes; one with a `GBRAIN:RLS_EXEMPT` comment is left alone; no row is read or written. Under a role that does not bypass RLS or does not own a table, the migration names the table on stderr and leaves it, and `gbrain doctor` (rls) keeps naming it with the fix. `gbrain repair missing-tables` now recreates a cache table with RLS on. A role that neither owns a table nor bypasses RLS reads no rows from it and cannot insert or update it once RLS is on (a read-only reporting role or a scoped write role, for example): give that role policies before upgrading (docs/ENGINES.md has the source-scope recipe), or, to keep a table open to it on purpose, add the `GBRAIN:RLS_EXEMPT reason=...` comment to that table. A write role set up with an earlier copy of that recipe also needs its new policies on `page_derivation_spend` and the two purge tables: without them its segmented derivation writes are refused, and the derivation purge triggers its writes fire read no purge, so they do not hold back a purged claim.' },
{ since: '0.60.464.0', text: 'On Postgres, `gbrain serve --access read-only` (stdio) no longer acts as a resident owner: it holds no session-lane (direct pool) connection, starts no persistence consumer, takes no on-commit notifier lease, runs no startup or idle sweep or facts drain, and refuses delegated sync and sweep requests (the CLI then runs them itself). Resolve, turn_context and context_pack still answer. A read-write serve, `gbrain jobs work` or the autopilot owns those duties; `gbrain doctor` reports when no process on the host holds the notifier (`commit_notifier`) or a consumer (`two_consumers_on_host`). Read-write and HTTP serves, and any serve on PGLite (the process that owns the database file), are unchanged.' },
diff --git a/src/core/minions/submission-authority.ts b/src/core/minions/submission-authority.ts
index 1aab0327f5..c5be09b968 100644
--- a/src/core/minions/submission-authority.ts
+++ b/src/core/minions/submission-authority.ts
@@ -112,7 +112,7 @@ async function sourceBoundary(engine: BrainEngine, sourceId: string, jobName: Re
if (!record(config) || record(config)!.kind != null) deny('generic filesystem jobs require an ordinary filesystem source; use the dedicated connector endpoint',
`Source ${sourceId} is a connector source: the brain host syncs it with gbrain connectors (connector_sync), not through submit_job.`);
if (!isAbsolute(source.local_path)) deny('registered source root is a relative path',
- `Source ${sourceId}'s registered root is the relative path "${source.local_path}", which names whatever directory the brain host runs from (#7630), so nothing was queued. The brain host operator sets it with gbrain sources set-path ${sourceId} <absolute-directory>.`);
+ `Source ${sourceId}'s registered root is a relative path, which names whatever directory the brain host runs from (#7630), so nothing was queued. The brain host operator sets it with gbrain sources set-path ${sourceId} <absolute-directory>.`);
let canonicalRoot: string;
try {
canonicalRoot = realpathSync(source.local_path);
diff --git a/src/core/persistence/resolve-paths.ts b/src/core/persistence/resolve-paths.ts
index fed8a14aba..0be90c7980 100644
--- a/src/core/persistence/resolve-paths.ts
+++ b/src/core/persistence/resolve-paths.ts
@@ -115,7 +115,7 @@ export async function resolveSourcePaths(engine: BrainEngine, sourceId: string,
const status = ['gbrain', 'sources', 'status', sourceId, '--json'];
if (!source || source.archived) throw opError('not_found', `Source ${sourceId} is not registered or is archived.`, 'List the registered sources and pass one of their ids.',
{ fix: readFix('Lists the registered sources.', ['gbrain', 'sources', 'list', '--json'], ['gbrain', 'sources', 'list', '--json']) });
- if (source.local_path && !isAbsolute(source.local_path)) throw opError('not_found', `Source ${sourceId} has the relative local_path "${source.local_path}", which names no fixed directory, so its paths cannot be resolved (sync_anchor_relative).`,
+ if (source.local_path && !isAbsolute(source.local_path)) throw opError('sync_anchor_relative', `Source ${sourceId} has a relative local_path, which names no fixed directory, so its paths cannot be resolved.`,
'Ask the user which directory holds the checkout, then run gbrain sources set-path on the host that holds it.', { fix: readFix('Shows the source and its stored path.', status, status) });
if (!source.local_path || !existsSync(source.local_path)) throw opError('not_found', `Source ${sourceId} has no Git checkout on this host, so its paths cannot be resolved here.`,
'Run this on the host that holds the checkout (gbrain sources status names its path).', { fix: readFix('Shows where the source checkout lives.', status, status) });
diff --git a/test/sync-relative-anchor-refusal-7630.test.ts b/test/sync-relative-anchor-refusal-7630.test.ts
index 0da572214e..75560b8028 100644
--- a/test/sync-relative-anchor-refusal-7630.test.ts
+++ b/test/sync-relative-anchor-refusal-7630.test.ts
@@ -174,6 +174,37 @@ for (const backend of testBackends()) {
expect(await pagesOf('default')).toBe(0);
}, 120_000);
+ // Value: protects=with an explicit absolute --repo and a stored "." the embed cost gate prices the --repo directory, never the cwd;
+ // fails_when=the gate input prefers the stored relative local_path, so the estimate runs git and walks files in whatever folder
+ // gbrain runs from; why_new=the gate case above refuses before the gate (no --repo); seam=resolveSingleSyncEmbedPlan spied to
+ // record its source and stop the run; no_claim=what the estimate would cost
+ test('gbrain sync --repo <absolute> with a stored "." prices the --repo directory in the cost gate, never the cwd', async () => {
+ const repo = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-7630-gate-')));
+ try {
+ execSync('git init -q && git config user.email [email protected] && git config user.name T', { cwd: repo, stdio: 'pipe' });
+ writeFileSync(join(repo, 'inside.md'), '---\ntype: note\ntitle: Inside\n---\n\nA page of the brain.\n');
+ execSync('git add -A && git commit -q -m initial', { cwd: repo, stdio: 'pipe' });
+ await engine.executeRaw("UPDATE sources SET local_path='.' WHERE id='default'");
+ configureGateway({ embedding_model: 'openai:text-embedding-3-large', embedding_dimensions: 1536, env: { OPENAI_API_KEY: 'sk-test-7630' } });
+ const embedBackfill = await import('../src/core/sync-embed-backfill.ts');
+ const priced: Array<string | null> = [];
+ const gate = spyOn(embedBackfill, 'resolveSingleSyncEmbedPlan').mockImplementation(async (_e, source) => {
+ priced.push(source.local_path ?? null);
+ return { stop: true, workerSurface: { status: 'ok' } as never, autoDeferEmbeds: false };
+ });
+ try {
+ await runSyncCli(['--repo', repo, '--source', 'default', '--no-pull']);
+ } finally {
+ gate.mockRestore();
+ resetGateway();
+ }
+ expect(priced).toEqual([repo]);
+ expect(existsSync(join(folder, '.git'))).toBe(false);
+ } finally {
+ rmSync(repo, { recursive: true, force: true });
+ }
+ }, 120_000);
+
// Value: protects=an explicit relative --repo that differs from the stored relative anchor is honored: that directory syncs;
// fails_when=the guard starts refusing every relative repoPath instead of only the stored anchor itself;
// why_new=no other case passes a relative repoPath other than the anchor; seam=none; no_claim=parallel import workers
@@ -479,8 +510,9 @@ for (const backend of testBackends()) {
await engine.executeRaw("UPDATE sources SET local_path='.' WHERE id='default'");
const { resolveSourcePaths } = await import('../src/core/persistence/resolve-paths.ts');
const refused = await resolveSourcePaths(engine, 'default', ['notes.md']).then(() => null, (error: { code?: string; message?: string }) => error);
- expect(refused?.code).toBe('not_found');
+ expect(refused?.code).toBe('sync_anchor_relative');
expect(refused?.message).toContain('relative local_path');
+ expect(refused?.message).not.toContain('"."');
const { runFenceCensus } = await import('../src/core/fence-repair/census.ts');
const [run] = await runFenceCensus(engine, { sourceIds: ['default'], deadline: Date.now() + 60_000 });
expect(run?.files).toBe('none');