Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: Step 11 native review fixes (restrictions marker is internal state; revoked principals resolve to no member; applied policy revision read per source)
garrytan33ae0b76230d
diff --git a/src/core/access/caller.ts b/src/core/access/caller.tsindex 7003815e64..de41afc305 100644--- a/src/core/access/caller.ts+++ b/src/core/access/caller.ts@@ -51,8 +51,8 @@ export async function memberIdentityFor(engine: Pick<BrainEngine, 'executeRaw'>,const principal = auth?.principal;if (!principal || (principal.kind !== 'legacy_token' && principal.kind !== 'oauth_client')) return [];return liveIdentity(engine, principal.kind === 'legacy_token'- ? 'SELECT member_id FROM access_tokens WHERE id::text = $1'- : 'SELECT member_id FROM oauth_clients WHERE client_id = $1', principal.id);+ ? 'SELECT member_id FROM access_tokens WHERE id::text = $1 AND revoked_at IS NULL'+ : 'SELECT member_id FROM oauth_clients WHERE client_id = $1 AND deleted_at IS NULL', principal.id);}/** The member a local stdio server is bound to (config mcp.stdio_member), or null when unset or ill-formed. */@@ -248,7 +248,8 @@ export async function appliedAccessSummary(engine: Pick<BrainEngine, 'executeRawif (access.restricted) {try {const rows = await engine.executeRaw<{ source_id: string; rev: number | string | null }>(- 'SELECT source_id, max(revision) FILTER (WHERE applied_at IS NOT NULL) AS rev FROM access_policy_revisions GROUP BY source_id ORDER BY source_id');+ `SELECT s.source_id, (SELECT r.revision FROM access_policy_revisions r WHERE r.source_id = s.source_id AND r.applied_at IS NOT NULL+ ORDER BY r.revision DESC LIMIT 1) AS rev FROM access_policy_state s ORDER BY s.source_id`);const visible = auth ? new Set([auth.sourceId, ...(auth.allowedSources ?? []), ...sourceIds].filter(Boolean)) : null;policyRev = Object.fromEntries(rows.filter(r => r.rev !== null && (!visible || visible.has(r.source_id))).map(r => [r.source_id, Number(r.rev)]));} catch { policyRev = null; }diff --git a/src/core/config-runtime-keys.ts b/src/core/config-runtime-keys.tsindex 387cac462a..e7500c5893 100644--- a/src/core/config-runtime-keys.ts+++ b/src/core/config-runtime-keys.ts@@ -24,5 +24,4 @@ export const RUNTIME_READER_CONFIG_KEYS: readonly string[] = ['serve.vector_prewarm', // config.ts loadConfigWithEngine (snapshot only) → serve.ts: a Postgres serve prewarms the HNSW indexes into shared_buffers at start when they fit, default off'mcp.stdio_member', // access/caller.ts (GBRA-218): binds a local stdio MCP server to one member; unbound, stdio reads no page that names readers'mcp.stdio_may_act_for', // access/audience.ts (GBRA-231): whom a local stdio server may act for (_meta.on_behalf_of); unset, stdio refuses every audience- 'access.restrictions_present', // search/private-visibility.ts (GBRA-218): '1' once a page names readers or a member exists (set by a migration trigger; sticky)];diff --git a/test/access-binding.test.ts b/test/access-binding.test.tsindex 998bbae383..55b78a91f0 100644--- a/test/access-binding.test.ts+++ b/test/access-binding.test.ts@@ -150,6 +150,17 @@ for (const kind of testBackends()) {expect(await memberIdentityFor(noQueries, joined)).toEqual([]);});+ test('a stored principal whose token was revoked resolves to the empty identity, like may_act_for', async () => {+ const principal = { kind: 'legacy_token' as const, id: tokens.alice!.id };+ expect(await memberIdentityFor(engine, { principal })).toEqual(['group:team-a', 'member:alice-example']);+ await engine.executeRaw('UPDATE access_tokens SET revoked_at = now() WHERE id = $1::uuid', [tokens.alice!.id]);+ try {+ expect(await memberIdentityFor(engine, { principal })).toEqual([]);+ } finally {+ await engine.executeRaw('UPDATE access_tokens SET revoked_at = NULL WHERE id = $1::uuid', [tokens.alice!.id]);+ }+ });+test('stdio: unbound sees no restricted page; mcp.stdio_member binds it; a disabled bound member sees none again', async () => {expect(await stdioGet(ALICE_SLUG)).not.toContain(CANARY);await engine.setConfig(STDIO_MEMBER_KEY, 'bob-example');diff --git a/test/config-set-runtime-keys.test.ts b/test/config-set-runtime-keys.test.tsindex 3606182023..8f271b5ed9 100644--- a/test/config-set-runtime-keys.test.ts+++ b/test/config-set-runtime-keys.test.ts@@ -57,4 +57,12 @@ describe('#6780 config set accepts the runtime reader keys', () => {expect(get.exitCode).toBe(0);expect(get.stdout.trim()).toBe(value);}, 240_000);++ test('GBRA-218: the sticky access.restrictions_present marker is not a knob; config set refuses it without --force', async () => {+ const env = { GBRAIN_BRAIN_ID: '', GBRAIN_SOURCE: '' };+ const set = await runCli(['config', 'set', 'access.restrictions_present', '0'], { home, env, timeoutMs: 120_000 });+ expect({ exitCode: set.exitCode, unknown: set.stderr.includes('Unknown config key') }).toEqual({ exitCode: 1, unknown: true });+ const get = await runCli(['config', 'get', 'access.restrictions_present'], { home, env, timeoutMs: 120_000 });+ expect(get.stdout.trim()).not.toBe('0');+ }, 240_000);});diff --git a/test/helpers/config-reader-registry.ts b/test/helpers/config-reader-registry.tsindex 54eab4555f..c1b15b6928 100644--- a/test/helpers/config-reader-registry.ts+++ b/test/helpers/config-reader-registry.ts@@ -25,6 +25,7 @@ export interface InternalConfigState {export const INTERNAL_CONFIG_STATE: readonly InternalConfigState[] = [{ key: 'version', reason: 'schema version stamp written by migrate.ts' },+ { key: 'access.restrictions_present', reason: 'sticky member-access marker a v282 trigger sets once a page names readers or a member exists (search/private-visibility.ts); clearing it would send remote reads down the unrestricted fast path' },{ key: '_internal.link_extraction_generation', reason: 'link-extraction watermark generation (link-extraction-watermark.ts)' },{ key: 'code.cluster_generation', reason: 'code-intel traversal cache generation counter' },{ key: 'embedding_migration.state', reason: 'gbrain migrate-embeddings resume state' },