Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(c2): Codex review round 1
garrytan0bb438e3c434
diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.tsindex 14472ec8c2..dde4af6dd4 100644--- a/src/core/ops/pages.ts+++ b/src/core/ops/pages.ts@@ -224,7 +224,9 @@ const fetch_page: Operation = {const slug = identity?.slug ?? id.trim();const missing = () => new OperationError('page_not_found', 'Page not found', 'Pass an id returned by a current `search` call.');let sourceOpts: ReturnType<typeof federatedSearchScope>;- try { sourceOpts = federatedSearchScope(ctx); }+ // #5081: a source-qualified id is read under the same explicit-read+ // admission as the search that issued it; a refusal still reads as missing.+ try { sourceOpts = federatedSearchScope(ctx, identity?.sourceId); }catch (error) {if (error instanceof OperationError && error.code === 'permission_denied') throw missing();throw error;diff --git a/src/core/ops/search.ts b/src/core/ops/search.tsindex c671dc6a3a..b1a6ff675e 100644--- a/src/core/ops/search.ts+++ b/src/core/ops/search.ts@@ -786,15 +786,9 @@ const query: Operation = {relationalRetrieval: true,autocut: false, decide: { remote: ctx.remote !== false, rerankOnly: true }, // System One: S2-S5 off on the re-rundetail,- // Preserve the caller's #3985 type filter on the re-run (raw- // pass-through; the base call already rejected malformed input).- ...(Array.isArray(p.types) || typeof p.types === 'string'- ? {- types: (Array.isArray(p.types) ? (p.types as string[]) : (p.types as string).split(','))- .map((t) => t.trim())- .filter(Boolean),- }- : {}),+ // Preserve the caller's #3985 type filter on the re-run, as+ // normalized for the base call (#5390: [] and "" stay absent).+ ...(types ? { types } : {}),language: (p.lang as string) || undefined,symbolKind: (p.symbol_kind as string) || undefined,// Preserve the caller's symbol-proximity constraints too — andiff --git a/src/mcp/server.ts b/src/mcp/server.tsindex ab410e2e97..2f121a4912 100644--- a/src/mcp/server.ts+++ b/src/mcp/server.ts@@ -55,7 +55,9 @@ export async function resolveMcpStdioSourceScope(const { resolveSourceWithTier, localFederatedSourceIds, explicitReadBinding } = await import('../core/source-resolver.ts');const resolved = await resolveSourceWithTier(engine, null, cwd);const federated = await localFederatedSourceIds(engine, resolved.source_id, resolved.tier);- const binding = await explicitReadBinding(engine, resolved.source_id, resolved.tier);+ // #5081: the admission set is optional; a failed lookup must not discard+ // the resolved binding (the catch below would fall back to 'default').+ const binding = await explicitReadBinding(engine, resolved.source_id, resolved.tier).catch(() => undefined);return {sourceId: resolved.source_id,...(federated ? { localFederatedSourceIds: federated } : {}),diff --git a/test/explicit-read-admission-5081.test.ts b/test/explicit-read-admission-5081.test.tsindex 7108ff97ca..33285efcb8 100644--- a/test/explicit-read-admission-5081.test.ts+++ b/test/explicit-read-admission-5081.test.ts@@ -29,6 +29,7 @@ import { requireWritablePage, resolveCodeIntelScope } from '../src/core/ops/contimport { dispatchToolCall, buildOperationContext, type DispatchOpts } from '../src/mcp/dispatch.ts';import { resolveMcpStdioSourceScope } from '../src/mcp/server.ts';import { withEnv } from './helpers/with-env.ts';+import { encodeDeepResearchId } from '../src/core/deep-research-id.ts';let engine: PGLiteEngine;let outsideCwd: string;@@ -153,6 +154,15 @@ describe('#5081 — explicit reads from a GBRAIN_SOURCE-bound stdio connection',});}+ test('fetch accepts the id of an admitted explicit search result and hides an unadmitted one', async () => {+ const { body: results } = await call(await bound(), 'search', { query: MARKER, source_id: 'notes' });+ const fetched = await call(await bound(), 'fetch', { id: results[0].id });+ expect(fetched.isError).toBe(false);+ expect(fetched.body.metadata.source_id).toBe('notes');+ const hidden = await call(await bound(), 'fetch', { id: encodeDeepResearchId('private', 'topics/private-topic') });+ expect(hidden.body.error).toBe('page_not_found');+ });+test('denials carry the docs anchor', async () => {const { body } = await call(await bound(), 'search', { query: MARKER, source_id: 'private' });expect(body.docs).toBe('docs/guides/multi-source-brains.md#explicit-reads-from-a-bound-agent-connection');diff --git a/test/mcp-stdio-source-resolution.test.ts b/test/mcp-stdio-source-resolution.test.tsindex 3763001b12..0094384b74 100644--- a/test/mcp-stdio-source-resolution.test.ts+++ b/test/mcp-stdio-source-resolution.test.ts@@ -62,6 +62,24 @@ describe('stdio MCP source resolution', () => {});});+ test('#5081: a failed admission lookup keeps the resolved pin instead of falling back to default', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-mcp-source-'));+ scratchDirs.push(dir);+ writeSourceDotfile(dir, 'team-alpha');+ const base = makeEngine(['default', 'team-alpha']);+ const failing = {+ ...base,+ executeRaw: async <T>(sql: string, params?: unknown[]): Promise<T[]> => {+ if (/SELECT id, config/.test(sql)) throw new Error('sources table unavailable');+ return base.executeRaw<T>(sql, params);+ },+ } as unknown as BrainEngine;++ await withEnv({ GBRAIN_SOURCE: undefined }, async () => {+ expect(await resolveMcpStdioSourceScope(failing, dir)).toEqual({ sourceId: 'team-alpha', tier: 'dotfile' });+ });+ });+test('GBRAIN_SOURCE wins over .gbrain-source', async () => {const dir = mkdtempSync(join(tmpdir(), 'gbrain-mcp-source-'));scratchDirs.push(dir);diff --git a/test/search/crag-query-op.test.ts b/test/search/crag-query-op.test.tsindex effc69b78c..edae87957c 100644--- a/test/search/crag-query-op.test.ts+++ b/test/search/crag-query-op.test.ts@@ -93,6 +93,28 @@ describe('query op — CRAG gate (#1663)', () => {expect(crag.escalate_to_think).toBe(true);}, 30000);+ test('#5390: types: [] escalates exactly like an omitted filter (the re-run reuses the normalized types)', async () => {+ await engine.setConfig('search.crag_escalation', 'true');+ let keywordCalls = 0;+ const counted = new Proxy(engine, {+ get(target, key) {+ const value = Reflect.get(target, key, target);+ if (key === 'searchKeyword') return (...args: unknown[]) => { keywordCalls++; return (value as (...a: unknown[]) => unknown).apply(target, args); };+ return typeof value === 'function' ? value.bind(target) : value;+ },+ });+ const calls: number[] = [];+ for (const types of [undefined, []]) {+ keywordCalls = 0;+ const { ctx, meta } = ctxWithMeta();+ await operationsByName.query.handler({ ...ctx, engine: counted } as OperationContext,+ { query: 'zxqv nonexistent quux', expand: false, ...(types ? { types } : {}) });+ expect(cragOf(meta).escalated).toBe(true);+ calls.push(keywordCalls);+ }+ expect(calls[1]).toBe(calls[0]);+ }, 30000);+test('remote and unset-trust escalation cannot adopt a matching private page', async () => {await engine.setConfig('search.crag_escalation', 'true');await engine.putPage('notes/private-crag', {