Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(loops): a remote open_loops call with no google source in its grant says so, without naming sources outside it (#7286)
garrytan6c10c25006c0
diff --git a/docs/guides/open-loops.md b/docs/guides/open-loops.mdindex c4934e3450..5fab0cc93b 100644--- a/docs/guides/open-loops.md+++ b/docs/guides/open-loops.md@@ -372,6 +372,11 @@ an empty inbox. Any Google access path works to fix it: `gbrain google setup`(BYO OAuth) or `--access command|env` on `sources add` (an existing GoogleCLI or token-minting gateway; see[google-connect.md](google-connect.md#other-ways-to-reach-google-no-gbrain-oauth)).+A remote caller (MCP) gets no digest, so it gets a `loops_no_google_in_scope`+notice instead: the answer covered only the sources its connection is granted+(named), pass `source_id` for a granted google source, and the fix lists them.+The notice never names a source outside the grant, so it reads the same+whether or not one exists.Memory verbs: entity cards' `open_threads[]` entries backed by loop rowscarry additive optional fields (`direction`, `due`, `counterparty`,diff --git a/src/core/error-registry.ts b/src/core/error-registry.tsindex 950eadc398..be0132e7df 100644--- a/src/core/error-registry.ts+++ b/src/core/error-registry.ts@@ -877,6 +877,7 @@ export const NOTICE_CODES = {identity_siblings_capped: { kind: 'info', summary: 'More than three pages share an entity\'s title subject, so the card shows no identity siblings; the fix (for the user) lists them with `gbrain extract mentions --explain`.' },alias_fanout: { kind: 'info', summary: 'search fanned out over an entity\'s other names and stopped at the per-call cap; the skipped names are listed and can be searched directly.' },search_filter_hint: { kind: 'info', summary: 'A search or query looked like it wanted a filter it did not pass (the query names a page type or a time, or one type fills the top results); the notice names types, since/until or where and the call to repeat. Results are unchanged.' },+ loops_no_google_in_scope: { kind: 'info', summary: 'A remote open_loops call read only the sources its connection is granted and none is a google source, so the empty answer is not "inbox clean"; the notice names the caller\'s own sources only (never one outside the grant) and the fix lists them for source_id.' },mention_index: { kind: 'degraded', summary: 'The entity mention index is pending, off, failed or does not cover this page type, so references listed for an entity may be incomplete.' },degraded_recall: { kind: 'degraded', summary: 'A retrieval stage that affects recall did not run; an empty or thin result is not proof of absence. A failed rerank names its reason (timeout, budget, rate_limited, unreachable, auth, provider_error), the fused-order fallback and the session\'s count of reranker-degraded calls; timeout and rate_limited say to repeat the call after a delay, the rest point at doctor\'s reranker_health.' },source_binding_narrowed: { kind: 'info', summary: "A GBRAIN_SOURCE / .gbrain-source binding narrowed an unqualified read that came back empty; the fix reads another source explicitly." },diff --git a/src/core/notice-ledger.ts b/src/core/notice-ledger.tsindex f332813b4b..ec8f08542c 100644--- a/src/core/notice-ledger.ts+++ b/src/core/notice-ledger.ts@@ -34,7 +34,7 @@ export const COACHING_BUDGET_PER_SESSION = 2;/** The one muteable `ask`: an unanswered first-run bundle must stay dismissible. Every other ask always shows. */export const MUTEABLE_ASK_CODES: ReadonlySet<string> = new Set(['first_run_decisions']);/** Notices that describe THIS call's result (never deduped unless the notice carries a `dedupe_key`): the diagnosis must ride every affected call. */-export const PER_CALL_NOTICE_CODES: ReadonlySet<string> = new Set(['degraded_recall', 'hidden_tool_content', 'empty_retrieval', 'unknown_param', 'listing_truncated', 'former_relationships_hidden', 'source_binding_narrowed', 'local_transcripts', 'held_files', 'relational_chain', 'mention_index', 'delta_incomplete', 'identity_siblings_capped', 'references_unavailable', 'record_types_undeclared', 'alias_fanout', 'facts_unembedded']);+export const PER_CALL_NOTICE_CODES: ReadonlySet<string> = new Set(['degraded_recall', 'hidden_tool_content', 'empty_retrieval', 'unknown_param', 'listing_truncated', 'former_relationships_hidden', 'source_binding_narrowed', 'local_transcripts', 'held_files', 'relational_chain', 'mention_index', 'delta_incomplete', 'identity_siblings_capped', 'references_unavailable', 'record_types_undeclared', 'alias_fanout', 'facts_unembedded', 'loops_no_google_in_scope']);/** How long a shown coverage state (a notice's `escalation`) stays shown. */export const COVERAGE_NOTICE_WINDOW_MS = 30 * 60 * 1000;diff --git a/src/core/ops/loops.ts b/src/core/ops/loops.tsindex 44e776d04d..d0fce6364b 100644--- a/src/core/ops/loops.ts+++ b/src/core/ops/loops.ts@@ -20,7 +20,7 @@*/import { opError, type Operation, type OperationContext, type OperationError } from './contract.ts';-import type { Action } from '../agent-output.ts';+import type { Action, Notice } from '../agent-output.ts';import { hostFix, invalidParam, opTransport, paramUse, readFix } from './op-fix.ts';import { resolveRequestedScope, sourceScopeOpts } from './context.ts';import { validateSourceId } from '../utils.ts';@@ -485,6 +485,7 @@ const open_loops: Operation = {});const freshness = await googleSourceFreshness(ctx, scope);const noGoogleSources = freshness.sources.length === 0;+ if (!trusted && noGoogleSources) ctx.emitNotice?.(noGoogleInScopeNotice(ctx));const partialStaleSources = freshness.stale ? [] : freshness.staleSources;const coverage = await heldCoverage(ctx, freshness.sources, trusted);const deepLinks = trusted ? await deepLinksFor(ctx, loops) : new Map<string, string>();@@ -636,6 +637,18 @@ function sourcesFix(why: string): Action {return readFix(why, { argv: ['gbrain', 'sources', 'list', '--json'], mcp: { tool: 'sources_list', arguments: {} } });}+/** #7286: names only the caller's own grant, so the text is the same whether or not a google source exists outside it. */+function noGoogleInScopeNotice(ctx: OperationContext): Notice {+ return {+ code: 'loops_no_google_in_scope',+ kind: 'info',+ why: `open_loops read only the sources this connection is granted (${grantedSources(ctx).join(', ') || 'none'}), and none of them is a google source, ` ++ 'so it had nothing to read: this is not "inbox clean", and it says nothing about sources outside the grant. ' ++ "Pass source_id naming a google source this connection is granted, or ask the brain's owner to grant one.",+ fix: sourcesFix('Lists the sources this connection can read; pass a google one as source_id.'),+ };+}+function closeFix(ctx: OperationContext, p: Record<string, unknown>): { fix?: Action } {if (typeof p.id !== 'number' || !Number.isSafeInteger(p.id)) return {};return { fix: hostFix(ctx, ['gbrain', 'loops', p.status === 'dropped' ? 'drop' : 'done', String(p.id)],diff --git a/test/loops-remote-scope-notice-7286.test.ts b/test/loops-remote-scope-notice-7286.test.tsnew file mode 100644index 0000000000..b1ff1e30de--- /dev/null+++ b/test/loops-remote-scope-notice-7286.test.ts@@ -0,0 +1,72 @@+/**+ * #7286: a remote open_loops call whose granted sources hold no google source+ * says so (a notice: the answer covers only this connection's sources, how to+ * pass source_id, the sources_list fix) instead of a bare empty result, and+ * the answer is the same whether or not a google source exists elsewhere in+ * the brain: no out-of-scope id, count or existence leaks. PGLite, synthetic.+ */+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { resetPgliteState } from './helpers/reset-pglite.ts';+import { loopsOperations } from '../src/core/ops/loops.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import type { Notice } from '../src/core/agent-output.ts';+import { upsertOpenLoop } from '../src/core/loops/loops-store.ts';++let engine: PGLiteEngine;+const openLoops = loopsOperations.find(o => o.name === 'open_loops')!;++beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); });+afterAll(async () => { await engine.disconnect(); });+beforeEach(async () => {+ await resetPgliteState(engine);+ await engine.executeRaw(`INSERT INTO sources (id, name, config) VALUES ('source-a', 'source-a', '{}'::jsonb) ON CONFLICT (id) DO NOTHING`);+});++async function seedGoogleElsewhere(): Promise<void> {+ await engine.executeRaw(`INSERT INTO sources (id, name, config, last_sync_at) VALUES ('google-elsewhere', 'google-elsewhere', '{"kind":"google"}'::jsonb, now()) ON CONFLICT (id) DO NOTHING`);+ await upsertOpenLoop(engine, { sourceId: 'google-elsewhere', dedupKey: 'thread:18c2f4a9b3d21e07:unanswered_inbound', loopType: 'unanswered_inbound',+ counterpartyEmail: '[email protected]', summary: 'Reply owed to [email protected]', evidence: [{ message_id: '18c2f4a9b3d21e07', quote: 'Can you review?' }],+ threadId: '18c2f4a9b3d21e07', detector: 'deterministic_thread' } as Parameters<typeof upsertOpenLoop>[1]);+}++async function call(params: Record<string, unknown>) {+ const notices: Notice[] = [];+ const ctx = { engine, config: {}, logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: true, sourceId: 'source-a',+ emitNotice: (n: Notice) => notices.push(n) } as unknown as OperationContext;+ const result = await openLoops.handler(ctx, { as_of: '2026-10-31T00:00:00Z', ...params }) as Record<string, unknown>;+ return { result, notices };+}++describe('#7286 open_loops for a remote caller bound to a non-google source', () => {+ for (const view of [{}, { group_by: 'none' }]) {+ test(`says the answer covers only this connection's sources (${JSON.stringify(view)})`, async () => {+ const { result, notices } = await call(view);+ expect(result.no_google_sources).toBe(true);+ const notice = notices.find(n => n.code === 'loops_no_google_in_scope');+ expect(notice).toBeDefined();+ expect(notice!.why).toContain('source-a');+ expect(notice!.why).toContain('source_id');+ expect(notice!.why).toContain('not "inbox clean"');+ expect(notice!.fix?.mcp).toEqual({ tool: 'sources_list', arguments: {} });+ });++ test(`is identical whether or not a google source exists outside the grant (${JSON.stringify(view)})`, async () => {+ const without = await call(view);+ await seedGoogleElsewhere();+ const withGoogle = await call(view);+ expect(JSON.stringify(withGoogle)).toBe(JSON.stringify(without));+ expect(JSON.stringify(withGoogle)).not.toContain('google-elsewhere');+ });+ }++ test('a scope that holds a google source carries no such notice', async () => {+ await seedGoogleElsewhere();+ const notices: Notice[] = [];+ const ctx = { engine, config: {}, logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: true, sourceId: 'google-elsewhere',+ emitNotice: (n: Notice) => notices.push(n) } as unknown as OperationContext;+ const result = await openLoops.handler(ctx, {}) as Record<string, unknown>;+ expect(result.no_google_sources).toBe(false);+ expect(notices.map(n => n.code)).not.toContain('loops_no_google_in_scope');+ });+});