Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Pass mcp verify's write check on member-bound credentials, and fix page mode's put_page call

garrytane430e5f68fa9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71efe4fae3..53aa83222e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,15 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**`gbrain mcp verify` now passes its write check on a credential bound to a member.** The verifier's test fact was always sent with `visibility: "world"`, which `remember` refuses for a member credential, so every member-bound connection showed "write" and "write_readback" as failed even when it was set up correctly. A member-bound credential now saves the test fact the way a member's own saves go by default. It is kept private on that member's page, where no other member reads it. The verifier reads the fact back and withdraws it, as before. A credential bound to no member still shares its test fact explicitly, so a brain whose `facts.default_visibility` is private still reads it back. Page mode (`coding-agent` profiles and credentials with direct-write prefixes) had a second mistake: its `put_page` call passed a `title` parameter the tool doesn't declare, so every page-mode write was refused. The title now goes in the page's frontmatter. The same fixes apply to the verify step inside `gbrain connect … --install`.
+
+### Itemized changes
+
+- `src/core/harness/verify.ts`: the fact-mode write reads the credential's bound member from `whoami` (`access.member`) and sends `visibility: "world"` only when there is none. The page-mode `put_page` drops the undeclared `title` parameter for a frontmatter title.
+- Tests: `test/harness-verify-member-credential.test.ts` covers a non-owner member, the owner and an unbound credential, in fact mode and page mode, on PGLite and Postgres (repo-less). It also checks that a member's fixture is private on its member page and unreadable by another member, and that an unbound credential passes under a private `facts.default_visibility`.
+
## [0.60.692.0] - 2026-11-12
**On a source whose pages are canonical in Git, every fact writer now commits a fact with no page of its own to Git, and doctor and a new repair find the ones an older gbrain left in the database only.** In the last release only `remember` did this. Google loops, fact extraction, the managed facts writer and an owner releasing a quarantined fact now also commit a fact with no entity, or for an entity with no page, as a row of `memory/unattributed`. Before, they kept it in the database only, where a rebuild from Git lost it, or were refused with `git_home_required` once that page existed. Sources that are not strict, and brains with no Git repository, behave as before.
diff --git a/scripts/postgres-arm-weights.json b/scripts/postgres-arm-weights.json
index 6d9fca4e58..df05a1c0e3 100644
--- a/scripts/postgres-arm-weights.json
+++ b/scripts/postgres-arm-weights.json
@@ -145,6 +145,7 @@
"test/graduation-verify.test.ts": 18535,
"test/grandfather-managed.test.ts": 46554,
"test/harness-skills-epoch.test.ts": 4313,
+ "test/harness-verify-member-credential.test.ts": 9000,
"test/held-bare-name-move-gst2492.test.ts": 17127,
"test/held-fence-readers-gst2492.test.ts": 6742,
"test/held-read-signals.test.ts": 10071,
diff --git a/src/core/harness/verify.ts b/src/core/harness/verify.ts
index dc0534c573..e464d3db41 100644
--- a/src/core/harness/verify.ts
+++ b/src/core/harness/verify.ts
@@ -89,10 +89,11 @@ export async function verifyHarnessConnection(c: HarnessCredentials, options: Ve
if (pageMode) cleanupSlug = `${typeof prefix === 'string' ? prefix.replace(/\/?\*?$/, '/') : 'gbrain-verification/'}${fixture}`;
else factAttempted = true;
const wrote = await stage('write', async () => {
+ const member = pageMode ? null : (identity.access ?? await active.call('whoami', {}).then(w => w?.access, () => null))?.member;
mutationAttempted = true;
const saved = await active.call(pageMode ? 'put_page' : 'remember', pageMode
- ? { request_id: writeRequestId, slug: cleanupSlug, title: 'Connection check', content: `# Connection check\n\n${fixture}\n` }
- : { request_id: writeRequestId, fact: fixture, entity: fixtureEntity, provenance: 'GBrain randomized connection verification', visibility: 'world' });
+ ? { request_id: writeRequestId, slug: cleanupSlug, content: `---\ntitle: Connection check\n---\n# Connection check\n\n${fixture}\n` }
+ : { request_id: writeRequestId, fact: fixture, entity: fixtureEntity, provenance: 'GBrain randomized connection verification', ...(member ? {} : { visibility: 'world' }) });
if (saved.state !== undefined && saved.state !== 'committed') throw new Error('write_not_committed');
if (!pageMode) factId = String(saved.id ?? '');
mutationConfirmed = true;
diff --git a/test/harness-verify-member-credential.test.ts b/test/harness-verify-member-credential.test.ts
new file mode 100644
index 0000000000..3cbb8e3ad1
--- /dev/null
+++ b/test/harness-verify-member-credential.test.ts
@@ -0,0 +1,125 @@
+/**
+ * GST-2543: gbrain mcp verify's write check passes for a credential bound to a member, writes its fixture the way that
+ * credential may (a member's fact stays private on its own member page, never shared), reads it back and withdraws it.
+ * 1. Protects: fact mode and page mode for a non-owner member, the owner and an unbound credential, on a repo-less brain.
+ * 2. Fails when: the verifier's remember sends visibility "world", which a member credential is refused
+ * (member_share_required), or a member's fixture becomes readable by another member.
+ * 3. Real seams: tokens minted by the token service and bound with SQL, verified by the serve --http verifier, every
+ * verifier call dispatched through MCP dispatch with remote=true. Synthetic names only.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { randomUUID } from 'node:crypto';
+import type { BrainEngine } from '../src/core/engine.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { GBrainOAuthProvider } from '../src/core/oauth-provider.ts';
+import { sqlQueryForEngine } from '../src/core/sql-query.ts';
+import { mintLegacyToken } from '../src/core/token-mint.ts';
+import { dispatchToolCall } from '../src/mcp/dispatch.ts';
+import { __resetPrivateVisibilityCacheForTests } from '../src/core/search/private-visibility.ts';
+import { setOwner } from '../src/core/access/owner.ts';
+import type { AuthInfo } from '../src/core/ops/contract.ts';
+import { verifyHarnessConnection, type VerificationPeer } from '../src/core/harness/verify.ts';
+import type { HarnessCredentials } from '../src/core/harness/credentials.ts';
+import { testBackends } from './helpers/test-backends.ts';
+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
+
+const WHO = ['alice', 'owner', 'unbound'] as const;
+type Who = typeof WHO[number];
+
+for (const kind of testBackends()) {
+ describe('mcp verify with a member-bound credential (' + kind + ', repo-less)', () => {
+ let engine: BrainEngine;
+ let close: () => Promise<void>;
+ const tokens: 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>) {
+ const auth = await provider().verifyAccessToken(tokens[who]) as unknown as AuthInfo;
+ return dispatchToolCall(engine, op, { ...params }, { remote: true, transport: 'http', auth, sourceId: auth.sourceId ?? 'default', takesHoldersAllowList: ['world'] });
+ }
+
+ function peerFor(who: Who, errors: string[]): VerificationPeer {
+ return {
+ connect: async () => {}, close: async () => {},
+ readCapabilities: async () => ({ transport: 'oauth', client_id: 'gbrain_cl_verify_' + who, scopes: ['read', 'write'], source_id: 'default' }),
+ call: async (name, params) => {
+ const out = await call(who, name, params);
+ const text = out.content.map(c => c.text).join('\n');
+ if (out.isError) { errors.push(name + ': ' + text); throw new Error('tool_error'); }
+ return JSON.parse(text);
+ },
+ };
+ }
+
+ const credentials = (who: Who, profile: string): HarnessCredentials => ({ version: 1, client_id: 'gbrain_cl_verify_' + who,
+ mcp_url: 'https://brain.example.com/mcp', issuer_url: 'https://brain.example.com', access_token: 'fixture-token', source_id: 'default', profile });
+
+ beforeAll(async () => {
+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ else { engine = new PGLiteEngine(); await engine.connect({ engine: 'pglite' } as never); await engine.initSchema(); close = () => engine.disconnect(); }
+ __resetPrivateVisibilityCacheForTests();
+ for (const id of ['owner-example', 'alice-example', 'bob-example']) await engine.executeRaw('INSERT INTO access_members (id) VALUES ($1)', [id]);
+ await setOwner(engine, 'owner-example');
+ for (const [name, member] of [['owner', 'owner-example'], ['alice', 'alice-example'], ['bob', 'bob-example'], ['unbound', null]] as const) {
+ const minted = await mintLegacyToken(engine, { name, scopes: ['read', 'write'], takesHolders: ['world'] });
+ tokens[name] = minted.token;
+ if (member) await engine.executeRaw('UPDATE access_tokens SET member_id = $2 WHERE id = $1::uuid', [minted.id, member]);
+ }
+ }, 240_000);
+ afterAll(async () => { await close?.(); }, 60_000);
+
+ for (const who of WHO) {
+ test('fact mode: every stage passes for ' + who + ', and the fixture is withdrawn', async () => {
+ const errors: string[] = [];
+ const report = await verifyHarnessConnection(credentials(who, 'memory-writer'), { peer: peerFor(who, errors), timeoutMs: 60_000 });
+ expect(errors).toEqual([]);
+ expect(report.stages.filter(s => s.status !== 'passed' && s.status !== 'not_requested')).toEqual([]);
+ for (const name of ['write', 'write_readback', 'cleanup']) expect(report.stages.find(s => s.name === name)?.status).toBe('passed');
+ expect(await engine.executeRaw("SELECT id FROM facts WHERE fact = $1 AND expired_at IS NULL", [report.fixture])).toEqual([]);
+ }, 240_000);
+ }
+
+ test('fact mode: a member\'s fixture is saved private on its own member page, so another member never reads it', async () => {
+ const errors: string[] = [];
+ const seen: string[] = [];
+ const base = peerFor('alice', errors);
+ const peer: VerificationPeer = { ...base, call: async (name, params) => {
+ const out = await base.call(name, params);
+ if (name === 'remember') {
+ const rows = await engine.executeRaw<{ visibility: string; page: string | null }>(
+ 'SELECT visibility, source_markdown_slug AS page FROM facts WHERE fact = $1', [params.fact]);
+ const other = await call('bob', 'recall', { grep: String(params.fact) });
+ seen.push(JSON.stringify({ rows, bob_reads_it: other.content.map(c => c.text).join('\n').includes(String(params.fact)) }));
+ }
+ return out;
+ } };
+ const report = await verifyHarnessConnection(credentials('alice', 'memory-writer'), { peer, timeoutMs: 60_000 });
+ expect(errors).toEqual([]);
+ expect(report.stages.find(s => s.name === 'write_readback')?.status).toBe('passed');
+ expect(seen).toEqual([JSON.stringify({ rows: [{ visibility: 'private', page: 'memory/members/alice-example' }], bob_reads_it: false })]);
+ }, 240_000);
+
+ test('fact mode: an unbound credential still shares its fixture explicitly, so a private brain default keeps it readable', async () => {
+ await engine.setConfig('facts.default_visibility', 'private');
+ try {
+ const errors: string[] = [];
+ const report = await verifyHarnessConnection(credentials('unbound', 'memory-writer'), { peer: peerFor('unbound', errors), timeoutMs: 60_000 });
+ expect(errors).toEqual([]);
+ for (const name of ['write', 'write_readback', 'cleanup']) expect(report.stages.find(s => s.name === name)?.status).toBe('passed');
+ } finally {
+ await engine.executeRaw("DELETE FROM config WHERE key = 'facts.default_visibility'");
+ }
+ }, 240_000);
+
+ for (const who of WHO) {
+ test('page mode: every stage passes for ' + who + ', and the fixture page is soft-deleted', async () => {
+ const errors: string[] = [];
+ const report = await verifyHarnessConnection(credentials(who, 'coding-agent'), { peer: peerFor(who, errors), timeoutMs: 60_000 });
+ expect(errors).toEqual([]);
+ expect(report.stages.filter(s => s.status !== 'passed' && s.status !== 'not_requested')).toEqual([]);
+ for (const name of ['write', 'write_readback', 'cleanup']) expect(report.stages.find(s => s.name === name)?.status).toBe('passed');
+ expect(await engine.executeRaw("SELECT slug FROM pages WHERE slug = $1 AND deleted_at IS NULL", [report.cleanup?.slug])).toEqual([]);
+ }, 240_000);
+ }
+ });
+}
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 3aad15e1e7..527ade80fd 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -157,6 +157,7 @@ test/graduation-verify-sync-freshness.test.ts
test/graduation-verify.test.ts
test/grandfather-managed.test.ts
test/harness-skills-epoch.test.ts
+test/harness-verify-member-credential.test.ts
test/held-bare-name-move-gst2492.test.ts
test/held-fence-readers-gst2492.test.ts
test/held-read-signals.test.ts