Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(#6007): put_pages refuses a write-less grant as one error; map new e2e files; rebuild llms
garrytan6e8e87f07a99
diff --git a/llms-full.txt b/llms-full.txtindex 89504ce105..958016a97d 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -393,6 +393,42 @@ brain data. To end one client's access, follow the distinct preview/revisionflows for token invalidation, revocation, or deletion in[MCP administration](../mcp/ADMIN.md#invalidate-tokens-revoke-or-delete).+## Writing many pages++Say to your agent: *"When you save more than three pages to gbrain, use+put_pages with one request_id per batch and wait_ms 25000."*++- **`put_pages`** writes 1-50 complete pages (8 MB of content at most) in one+ call. Every page is an ordinary `put_page` write with the same fences,+ revision checks and receipts; the pages are admitted together, so the+ writer queue has room for the whole batch or the call refuses with+ `queue_capacity` and admits none of them. Keep 5-8 large pages per call:+ the model has to write every page into the tool arguments.+- **One receipt per batch.** The reply lists each page's state, revision or+ error (with its own `fix`), counts, and `next`: `done`, `poll` or+ `fix_pages`. A page refused for its own reason (an invalid slug, a slug+ outside the grant, a revision conflict) does not stop the others.+- **Replays and progress.** Replaying the identical call with the same+ `request_id` never writes twice. Calling `put_pages` with only the+ `request_id` reads the batch's progress without resending the pages. A+ replay with different pages refuses with `idempotency_conflict` and names+ the pages that changed.+- **`wait_ms`** (put_page and put_pages, 0-30000 ms) holds the reply until+ the commit. It is not part of the write, so changing it on a replay is+ safe. When a reply is still pending, follow `next` no sooner than+ `retry_after_ms`.+- **Links.** For remote writes, `[[wikilinks]]` in a page body that point at+ pages already in the same source become plain `mentions` links after the+ commit, and a batch links pages to each other once its last page commits.+ The batch receipt's `links` field shows when they have landed; agents do+ not add them by hand. Typed links still need `add_link`. Turn this off with+ `gbrain config set mcp.remote_auto_links false`.+- **Embedding** runs after the commit. New text is searchable by keyword+ immediately and by meaning once its embedding effect finishes.+- **Request size.** `gbrain serve --http` reads the whole request; the+ simpler HTTP transport caps a request at `GBRAIN_HTTP_MAX_BODY_BYTES`+ (1 MiB by default) and its 413 reply tells the agent to split the batch.+## PGLite brainsPGLite is single-writer. While the service runs, host-side commands that opendiff --git a/scripts/e2e-test-map.ts b/scripts/e2e-test-map.tsindex 32849b32bd..16ddc8ee18 100644--- a/scripts/e2e-test-map.ts+++ b/scripts/e2e-test-map.ts@@ -72,6 +72,8 @@ export const E2E_TEST_MAP: Record<string, string[]> = {"src/commands/projections.ts": ["test/e2e/projection-drain-postgres.test.ts", "test/e2e/fix-wave-5-integration.test.ts"],"src/core/persistence/consumer.ts": ["test/e2e/projection-drain-postgres.test.ts"],"src/core/persistence/effect-links.ts": ["test/e2e/persistence-links-effect-postgres.test.ts"],+ "src/core/page-state/guards.ts": ["test/e2e/page-guards-postgres.test.ts"],+ "src/core/persistence/protocol.ts": ["test/e2e/persistence-statement-budget.test.ts"],"src/core/persistence/journal.ts": ["test/e2e/projection-drain-postgres.test.ts", "test/e2e/withdrawal-followup-writes-postgres.test.ts", "test/e2e/worktree-refresh-postgres.test.ts"],// F0 `gbrain sources refresh`: the refresh state machine, its admission/claim fence and restart recovery."src/core/persistence/worktree-refresh.ts": ["test/e2e/worktree-refresh-postgres.test.ts"],diff --git a/src/core/persistence/page-batch.ts b/src/core/persistence/page-batch.tsindex be1cd0313e..0ca339d220 100644--- a/src/core/persistence/page-batch.ts+++ b/src/core/persistence/page-batch.ts@@ -215,6 +215,10 @@ export async function submitPageBatch(ctx: OperationContext, params: Record<stri`To check the original batch, call put_pages with only request_id ${batchId}. To write a different set of pages, use a new request_id.`);}const prepared = await prepareAll(ctx, batchId, sourceId, pages);+ // A grant that may not write here refuses every page alike: answer the call with that one error.+ const first = prepared[0];+ if (first instanceof OperationError && first.code === 'permission_denied'+ && prepared.every(entry => entry instanceof OperationError && entry.code === first.code && entry.message === first.message)) throw first;const conflicts = prepared.flatMap((entry, index) => entry instanceof OperationError && entry.code === 'idempotency_conflict' ? [pages[index]!.slug] : []);if (conflicts.length) {throw opError('idempotency_conflict', `Batch ${batchId} was already accepted with different content for ${conflicts.join(', ')}. Nothing new was admitted.`,diff --git a/test/put-pages-batch.test.ts b/test/put-pages-batch.test.tsindex d2b088926f..5e98599e9d 100644--- a/test/put-pages-batch.test.ts+++ b/test/put-pages-batch.test.ts@@ -110,9 +110,8 @@ describe('put_pages', () => {VALUES($1,'Batch-only fixture','read write','default',$2)`, [clientId, ['put_pages']]);const caller = ctx({ auth: { token: 'synthetic', clientId, principal: { kind: 'oauth_client', id: clientId },sourceId: 'default', scopes: ['read', 'write'], allowedOperations: ['put_pages'] } as any });- const result = await putPages.handler(caller, { request_id: randomUUID(), pages: [page('notes/denied')] }) as any;- expect(result).toMatchObject({ state: 'failed', counts: { failed: 1 } });- expect(result.pages[0].error.code).toBe('permission_denied');+ await expect(putPages.handler(caller, { request_id: randomUUID(), pages: [page('notes/denied'), page('notes/denied-2')] }))+ .rejects.toMatchObject({ code: 'permission_denied' });expect(await engine.readPageSnapshot('notes/denied', { sourceId: 'default' })).toBeNull();});});