Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Keep shared agents' share: true and defer the shared rows QM could write for a person (GST-2249)

garrytan0192842aad93
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93bc65cc71..ac1b42bb0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,15 +18,15 @@ identifiers and attribution are available in the pre-removal Git revision
| Area | Before | Now |
|---|---|---|
-| Page writes from QM | `add_timeline_entry`, `add_link`, `put_page` and `edit_page` were refused; every other page write could be listed in `--attest-ops` | every operation that writes a page's content, frontmatter, tags, links, timeline, facts, raw data or uploads, or deletes or restores it, is refused (`actor_not_attested`, reason `op_not_attested`), at `--attest-ops`, on every call and when a queued write publishes |
+| Page writes from QM | `add_timeline_entry`, `add_link`, `put_page` and `edit_page` were refused; every other page write could be listed in `--attest-ops` | every operation that writes a page's content, frontmatter, tags, links, timeline, facts, raw data or uploads, or deletes or restores it, is refused, and so are the shared rows with no page (`rate_answer` feedback, `log_ingest`, `loops_mute` and `loops_unmute`) (`actor_not_attested`, reason `op_not_attested`), at `--attest-ops`, on every call and when a queued write publishes |
| A fact saved for a person | `share: true` put it on its subject's page for every reader of the source | refused (`invalid_params`, reason `attested_share_refused`), as is `visibility: "world"`; the reply points at `memory_propose` |
| Writeback instructions for a service acting for a person | "share: true shares a fact about the team's work" | never pass `share: true`; propose team knowledge with `memory_propose` |
| QM contract | v2 and v3 `deferred_ops` named 11 operations | they name every deferred operation; v1 is byte-identical |
### Itemized changes
-- `src/core/access/actor-model.ts`: `ACTOR_DEFERRED_OPS` gains every remaining page write. `test/qm-attest-write-boundary.test.ts` checks that every attestable mutating operation in the registry is either deferred or reviewed as not a page write, so a new page write cannot become attestable unnoticed.
-- `src/core/verbs.ts`, `src/core/access/member-facts.ts`, `src/core/persistence/memory-prepare.ts`: an attested `remember` refuses `share: true` and `visibility: "world"` at the call (a batch included), and a stored shared save made for a person is refused when it is prepared.
+- `src/core/access/actor-model.ts`: `ACTOR_DEFERRED_OPS` gains every remaining page write, plus `rate_answer` (its feedback is keyed to the client, not the person, so one person could see another's restricted page in a refusal and move its ranking), `log_ingest` (text every reader of the ingest log sees) and `loops_mute`/`loops_unmute` (they close or reopen other people's loops). `test/qm-attest-write-boundary.test.ts` checks that every attestable mutating operation in the registry is either deferred or reviewed as not a page write, so a new page write cannot become attestable unnoticed.
+- `src/core/verbs.ts`, `src/core/access/member-facts.ts`, `src/core/persistence/memory-prepare.ts`: an attested `remember` refuses `share: true` and `visibility: "world"` at the call (a batch included), and a stored shared save made for a person is refused when it is prepared; a shared agent acting for an audience (`on_behalf_of`) still shares.
- `src/core/facts/writeback-instructions.ts`: the instruction line for a service acting for a person.
- `docs/contracts/qm-memory-provider/v2.json`, `v3.json`: regenerated `deferred_ops` (a published-contract amendment).
- Docs: `docs/guides/qm.md`, `docs/mcp/ADMIN.md`, `docs/guides/write-refusals.md`, `docs/tutorials/company-brain.md`.
diff --git a/docs/contracts/qm-memory-provider/v2.json b/docs/contracts/qm-memory-provider/v2.json
index b6df5c5966..1dad8d23eb 100644
--- a/docs/contracts/qm-memory-provider/v2.json
+++ b/docs/contracts/qm-memory-provider/v2.json
@@ -37,7 +37,10 @@
"extract_entities",
"extract_facts",
"list_write_conflicts",
+ "log_ingest",
"loops_close",
+ "loops_mute",
+ "loops_unmute",
"ontology_propose",
"put_page",
"put_pages",
@@ -45,6 +48,7 @@
"questions_pin",
"questions_refresh",
"questions_unpin",
+ "rate_answer",
"remove_link",
"remove_tag",
"restore_page",
diff --git a/docs/contracts/qm-memory-provider/v3.json b/docs/contracts/qm-memory-provider/v3.json
index 3f4ee33c29..d8b9d8f2d7 100644
--- a/docs/contracts/qm-memory-provider/v3.json
+++ b/docs/contracts/qm-memory-provider/v3.json
@@ -37,7 +37,10 @@
"extract_entities",
"extract_facts",
"list_write_conflicts",
+ "log_ingest",
"loops_close",
+ "loops_mute",
+ "loops_unmute",
"ontology_propose",
"put_page",
"put_pages",
@@ -45,6 +48,7 @@
"questions_pin",
"questions_refresh",
"questions_unpin",
+ "rate_answer",
"remove_link",
"remove_tag",
"restore_page",
diff --git a/docs/guides/qm.md b/docs/guides/qm.md
index 9ce8fca8d6..6ed908e243 100644
--- a/docs/guides/qm.md
+++ b/docs/guides/qm.md
@@ -37,8 +37,8 @@ They read as the person, their own restricted pages included, so grant them only
the client that serves the person's own DM, never to a client that serves shared
rooms.
No page write is attestable: `put_page`, `edit_page`, `append_page`, `add_timeline_entry`, `add_link`,
-tags, deletes, restores, uploads, raw data and every other operation that writes a page are listed in
-the contract's `deferred_ops`. A person's words reach a shared page only through an owner-approved
+tags, deletes, restores, uploads, raw data and every other operation that writes a page, plus answer
+feedback, the ingest log and loop muting, are listed in the contract's `deferred_ops`. A person's words reach a shared page only through an owner-approved
proposal (`memory_propose`, [below](#proposed-writes)). `--attest-ops` refuses them, and a list that
already names one is refused for it on every call (`actor_not_attested`, reason `op_not_attested`).
An attested `remember` keeps the fact on the person's own page: `share: true` or `visibility: "world"`
diff --git a/src/core/access/actor-model.ts b/src/core/access/actor-model.ts
index a5d08b92de..4d845714fc 100644
--- a/src/core/access/actor-model.ts
+++ b/src/core/access/actor-model.ts
@@ -22,7 +22,9 @@ export const SCOPE_ATTEST_OPS: ReadonlySet<string> = new Set(['forget', 'forget_
* approve them, and GST-2249 W1 deferred every other page write: anything that writes a page's content, frontmatter,
* links, tags, timeline, facts, attached data or files, or deletes or restores a page. The only attested writes left
* are the person's own (memory_write, remember, forget and forget_fact on the member page) and memory_propose, which
- * holds a write for the owner. test/qm-attest-write-boundary.test.ts checks every attestable mutating operation in the
+ * holds a write for the owner. W1 also deferred the writes whose rows every reader shares without a page: answer
+ * feedback (rate_answer, keyed to the client, not the person), the ingest log (log_ingest) and loop suppression
+ * (loops_mute, loops_unmute). test/qm-attest-write-boundary.test.ts checks every attestable mutating operation in the
* registry is either here or reviewed as not a page write. Refused at `--attest-ops`, at every call and when a stored
* write or job tool call is re-resolved.
*/
@@ -34,6 +36,7 @@ export const ACTOR_DEFERRED_OPS: ReadonlySet<string> = new Set([
'put_page', 'put_pages', 'edit_page', 'append_page', 'delete_page', 'restore_page', 'revert_version',
'begin_page_upload', 'upload_page_part', 'commit_page_upload', 'abort_page_upload',
'put_raw_data', 'extract_entities', 'questions_pin', 'questions_refresh', 'questions_unpin',
+ 'rate_answer', 'log_ingest', 'loops_mute', 'loops_unmute',
]);
/** Canonical person ids: 1-256 visible ASCII characters (QM's credential broker rule), no case folding. */
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 72b3790141..7fe14534df 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1513,7 +1513,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.655.0', id: 'personal_sources_gbra284', text: 'An operator can bind a source to the member it belongs to (`gbrain access member source add <member> <source>`, migration v299); a bound source is personal. An attested call (`x-qm-actor`) now reads its credential\'s grant minus every personal source bound to another member, and a read that names sources as their audience (the scope read) reads no personal source at all, not even the speaker\'s own. A hidden personal source named in `source_id` or `source_ids` is refused exactly like a source outside the grant (`permission_denied`); an unnamed read skips it. The rule only hides inside the grant and never makes a source readable, so it is within the existing trust posture (gate_rev 6). On an existing install nothing changes until an operator binds a source; after that, a credential whose grant already includes the bound source stops showing it to attested callers for anyone else. Unattested calls and member-bound credentials are unchanged.' },
{ since: '0.60.655.0', id: 'qm_personal_structured_gst1158', text: 'An attested call (`x-qm-actor`) to `query`, `get_page`, `get_timeline`, `get_backlinks`, `find_experts`, `whois`, `entity`, `context_pack`, `volunteer_context`, `get_write_request` or `forget_fact` now also answers with its result in `structuredContent` (a list as `structuredContent.results`) and its refusals with `structuredContent.error`; `content` keeps the JSON, except `context_pack`, whose `content` is now its rendered text alone. A personal read whose answer, counted with `structuredContent`, is over the result cap is refused whole (`result_too_large`). Each `memory_recall` fact in `structuredContent.facts` gains `arm` (`own` or `ranked`). The same tools without `x-qm-actor` are unchanged, and none of them joined the default attested operations.' },
{ since: '0.60.655.0', id: 'memory_propose_held_writes_gst1158', text: 'New attested operation `memory_propose` (add it to `--attest-ops`): QM proposes one timeline entry or link on a shared page for the person it serves, and nothing is written until the brain owner runs `gbrain memory-proposals approve <request_id>` (`list`, `show`, `deny --reason`). `get_write_request` and `cancel_write_request` read and withdraw the proposal; an approved one becomes an ordinary write under the same request id. Held text stays in the `memory_proposals` table, out of git, export, search and recall. Proposals expire after `proposals.ttl_hours` (168), at most 10 wait per person and 50 per credential, and closed ones are deleted after `proposals.retention_days` (30). `gbrain doctor` (`memory_proposals_pending`) and `gbrain status` show the queue.' },
- { since: '0.60.655.0', id: 'attest_every_page_write_deferred_gst2249', text: 'An attested call (`x-qm-actor`) may no longer run any operation that writes a page: besides `add_timeline_entry`, `add_link`, `put_page` and `edit_page`, also `append_page`, `put_pages`, `delete_page`, `restore_page`, `revert_version`, `add_tag`, `remove_tag`, `remove_link`, the page uploads, `put_raw_data`, `extract_entities`, `ontology_propose`, `confirm_memory`, `loops_close` and the `questions_*` writes. `gbrain auth rescope --attest-ops` refuses a list that names one, a credential whose list already names one is refused for it on every attested call (`actor_not_attested`, reason `op_not_attested`), and a queued attested write of one fails when it publishes. An attested `remember` with `share: true` or `visibility: "world"` is refused (`invalid_params`, reason `attested_share_refused`) and nothing is saved; the fact stays on the person\'s own page without them, and `memory_propose` is the path to a shared page. Unattested calls and member-bound credentials are unchanged. The QM contract files v2.json and v3.json list the new operations in `deferred_ops`.' },
+ { since: '0.60.655.0', id: 'attest_every_page_write_deferred_gst2249', text: 'An attested call (`x-qm-actor`) may no longer run any operation that writes a page: besides `add_timeline_entry`, `add_link`, `put_page` and `edit_page`, also `append_page`, `put_pages`, `delete_page`, `restore_page`, `revert_version`, `add_tag`, `remove_tag`, `remove_link`, the page uploads, `put_raw_data`, `extract_entities`, `ontology_propose`, `confirm_memory`, `loops_close` and the `questions_*` writes, and the shared rows with no page: `rate_answer`, `log_ingest`, `loops_mute` and `loops_unmute`. `gbrain auth rescope --attest-ops` refuses a list that names one, a credential whose list already names one is refused for it on every attested call (`actor_not_attested`, reason `op_not_attested`), and a queued attested write of one fails when it publishes. An attested `remember` with `share: true` or `visibility: "world"` is refused (`invalid_params`, reason `attested_share_refused`) and nothing is saved; the fact stays on the person\'s own page without them, and `memory_propose` is the path to a shared page. Unattested calls and member-bound credentials are unchanged. The QM contract files v2.json and v3.json list the new operations in `deferred_ops`.' },
{ since: '0.60.655.0', id: 'member_email_link_gst1158', text: 'A member can carry an operator-declared email: `gbrain access member add <id> --email <addr>` or `gbrain access member set <id> --email <addr>|none`, shown by `member list`, stored lower-case and unique per brain, and cleared when the member is removed. `gbrain access member link --email <addr> --qm <id>` (and `gbrain mcp admin link --email`, `member-add --email`, `member-set` over the owner session) links the one member that declares it, exactly as linking by member id does; an unknown email is `not_found` and creates nothing. No OAuth token, attested call or MCP tool can set an email or make a link.' },
{ since: '0.60.655.0', id: 'qm_admin_http_gst1094', text: 'The brain owner can now manage the attest right, members and canonical-id links over the running server: `gbrain mcp admin attest <client> --attest-actor qm|none [--attest-ops <list>]`, `member-add`, `member-disable`, `member-enable`, `members`, `link <member> --qm <id>`, `unlink --qm <id>` and `links`, backed by `/admin/api/access/attest`, `/admin/api/access/members` and `/admin/api/access/member-links`. These routes take the owner session only (never an OAuth token or an MCP tool), refuse what the local `gbrain auth rescope` and `gbrain access member` commands refuse, preview with `--dry-run` where those do, and log each applied change as `access_admin`. Removing a member stays a brain-host command.' },
];
diff --git a/src/core/persistence/memory-prepare.ts b/src/core/persistence/memory-prepare.ts
index 06cc7a3518..871d3be88c 100644
--- a/src/core/persistence/memory-prepare.ts
+++ b/src/core/persistence/memory-prepare.ts
@@ -26,6 +26,7 @@ import { UNATTRIBUTED_MEMORY_SLUG } from '../facts/extract-from-fence.ts';
import { noteBelief } from '../belief/ledger.ts';
import { attestedShareRefused, MEMBER_PAGE_PREFIX, memberPageFrontmatter, memberPageIsOwn, memberPageNotOwned, onOwnedMemoryPageSql, scopePageFrontmatter, scopePageIsShared, scopePageNotShared } from '../access/member-facts.ts';
import { claimColumns, storedClaim } from '../facts/typed-claim.ts';
+import { parseStoredActor } from '../access/actor-model.ts';
function conflict(row: WriteRequest): never {
throw opError('revision_conflict', 'The memory changed during semantic preparation.',
@@ -73,8 +74,9 @@ export async function prepareMemoryMutation(engine: BrainEngine, row: WriteReque
{ fix: requestReceiptFix(row) });
}
const p = row.intent;
- // GST-2249 W1: a stored save made for an attested person never publishes shared, whenever it was admitted.
- if (p.share === true && row.authority?.actingFor != null) throw attestedShareRefused(opError);
+ // GST-2249 W1: a stored save made for an attested person never publishes shared, whenever it was admitted. An audience
+ // (on_behalf_of) is not an attested person, so a shared agent's share: true still publishes.
+ if (p.share === true && parseStoredActor(row.authority?.actingFor)) throw attestedShareRefused(opError);
const claim = storedClaim(p);
const input: SingleFactIntent = { fact: String(p.fact).trim(), kind: (p.kind ?? 'fact') as SingleFactIntent['kind'],
visibility: (p.visibility ?? 'world') as SingleFactIntent['visibility'], entity_slug: p.entity_slug as string | null,
diff --git a/test/access-qm-actor.test.ts b/test/access-qm-actor.test.ts
index 9ab0393158..c188218461 100644
--- a/test/access-qm-actor.test.ts
+++ b/test/access-qm-actor.test.ts
@@ -515,6 +515,9 @@ for (const kind of testBackends()) {
['extract_entities', { text: 'Alice met Bob.' }], ['ontology_propose', { subject: PAGES.alice.slug, fact: 'x' }],
['confirm_memory', { ref: 'p:' + SRC + '/' + PAGES.alice.slug }], ['loops_close', { id: 1 }],
['questions_pin', { question: 'x?' }], ['questions_refresh', { id: 1 }], ['questions_unpin', { id: 1 }],
+ // Shared rows with no page: answer feedback, the ingest log and loop suppression.
+ ['rate_answer', { answer_id: 'x', rating: 'up' }], ['log_ingest', { source_type: 'note', source_ref: 'x', pages_updated: [], summary: 'x' }],
+ ['loops_mute', { sender: '[email protected]' }], ['loops_unmute', { sender: '[email protected]' }],
];
expect(new Set(deferredCalls.map(([op]) => op))).toEqual(new Set(ACTOR_DEFERRED_OPS));
for (const [op, params] of deferredCalls) {
diff --git a/test/qm-attest-write-boundary.test.ts b/test/qm-attest-write-boundary.test.ts
index 5aff8f8493..40d71be222 100644
--- a/test/qm-attest-write-boundary.test.ts
+++ b/test/qm-attest-write-boundary.test.ts
@@ -34,7 +34,10 @@ import type { AuthInfo } from '../src/core/ops/contract.ts';
import { testBackends } from './helpers/test-backends.ts';
import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
-/** Attestable mutating operations that write no page every reader of it sees, each with the reason. */
+/**
+ * Attestable mutating operations that write nothing another person reads or relies on, each with the reason. A row
+ * here is a reviewed claim; rate_answer, log_ingest and loops_mute|unmute were deferred because their rows are shared.
+ */
const NOT_PAGE_WRITES: Record<string, string> = {
remember: "the person's own member page; share: true is refused when attested",
memory_write: "the person's own member page, or a scope page the credential's attest_sources allows",
@@ -43,10 +46,6 @@ const NOT_PAGE_WRITES: Record<string, string> = {
memory_propose: 'holds the write for the brain owner; nothing is written until the owner approves',
cancel_write_request: "cancels the caller's own queued request",
memory_conversation_mode: 'returns a rule for the conversation and stores nothing',
- rate_answer: 'retrieval feedback tables only',
- log_ingest: 'ingest_log audit rows only',
- loops_mute: 'loop suppression rows only',
- loops_unmute: 'loop suppression rows only',
mute_notice: 'a local notice mute list, outside the brain database',
request_tools: "the calling client's own MCP tool surface",
think: 'read-only for remote callers; only a local --save writes',
@@ -128,6 +127,16 @@ for (const kind of testBackends()) {
expect(await factRow('canaryw1kept')).toMatchObject({ visibility: 'private', source_markdown_slug: 'memory/members/alice-example' });
}, 120_000);
+ test('a shared agent acting for an audience (on_behalf_of, not an attested person) still shares', async () => {
+ const c = await provider().registerClientManual('w1-shared-' + randomUUID().slice(0, 8), ['client_credentials'], 'read write', [], SRC);
+ await bindCredential(engine, { kind: 'client', id: c.clientId }, { mayActFor: ['member:alice-example'] });
+ const auth = await verify((await provider().exchangeClientCredentials(c.clientId, c.clientSecret ?? '')).access_token);
+ const out = await dispatchToolCall(engine, 'remember', { fact: 'Acme renewed canaryw1audience', provenance: 'qm test', entity: ACME, share: true },
+ { remote: true, transport: 'http', auth, sourceId: SRC, onBehalfOf: { header: 'member:alice-example' } });
+ expect(out.isError === true).toBe(false);
+ expect(await factRow('canaryw1audience')).toMatchObject({ visibility: 'world', source_markdown_slug: ACME });
+ }, 120_000);
+
test('a stored shared save made for a person is refused when it is prepared', async () => {
const [page] = await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE source_id = $1 AND slug = $2', [SRC, ACME]);
const row = { operation: 'remember', request_id: 'w1-prepare-' + randomUUID().slice(0, 6), source_id: SRC, slug: ACME, page_id: page!.id,