Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes
garrytana19edf887082
diff --git a/docs/guides/multi-source-brains.md b/docs/guides/multi-source-brains.mdindex a61a28627d..5de472cc88 100644--- a/docs/guides/multi-source-brains.md+++ b/docs/guides/multi-source-brains.md@@ -244,7 +244,9 @@ who may read it, before any member's bot connects:```The first id is the token's write source, so a member's saved memories land- in their own private source. Keep that source unfederated.+ in their own private source. Keep that source unfederated: federating it+ later makes the pages already written there readable by every credential+ without a source grant, since they carry no `readable_by`.A credential bound to a member (`--member`) whose write source is `default`(a token with no `--sources` or with `--sources default`, or an OAuth clientdiff --git a/src/core/minions/handlers/ingest-capture.ts b/src/core/minions/handlers/ingest-capture.tsindex 44a530decd..7199ed9601 100644--- a/src/core/minions/handlers/ingest-capture.ts+++ b/src/core/minions/handlers/ingest-capture.ts@@ -120,8 +120,8 @@ export async function assertWebhookWriterMayReplace(engine: BrainEngine, writer:// GST-2051 x GST-2112: POST /ingest refuses a member-bound credential writing to default; a job queued before that// refusal (or before the binding) is refused here at write time, since the capture cannot keep the page to the member.if (authority.principal && await defaultSourceMemberWriter(engine, authority)) {- throw opError('permission_denied', 'A capture from a credential bound to a member whose write source is default is refused: its page would land where other members and unbound credentials read.',- 'Write through the MCP put_page op, which keeps a new page to its member, or ask the brain operator to grant this credential its own write source (gbrain auth rescope --sources <private-source>,default).');+ throw opError('permission_denied', `A capture from a credential bound to a member whose write source is ${sourceId}, which every credential without a source grant reads, is refused: its page would land where other members and unbound credentials read.`,+ 'Write through the MCP put_page op, which keeps a new page to its member, or ask the brain operator to grant this credential its own write source that is not federated (gbrain auth rescope --sources <private-source>,default).');}// GST-2112: the snapshot is read before the visibility check, so the revision returned (which binds the write) is// never older than the state the writer was authorized against.diff --git a/test/access-federated-member-writes.test.ts b/test/access-federated-member-writes.test.tsindex 8c1a4e1933..81c9f2077e 100644--- a/test/access-federated-member-writes.test.ts+++ b/test/access-federated-member-writes.test.ts@@ -27,6 +27,7 @@ import { mintLegacyToken } from '../src/core/token-mint.ts';import { noGrantFederatedScope } from '../src/core/source-resolver.ts';import { dispatchToolCall } from '../src/mcp/dispatch.ts';import { mountWebhooks } from '../src/commands/serve-http-webhooks.ts';+import { assertWebhookWriterMayReplace } from '../src/core/minions/handlers/ingest-capture.ts';import type { ServeHttpContext } from '../src/commands/serve-http.ts';import { __resetPrivateVisibilityCacheForTests } from '../src/core/search/private-visibility.ts';import type { AuthInfo } from '../src/core/ops/contract.ts';@@ -46,6 +47,7 @@ for (const kind of testBackends()) {let engine: BrainEngine;let close: () => Promise<void>;const tokens: Record<string, string> = {};+ const tokenIds: Record<string, string> = {};const provider = () => new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });async function call(who: string, op: string, params: Record<string, unknown>) {@@ -90,6 +92,7 @@ for (const kind of testBackends()) {['bob', 'bob-example', undefined], ['public', null, undefined]] as const) {const minted = await mintLegacyToken(engine, { name, scopes: ['read', 'write'], takesHolders: ['world'], ...(sourceGrant ? { sourceGrant: [...sourceGrant] } : {}) });tokens[name] = minted.token;+ tokenIds[name] = minted.id;if (member) await engine.executeRaw('UPDATE access_tokens SET member_id = $2 WHERE id = $1::uuid', [minted.id, member]);}}, 240_000);@@ -231,5 +234,14 @@ for (const kind of testBackends()) {await new Promise<void>(resolve => server.close(() => resolve()));}}, 240_000);++ test('an ingest_capture job it queued earlier is refused at write time and stores nothing', async () => {+ const slug = 'notes/alice-queued-' + marker('queued');+ const writer = { principal: { kind: 'legacy_token', id: tokenIds['alice-a'] } };+ await expect(assertWebhookWriterMayReplace(engine, writer, FEDERATED, slug, note('Alice queued', 'Queued.')))+ .rejects.toMatchObject({ code: 'permission_denied', message: expect.stringContaining('write source is ' + FEDERATED) });+ expect(await stored(slug, FEDERATED)).toBeUndefined();+ expect(await assertWebhookWriterMayReplace(engine, { principal: { kind: 'legacy_token', id: tokenIds['alice-b'] } }, ISOLATED, slug, note('Alice queued', 'Queued.'))).toBeNull();+ }, 60_000);});}