Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

storage manifest: the hosted shelf never becomes the sole non-default write source

garrytan2a2d585b6c61
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8882a9b8ed..7920cec60b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ The shelf is written only through the storage verbs. `put_page`, `remember` and
- `src/core/storage-manifest/` (`schema.ts`, `door.ts`, `source.ts`, `find.ts`) and `src/core/ops/storage-manifest.ts`: the card schema and secret checks, the write door, the source lifecycle (`storage init`), keyless ranked lookup (exact id, `page_aliases`, word matches, `pg_trgm` closest cards) and the five ops `storage_find`, `storage_get`, `storage_list`, `storage_register`, `storage_update`.
- `src/core/persistence/page-mutations.ts`, `src/core/persistence/memory-mutations.ts`: the page door and `remember`/`forget` refuse writers other than the storage verbs on a source with `role: storage_manifest`; the owner's import of commits already in the hosted repository still syncs.
- `src/core/cycle.ts`, `src/commands/enrich.ts`: a cycle scoped to the storage source returns `skipped` with reason `storage_manifest_source`; enrichment considers no card there.
+- `src/core/source-resolver.ts`: the hosted shelf never counts as the sole non-default source, so after `storage init` bare `put`, `capture` and `sync` keep routing where they did before. `src/core/persistence/preadmit-cache.ts` caches the page door's source read with its new `role` column.
- `src/core/error-registry.ts`, `docs/guides/write-refusals.md`, `docs/guides/error-codes.md`: `storage_source_managed`, `storage_manifest_missing`, `storage_record_invalid`, `storage_record_secret`, `storage_card_exists` and `storage_revision_conflict`, each with its recovery path. Remote register and update refuse with the shared `trusted_local_only`.
- `src/commands/storage.ts`: `gbrain storage init`; the help separates the tiers report (`status`) from the shelf verbs.
- Goldens: `test/fixtures/goldens/cli/tools-json.json` gains the three read tools; `test/fixtures/goldens/exports/types.json` gains the new error codes in the `canonical` union and lists `ThinkSynthesisStatus` in a new order (the new schema module declares the `not_json` literal first; the type is unchanged).
diff --git a/src/core/source-resolver.ts b/src/core/source-resolver.ts
index 49da64fc06..28c205009b 100644
--- a/src/core/source-resolver.ts
+++ b/src/core/source-resolver.ts
@@ -311,7 +311,7 @@ export function resolveSourceIdEngineFree(
* GBRAIN_NO_SOLE_NON_DEFAULT_NUDGE=1) so the reroute is diagnosable.
*
* Excludes archived sources (`archived = false`) so a soft-deleted source
- * doesn't auto-resolve. Shared by `resolveSourceId` and `resolveSourceWithTier`
+ * doesn't auto-resolve, and the storage manifest (GST-1943), which only the storage verbs write. Shared by `resolveSourceId` and `resolveSourceWithTier`
* so the heuristic can't drift between the two entry points.
*
* NOTE (#2928): this tier deliberately does NOT consult config.federated —
@@ -376,11 +376,11 @@ async function pickSoleNonDefaultSource(
`SELECT 1 AS one FROM pages WHERE source_id = 'default' AND deleted_at IS NULL LIMIT 1`,
).then(found => found.length > 0);
defaultHasPages.catch(() => {});
- let rows: Array<{ id: string }> = request ? request.filter(row => row.local_path !== null && row.id !== 'default' && row.archived === false) : [];
+ let rows: Array<{ id: string }> = request ? request.filter(row => row.local_path !== null && row.id !== 'default' && row.archived === false && parseSourceConfig(row.config).role !== 'storage_manifest') : [];
if (!request) {
try {
rows = await engine.executeRaw<{ id: string }>(
- `SELECT id FROM sources WHERE local_path IS NOT NULL AND id != 'default' AND archived = false`,
+ `SELECT id FROM sources WHERE local_path IS NOT NULL AND id != 'default' AND archived = false AND config->>'role' IS DISTINCT FROM 'storage_manifest'`,
);
} catch {
rows = await engine.executeRaw<{ id: string }>(
diff --git a/test/storage-manifest.test.ts b/test/storage-manifest.test.ts
index f45a8c639e..e403f33ed8 100644
--- a/test/storage-manifest.test.ts
+++ b/test/storage-manifest.test.ts
@@ -13,7 +13,8 @@
* - register and update refuse remote callers; the shelf is not federated, so a remote connection reads cards only
* when its grant names the storage source (an ungranted bound client and an unbound stdio connection are refused);
* - derived writers skip the shelf: a dream cycle scoped to the storage source runs no phase, and enrichment
- * considers no card there (no model call, no page write).
+ * considers no card there (no model call, no page write);
+ * - a hosted shelf never becomes the sole non-default source that bare writes route to.
*/
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
import { mkdtempSync, rmSync } from 'node:fs';
@@ -27,6 +28,7 @@ import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
import { runCycle } from '../src/core/cycle.ts';
import { runEnrichCore } from '../src/commands/enrich.ts';
+import { resolveSourceWithTier } from '../src/core/source-resolver.ts';
let engine: PGLiteEngine;
let home: string;
@@ -195,6 +197,14 @@ describe('storage shelf on a repo-less brain', () => {
expect(await engine.executeRaw("SELECT updated_at::text AS revision FROM pages WHERE source_id='storage'")).toEqual(before);
}, 30_000);
+ test('a hosted shelf is never the sole non-default source bare commands route to', async () => {
+ await engine.executeRaw("INSERT INTO sources (id, name, local_path, config) VALUES ('storage', 'storage', $1, $2::jsonb)",
+ [join(home, 'shelf'), JSON.stringify({ role: 'storage_manifest', federated: false })]);
+ expect(await resolveSourceWithTier(engine, null, tmpdir())).toMatchObject({ source_id: 'default', tier: 'seed_default' });
+ await engine.executeRaw("INSERT INTO sources (id, name, local_path, config) VALUES ('vault-a', 'vault-a', $1, '{}'::jsonb)", [join(home, 'vault-a')]);
+ expect(await resolveSourceWithTier(engine, null, tmpdir())).toMatchObject({ source_id: 'vault-a', tier: 'sole_non_default' });
+ }, 30_000);
+
test('a brain with a Git checkout needs storage init first, and init needs managed persistence', async () => {
await engine.setConfig('sync.repo_path', join(home, 'repo'));
expect((await refusal(call('storage_register', { card: card('repo-item') })))?.code).toBe('storage_manifest_missing');