Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

security: remote entity cards, context_pack and delta no longer carry open loops; remote open_loops ranking ignores backlinks

garrytan0a31bae250e6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 11547d3f2b..6e769c61f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,31 @@ 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).
+## [0.60.267.0] - 2026-10-16
+
+**Security: remote entity cards and context packs no longer carry open loops.** Since v0.47.0.0, an `entity` card built for a remote caller (any MCP client, stdio or HTTP) listed the open loops whose counterparty is that entity: the loop summary, its due date and its `loop_id`. Loop rows have no visibility or source grant of their own, so the card showed them even when the loop's commitment fact was private, and since v0.60.167.0 (#5504) also when the loop lives in a source outside the caller's grant, such as a connected Google source. `context_pack` and `delta` build their threads from the same card, so they carried the same loops. Remote cards now skip loop-backed threads; their fact and timeline threads are unchanged.
+
+### What you'd see
+
+| Situation | Before | Now |
+|---|---|---|
+| A remote `entity`, `context_pack` or `delta` call for a person with open loops | `open_threads` listed each loop's summary, `due` and `loop_id`, whatever the loop's source | no loop-backed threads; eligible commitment facts and recent timeline events still appear |
+| A remote client needs its open loops | the card | `open_loops`, which reads only loops in sources the client is granted |
+| `gbrain entity <name>` on the brain host | loops on the card | unchanged |
+| `context_pack` / `delta` from the trusted local CLI | loops on the cards | loops only with `include_private`, the same switch that adds private facts (loop summaries come from private mail) |
+| Remote `open_loops` grouped by counterparty | groups were ranked partly by backlink counts that included pages outside the caller's grant | remote ranking leaves backlinks out; the trusted local CLI still uses them |
+
+### If you share brain access
+
+A brain without open loops (no Google source and no extracted commitments), or whose MCP clients are all your own agents, needs nothing. If you granted MCP read access to a client that should not see your mail-derived loops, run `gbrain auth clients --usage --days 60` on the brain host to see which clients called `entity`, `context_pack` or `delta` (stdio use is not logged), and revoke or rescope any you no longer trust (`gbrain auth revoke-client <client_id>`). No credentials were exposed, so no rotation is needed for this fix.
+
+### Itemized changes
+
+- `src/core/verbs/entity-card.ts`: a world-only card (`remote: true`) no longer reads `open_loops`.
+- `src/core/ops/loops.ts`: `open_loops` computes the backlink ranking boost for trusted local callers only.
+- Test: `test/entity-card-remote-loops.test.ts` drives the real `entity`, `context_pack`, `delta` and `open_loops` handlers with `remote: true` (fails on v0.60.266.0).
+- Docs: `docs/protocol/MEMORY_VERBS_v1.md` and `docs/guides/open-loops.md` say who gets loop-backed threads.
+
## [0.60.266.0] - 2026-10-16
**Managed sync tells the truth about where it stands, and every held file has a way out (#6712 PR 2).** A managed `gbrain sync` returns `synced` the moment its checkpoint commits: link extraction and planner statistics run after the drain lease is released, and a crash between the two is made up by the next sync. `gbrain sync status` stays fast on large brains and never reads a timed-out probe as "nothing pending". Each of the 14 hold codes now leads an agent to a cleared hold or to one decision sentence for the user, and a hold asks a person only after its safe action failed three times over at least a day. Every `gbrain sync` flag lives in one table, and the `sync.*` config keys are split into tunables, rollback keys and retired keys (five retired keys become `GBRAIN_SYNC_*` environment variables, and doctor names any stored value that stopped applying).
diff --git a/docs/guides/open-loops.md b/docs/guides/open-loops.md
index 32ac1037fc..c4934e3450 100644
--- a/docs/guides/open-loops.md
+++ b/docs/guides/open-loops.md
@@ -375,8 +375,10 @@ CLI or token-minting gateway; see
Memory verbs: entity cards' `open_threads[]` entries backed by loop rows
carry additive optional fields (`direction`, `due`, `counterparty`,
-`status`, `loop_id`) — visible through `entity`, `context_pack`, and
-`delta` on any harness.
+`status`, `loop_id`) — visible through `entity`, and through `context_pack`
+and `delta` with `include_private`, to the trusted local CLI only. Remote
+callers (every MCP transport) get cards without loop-backed threads and read
+loops inside their grant with `open_loops`.
## Close semantics
diff --git a/docs/protocol/MEMORY_VERBS_v1.md b/docs/protocol/MEMORY_VERBS_v1.md
index e5dff447a7..4e0271d62b 100644
--- a/docs/protocol/MEMORY_VERBS_v1.md
+++ b/docs/protocol/MEMORY_VERBS_v1.md
@@ -557,7 +557,10 @@ pending-decision loops — the ADDITIVE-FOREVER optional fields disambiguate:
All five are absent on threads not backed by a loop row and on servers that
do not implement them; a server that omits them still certifies. Same propagation to the
-per-entity cards and top-level `open_threads` of `context_pack`.
+per-entity cards and top-level `open_threads` of `context_pack`. Loop rows carry
+no visibility or source grant of their own, so only the trusted local caller's
+cards derive threads from them (`entity`, and `context_pack` / `delta` with
+`include_private`); a remote caller's card has no loop-backed entries.
- `edges`: top ~10 typed edges, mentions excluded, out-edges first, live relationships first. Additive fields: `status` (`live`, `ended`, `ended_unknown_date`, `event`, …), `since` / `until` (latest stint). `relationship_note` (additive) summarizes current and ended relationships and flags a summary that still names an ended one ([temporal edges](../guides/temporal-edges.md)).
- The p99 < 100ms promise is op-layer latency (transport excluded), CI-gated
on a 20K-page corpus. 200K validation recipe below.
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 1cf5fa710d..887e5191c5 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -717,6 +717,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
{ since: '0.60.266.0', text: 'A managed-sync file that `write_gate.external_mode=reject` refuses is now held as `write_gate_rejected` when sync freezes it, instead of failing its receipt and stopping the rest of the source. A held file that leaves the source (excluded with `sync.exclude`, or an image while multimodal embedding is off) is released by the next sync even when nothing new was committed. Every sync re-screens a `write_gate_rejected`, `content_rejected` or `purged_content` hold, so switching the setting, an owner allow rule or `gbrain pages unpurge` clears it.' },
{ since: '0.60.266.0', text: 'A `source_changed` write receipt\'s fix now follows its recorded reason: two-sided drift previews `gbrain repair file-drift --source <id> --slug <slug> --prefer database` (a group of them `--all-drifted --since <instant>`), a missing canonical file previews `gbrain repair ghost-pages`, an admission race is retried, and a changed binding or unsafe target names `gbrain sources writer status`. `gbrain repair file-drift` takes `--since <ISO-8601 | age>` to narrow `--all-drifted`.' },
{ since: '0.60.266.0', text: 'Doctor `managed_sync_not_moving` now fails (it used to list the source as parked) when a managed source\'s queue holds admitted requests with no consumer and nothing has moved for longer than `persistence.preparation_ceiling_ms`; its fix is the resume sync, which consumes the queue (#6552). A managed sync now prints a line when live pages of the source have no canonical file, naming the read-only `gbrain repair ghost-pages` preview; it never deletes them.' },
+ // Remote open-loop hotfix (GBRA-120). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.
+ { since: '0.60.266.0', text: 'Remote callers (every MCP transport) no longer get open-loop-backed threads on `entity` cards, or in `context_pack` and `delta`, which build on those cards: no loop summary, `due` or `loop_id`. Use `open_loops`, which reads loops only in granted sources. The trusted local CLI still sees them on `gbrain entity`, and in `context_pack` / `delta` with `include_private`. Remote `open_loops` grouped results no longer rank counterparties by backlink counts.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/ops/loops.ts b/src/core/ops/loops.ts
index 1cd9c63c4c..86508b7c1e 100644
--- a/src/core/ops/loops.ts
+++ b/src/core/ops/loops.ts
@@ -540,7 +540,9 @@ const open_loops: Operation = {
const backlinks = new Map<string, number>();
try {
- const slugs = [...byKey.values()]
+ // Backlink counts span every source, so they rank trusted-local reads
+ // only: an untrusted caller's order must not depend on pages outside its grant.
+ const slugs = !trusted ? [] : [...byKey.values()]
.map((g) => g.counterparty_slug)
.filter((s): s is string => s !== null);
if (slugs.length > 0) {
diff --git a/src/core/verbs/entity-card.ts b/src/core/verbs/entity-card.ts
index e9f61d19b6..81d29aaa66 100644
--- a/src/core/verbs/entity-card.ts
+++ b/src/core/verbs/entity-card.ts
@@ -570,8 +570,11 @@ async function assembleCard(
// belongs to this card when its counterparty page is THIS (source, slug):
// a Gmail-source loop whose person page lives in `default` shows on the
// default card, a pre-v236 row (NULL counterparty source) on its own
- // source's card (#5504).
- const loopRows = await engine.executeRaw<{
+ // source's card (#5504). Loops carry no visibility or grant of their own
+ // (summaries derive from private mail, often another source), so a
+ // world-only card never reads them; open_loops serves remote callers
+ // inside their grant.
+ const loopRows = remote ? [] : await engine.executeRaw<{
id: number;
loop_type: string;
summary: string;
diff --git a/test/entity-card-remote-loops.test.ts b/test/entity-card-remote-loops.test.ts
new file mode 100644
index 0000000000..1943050ffc
--- /dev/null
+++ b/test/entity-card-remote-loops.test.ts
@@ -0,0 +1,152 @@
+/**
+ * Remote entity cards, context packs and delta never carry open-loop-backed threads.
+ *
+ * Loops have no visibility or grant of their own: a summary derives from
+ * private mail, and a Gmail-source loop can point at a world person page in
+ * `default` (#5504). Through the real remote handlers (MCP dispatch,
+ * remote: true), neither a same-source loop backed by a private commitment
+ * fact nor an out-of-grant google-source loop may surface its summary, due
+ * date or loop_id. Trusted local callers still see both loops.
+ *
+ * Synthetic data only.
+ */
+import { describe, expect, test, beforeAll, afterAll } from 'bun:test';
+import { randomUUID } from 'node:crypto';
+
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { operationsByName, type OperationContext } from '../src/core/operations.ts';
+import { dispatchToolCall } from '../src/mcp/dispatch.ts';
+import { upsertOpenLoop } from '../src/core/loops/loops-store.ts';
+import { __resetHotMemoryCacheForTests } from '../src/core/facts/meta-hook.ts';
+import type { GBrainConfig } from '../src/core/config.ts';
+
+const PRIVATE_LOOP = 'PRIVATE-LOOP-SENTINEL send the signed term sheet';
+const GRANT_LOOP = 'OUT-OF-GRANT-LOOP-SENTINEL reply owed about the offer';
+const DUE = '2031-03-04T05:06:07.000Z';
+
+let engine: PGLiteEngine;
+const loopIds: number[] = [];
+const noop = { info: () => {}, warn: () => {}, error: () => {} };
+const local = (): OperationContext =>
+ ({ engine, config: {} as GBrainConfig, logger: noop, dryRun: false, remote: false, sourceId: 'default' }) as OperationContext;
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ await engine.executeRaw(`INSERT INTO sources (id, name, config) VALUES ('gmail-example', 'gmail-example', '{"kind":"google"}'::jsonb) ON CONFLICT (id) DO NOTHING`);
+ await engine.putPage('people/alice-example', { title: 'Alice Example', type: 'person', compiled_truth: 'Alice Example, a founder at acme-example.' }, { sourceId: 'default' });
+ const fact = await engine.executeRaw<{ id: number }>(
+ `INSERT INTO facts (source_id, entity_slug, fact, kind, source, visibility)
+ VALUES ('default', 'people/alice-example', $1, 'commitment', 'loops-extract-test', 'private') RETURNING id`,
+ [PRIVATE_LOOP],
+ );
+ loopIds.push((await upsertOpenLoop(engine, {
+ sourceId: 'default', dedupKey: 'commit:private0001', loopType: 'commitment_owed_by_me',
+ counterpartySlug: 'people/alice-example', summary: PRIVATE_LOOP, evidence: [{ message_id: 'm-private-1', quote: 'quote' }],
+ detector: 'llm_extract', dueAt: DUE, factId: Number(fact[0].id),
+ })).id);
+ loopIds.push((await upsertOpenLoop(engine, {
+ sourceId: 'gmail-example', dedupKey: 'thread:18c2f4a9b3d21e07:unanswered_inbound', loopType: 'unanswered_inbound',
+ counterpartySlug: 'people/alice-example', counterpartySourceId: 'default', counterpartyEmail: '[email protected]',
+ summary: GRANT_LOOP, evidence: [{ message_id: '18c2f4a9b3d21e07', quote: 'quote' }], threadId: '18c2f4a9b3d21e07',
+ detector: 'deterministic_thread', dueAt: DUE,
+ })).id);
+}, 120_000);
+
+afterAll(async () => {
+ await engine.disconnect();
+});
+
+function expectNoLoop(raw: string) {
+ expect(raw).not.toContain('LOOP-SENTINEL');
+ expect(raw).not.toContain('2031-03-04');
+ expect(raw).not.toContain('loop_id');
+}
+
+async function remote(name: string, params: Record<string, unknown>): Promise<{ raw: string; body: Record<string, any> }> {
+ const res = await dispatchToolCall(engine as never, name, params, { remote: true, transport: 'stdio', sourceId: 'default' });
+ expect(res.isError).toBeFalsy();
+ const texts = res.content.map(c => (c as { text?: string }).text ?? '');
+ return { raw: texts.join('\n'), body: JSON.parse(texts[0]!) };
+}
+
+describe('remote entity, context_pack and delta withhold open loops', () => {
+ test('remote entity card carries neither loop, and still returns the card', async () => {
+ const { raw, body } = await remote('entity', { name: 'people/alice-example' });
+ expect(body.card.entity.slug).toBe('people/alice-example');
+ expectNoLoop(raw);
+ });
+
+ test('remote context_pack carries neither loop in cards, open_threads or text', async () => {
+ __resetHotMemoryCacheForTests();
+ const { raw, body } = await remote('context_pack', { entities: 'people/alice-example', session_id: randomUUID() });
+ expect(body.cards.map((c: { slug: string }) => c.slug)).toContain('people/alice-example');
+ expectNoLoop(raw);
+ });
+
+ test('remote context_pack cannot widen with include_private', async () => {
+ __resetHotMemoryCacheForTests();
+ expectNoLoop((await remote('context_pack', { entities: 'people/alice-example', session_id: randomUUID(), include_private: true })).raw);
+ });
+
+ test('remote delta thread events carry neither loop', async () => {
+ expectNoLoop((await remote('delta', { since: '2000-01-01T00:00:00Z', entities: 'people/alice-example' })).raw);
+ });
+
+ test('trusted local delta with include_private still shows both loops', async () => {
+ const body = await operationsByName.delta!.handler(local(), { since: '2000-01-01T00:00:00Z', entities: 'people/alice-example', include_private: true });
+ expect(JSON.stringify(body)).toContain(PRIVATE_LOOP);
+ expect(JSON.stringify(body)).toContain(GRANT_LOOP);
+ });
+
+ test('trusted local entity card still shows both loops with loop_id and due', async () => {
+ const body = await operationsByName.entity!.handler(local(), { name: 'people/alice-example' }) as
+ { card: { open_threads: Array<{ text: string; loop_id?: number; due?: string | null }> } };
+ const loops = body.card.open_threads.filter(t => t.loop_id !== undefined);
+ expect(loops.map(t => t.text).sort()).toEqual([GRANT_LOOP, PRIVATE_LOOP].sort());
+ expect(loops.map(t => t.loop_id).sort()).toEqual([...loopIds].sort());
+ for (const t of loops) expect(new Date(t.due as string).toISOString()).toBe(DUE);
+ });
+
+ test('trusted local context_pack with include_private still shows both loops', async () => {
+ __resetHotMemoryCacheForTests();
+ const body = await operationsByName.context_pack!.handler(local(), { entities: 'people/alice-example', session_id: randomUUID(), include_private: true }) as
+ { open_threads: Array<{ text: string; loop_id?: number }> };
+ expect(body.open_threads.filter(t => t.loop_id !== undefined).map(t => t.text).sort()).toEqual([GRANT_LOOP, PRIVATE_LOOP].sort());
+ });
+});
+
+describe('remote open_loops ranking ignores backlinks outside the grant', () => {
+ const AS_OF = '2026-10-16T00:00:00Z';
+ const AT = '2026-10-10T00:00:00.000Z';
+ const top = async (remoteCall: boolean): Promise<string[]> => {
+ const params = { as_of: AS_OF, limit: 1 };
+ if (!remoteCall) {
+ const body = await operationsByName.open_loops!.handler({ ...local(), sourceId: 'gmail-granted' } as OperationContext, params) as { groups: Array<{ counterparty: string }> };
+ return body.groups.map(g => g.counterparty);
+ }
+ const res = await dispatchToolCall(engine as never, 'open_loops', params, {
+ remote: true, transport: 'http', sourceId: 'gmail-granted',
+ auth: { token: 't', clientId: 'c', scopes: ['read'], allowedSources: ['gmail-granted'] } as never,
+ });
+ expect(res.isError).toBeFalsy();
+ return (JSON.parse((res.content[0] as { text: string }).text) as { groups: Array<{ counterparty: string }> }).groups.map(g => g.counterparty);
+ };
+
+ test('a backlink added only in an ungranted source does not change the remote order; trusted local still ranks by it', async () => {
+ await engine.executeRaw(`INSERT INTO sources (id, name, config) VALUES ('gmail-granted', 'gmail-granted', '{"kind":"google"}'::jsonb), ('private-other', 'private-other', '{}'::jsonb) ON CONFLICT (id) DO NOTHING`);
+ await engine.putPage('people/z-example', { title: 'Z Example', type: 'person', compiled_truth: 'Z Example.' }, { sourceId: 'private-other' });
+ await engine.putPage('notes/z-ref', { title: 'Z ref', type: 'note', compiled_truth: 'About Z Example.' }, { sourceId: 'private-other' });
+ const base = { sourceId: 'gmail-granted', loopType: 'unanswered_inbound' as const, evidence: [{ message_id: 'm', quote: 'q' }],
+ detector: 'deterministic_thread' as const, lastActivityAt: AT, openedAt: AT };
+ await upsertOpenLoop(engine, { ...base, dedupKey: 'thread:aaaa:unanswered_inbound', counterpartyEmail: '[email protected]', summary: 'Reply owed to a' });
+ await upsertOpenLoop(engine, { ...base, dedupKey: 'thread:zzzz:unanswered_inbound', counterpartySlug: 'people/z-example', counterpartySourceId: 'private-other', summary: 'Reply owed to z' });
+
+ expect(await top(true)).toEqual(['[email protected]']);
+ expect(await top(false)).toEqual(['[email protected]']);
+ await engine.addLink('notes/z-ref', 'people/z-example', 'about', 'references', 'manual', undefined, undefined, { fromSourceId: 'private-other', toSourceId: 'private-other' });
+ expect(await top(true)).toEqual(['[email protected]']);
+ expect(await top(false)).toEqual(['people/z-example']);
+ });
+});