Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes (open_loops notice names the sources the call read)

garrytan9164eb6a66c2
diff --git a/docs/guides/open-loops.md b/docs/guides/open-loops.md
index 5fab0cc93b..4dc7c10ec6 100644
--- a/docs/guides/open-loops.md
+++ b/docs/guides/open-loops.md
@@ -373,8 +373,9 @@ an empty inbox. Any Google access path works to fix it: `gbrain google setup`
CLI 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.
+notice instead: the answer covered only the sources the call read (named, all
+inside the grant), 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.
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index 87c45b0367..3bfd94f6ea 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -918,7 +918,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.' },
+ loops_no_google_in_scope: { kind: 'info', summary: 'A remote open_loops call read no google source, so the empty answer is not "inbox clean"; the notice names only the sources the call read, all inside the caller\'s grant (never one outside it) 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/ops/loops.ts b/src/core/ops/loops.ts
index 46b93ef88e..98347ae115 100644
--- a/src/core/ops/loops.ts
+++ b/src/core/ops/loops.ts
@@ -485,7 +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));
+ if (!trusted && noGoogleSources) ctx.emitNotice?.(noGoogleInScopeNotice(scope.sourceIds ?? (scope.sourceId ? [scope.sourceId] : [])));
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>();
@@ -638,12 +638,12 @@ 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 {
+/** #7286: names only the sources this read covered, all inside the grant, so the text is the same whether or not a google source exists outside it. */
+function noGoogleInScopeNotice(readSources: string[]): 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, ` +
+ why: `open_loops read only ${readSources.join(', ') || 'none'}, inside this connection's grant, 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.'),
diff --git a/test/loops-remote-scope-notice-7286.test.ts b/test/loops-remote-scope-notice-7286.test.ts
index b1ff1e30de..e084309e22 100644
--- a/test/loops-remote-scope-notice-7286.test.ts
+++ b/test/loops-remote-scope-notice-7286.test.ts
@@ -69,4 +69,17 @@ describe('#7286 open_loops for a remote caller bound to a non-google source', ()
expect(result.no_google_sources).toBe(false);
expect(notices.map(n => n.code)).not.toContain('loops_no_google_in_scope');
});
+
+ test('names the sources it read, not the whole grant, when source_id narrows a federated read', async () => {
+ await engine.executeRaw(`INSERT INTO sources (id, name, config, last_sync_at) VALUES ('mail-a', 'mail-a', '{"kind":"google"}'::jsonb, now()), ('notes-a', 'notes-a', '{}'::jsonb, NULL) ON CONFLICT (id) DO NOTHING`);
+ const notices: Notice[] = [];
+ const ctx = { engine, config: {}, logger: { info() {}, warn() {}, error() {} }, dryRun: false, remote: true, sourceId: 'notes-a',
+ auth: { allowedSources: ['mail-a', 'notes-a'] }, emitNotice: (n: Notice) => notices.push(n) } as unknown as OperationContext;
+ const result = await openLoops.handler(ctx, { source_id: 'notes-a' }) as Record<string, unknown>;
+ 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('notes-a');
+ expect(notice!.why).not.toContain('mail-a');
+ });
});