Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Mark think answers from the anchor, graph pages and calibration they were given, and mark a failed remember batch

garrytan6afd4d168b83
diff --git a/docs/guides/rooms.md b/docs/guides/rooms.md
index 8970d13315..05977fc411 100644
--- a/docs/guides/rooms.md
+++ b/docs/guides/rooms.md
@@ -89,9 +89,10 @@ Covered tools: `get_page`, `search`, `query`, `list_pages`, `find_pages`,
declared; its answer is marked unknown with reason `op_not_covered`.
A `think` answer is one item, marked at the strictest class of everything the
-synthesis retrieved, not only what it cites: it is readable only when the room
-can read every page and fact it was built from. An answer built partly from
-takes, or with no recorded evidence, is unknown (`not_identified`).
+synthesis retrieved or named in its prompt (the anchor and the graph pages
+reachable from it), not only what it cites: it is readable only when the room
+can read every one of them. An answer built partly from takes or a calibration
+profile, or with no recorded evidence, is unknown (`not_identified`).
`put_page` and `remember` mark their own result: the page or fact just written
(each item of a `remember` batch), judged as the room would read it. A write is
@@ -166,7 +167,10 @@ or the view of the member `--as` names.
room marks leaves every item unknown (`not_supported`).
- A command outside the operations (`gbrain think`, `gbrain doctor`, ...) runs
unchanged and prints a line saying it marks nothing: treat all of its output
- as above the room's level.
+ as above the room's level. The same line marks a page too large for one
+ answer, which `gbrain get` streams in parts: that output carries no
+ `room_access` and no `_meta.room`, even with `--json`, so a `--json` document
+ without `_meta.room` is never a readable one.
## Keep raw results out of the room's transcript
diff --git a/src/core/ops/takes.ts b/src/core/ops/takes.ts
index 831c4a21e6..8a7bc183e4 100644
--- a/src/core/ops/takes.ts
+++ b/src/core/ops/takes.ts
@@ -427,8 +427,8 @@ const think: Operation = {
if (remote && (Boolean(p.save) || Boolean(p.take))) ctx.emitNotice?.(thinkNotSavedNotice());
const { recordThinkAnswer, feedbackMetaFields } = await import('../feedback/record.ts');
const feedbackMeta = feedbackMetaFields(await recordThinkAnswer(ctx, 'think', result));
- const evidence = result.taint_refs;
- delete result.feedback_evidence; delete result.taint_refs;
+ const evidence = result.taint_refs && [...result.taint_refs, ...(result.room_extra ?? [])];
+ delete result.feedback_evidence; delete result.taint_refs; delete result.room_extra;
const { persist: _persist, persist_base: _persistBase, ...visible } = result;
// GBRA-498: a think answer going into a room is marked at the strictest class of everything it was built from.
return keepRoomEvidence({
diff --git a/src/core/persistence/provider.ts b/src/core/persistence/provider.ts
index 823341231e..12d586720c 100644
--- a/src/core/persistence/provider.ts
+++ b/src/core/persistence/provider.ts
@@ -90,18 +90,19 @@ export async function createPersistenceIpcProvider(engine: BrainEngine, config:
...(unrestricted ? {} : { localFederatedSourceIds: verified.grant.sourceIds }),
});
const body = JSON.parse(result.content[0].text) as Record<string, unknown>;
- if (!result.isError) {
- // GBRA-498: the trusted local CLI's --room is marked here, where the brain is; any other lane's answer goes back
- // unmarked and the CLI marks every item unknown.
+ // GBRA-498: the trusted local CLI's --room is marked here, where the brain is; any other lane's answer goes back
+ // unmarked and the CLI marks every item unknown.
+ const answer = async (): Promise<unknown> => {
if (request.room === undefined || verified.remote || verified.principal.kind !== 'local_cli') return body;
const { assessRoom, readRoomDeclaration } = await import('../access/room.ts');
const room = await assessRoom(engine, { op: request.operation, result: body, sourceId,
declaration: readRoomDeclaration({ requestMeta: { room: request.room } }, undefined).declaration!,
caller: { access: currentCallerAccess(), transport: 'cli', local: true } });
return { [PERSISTENCE_ROOM_MARKED_KEY]: { result: room.result, meta: room.meta, notices: room.stamped } };
- }
+ };
+ if (!result.isError) return answer();
// GST-1387: a remember batch with a failed item keeps every item's receipt; the CLI exits 1 on its status.
- if (Array.isArray(body.items) && body.status === 'error') return body;
+ if (Array.isArray(body.items) && body.status === 'error') return answer();
const error = new OperationError(typeof body.error === 'string' ? body.error : 'unavailable',
typeof body.message === 'string' ? body.message : 'The local operation could not complete.',
typeof body.suggestion === 'string' ? body.suggestion : undefined);
diff --git a/src/core/think/index.ts b/src/core/think/index.ts
index a8579abcfb..5c5cad6c46 100644
--- a/src/core/think/index.ts
+++ b/src/core/think/index.ts
@@ -234,6 +234,11 @@ export interface ThinkResult {
feedback_evidence?: Array<{ source_id: string; slug: string; content_hash: string | null }>;
/** #5575 I2: every page, take and trajectory fact placed in the synthesis prompt; `persistSynthesis` taints from them. The op layer strips it. */
taint_refs?: TaintRef[];
+ /**
+ * GBRA-498: what reaches the prompt beyond taint_refs, for room marks only: the anchor and the graph pages the prompt
+ * names, and a calibration profile (no page or fact id, so the answer is unknown). Never feeds trust derivation.
+ */
+ room_extra?: Array<{ table: 'pages'; sourceId: string; slug: string } | { table: 'calibration'; id: number }>;
/** Only set when --save was true and the caller persisted a synthesis page. */
savedSlug?: string;
/**
@@ -1048,6 +1053,9 @@ export async function runThink(
feedback_evidence: gather.pages.map(pg => ({ source_id: pg.source_id ?? 'default', slug: pg.slug, content_hash: pg.content_hash ?? null })),
taint_refs: [...gather.pages.map(pg => ({ table: 'pages' as const, sourceId: pg.source_id ?? 'default', slug: pg.slug })),
...gather.takes.map(t => ({ table: 'takes' as const, id: t.take_id })), ...trajectoryFactIds.map(id => ({ table: 'facts' as const, id }))],
+ room_extra: [...(graphBlock ? [opts.anchor, ...gather.graphSlugs.slice(0, 30)].filter((s): s is string => !!s)
+ .map(slug => ({ table: 'pages' as const, sourceId: opts.sourceId ?? 'default', slug })) : []),
+ ...(calibrationBlockOpts ? [{ table: 'calibration' as const, id: 0 }] : [])],
...(extractive ? { extractive } : {}),
usage, ...(evidenceDelivery ? { evidence_delivery: evidenceDelivery } : {}),
diagnostics: {
diff --git a/test/access-room.test.ts b/test/access-room.test.ts
index 48e91b3481..98558c9229 100644
--- a/test/access-room.test.ts
+++ b/test/access-room.test.ts
@@ -304,6 +304,7 @@ for (const kind of testBackends()) {
expect((await think([open])).room_access).toEqual({ readable: true });
expect((await think([open, { table: 'pages', sourceId: SRC, slug: PAGES.mine.slug }])).room_access).toEqual({ readable: false, reason: 'readers' });
expect((await think([open, { table: 'takes', id: 1 }])).room_access).toEqual({ readable: 'unknown', reason: 'not_identified' });
+ expect((await think([open, { table: 'calibration', id: 0 }])).room_access).toEqual({ readable: 'unknown', reason: 'not_identified' });
expect((await think([])).room_access).toEqual({ readable: 'unknown', reason: 'not_identified' });
expect((await think(undefined)).room_access).toEqual({ readable: 'unknown', reason: 'not_identified' });
const kept = keepRoomEvidence({ answer: 'a' }, [open]);