Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Owner default saves about a private page or replacing its own fact stay on its member page; its world onto a restricted page is refused (GST-2346)
garrytan9cd52ee5daf0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0f1b4a8b88..9d2f676578 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,7 +12,7 @@ identifiers and attribution are available in the pre-removal Git revision## [Unreleased]-**The brain owner's own agents now save facts shared by default, the way they already save pages.** A credential bound to the brain owner (`gbrain access owner set`) reads the whole brain, but its `remember` kept every fact private on the owner's member page unless the call passed `share: true`, its `visibility: "world"` was refused, and its `forget` refused a fact it had just shared. Those private facts also stayed out of hot memory, turn context and context packs, which carry shared facts only. Now, speaking for itself, the owner's credential saves a fact with no `visibility` on its subject's page for every reader of the source, keeps it private on its member page when the call passes `visibility: "private"` or the page or `facts.default_visibility` keeps facts private, and withdraws a shared fact it reads. The reply still names the `page` and `visibility` the fact got. The trade-off: an owner agent that follows a planted instruction can now share a fact without passing a flag, so pass `visibility: "private"` for a fact that must stay with the owner. Member credentials, attested QM calls (`x-qm-actor`), audiences, subagent jobs and slug-fenced clients keep what they had. Works the same on a brain with no Git repository and on a managed one.+**The brain owner's own agents now save facts shared by default, the way they already save pages.** A credential bound to the brain owner (`gbrain access owner set`) reads the whole brain, but its `remember` kept every fact private on the owner's member page unless the call passed `share: true`, its `visibility: "world"` was refused, and its `forget` refused a fact it had just shared. Those private facts also stayed out of hot memory, turn context and context packs, which carry shared facts only. Now, speaking for itself, the owner's credential saves a fact with no `visibility` on its subject's page for every reader of the source, keeps it private on its member page when the call passes `visibility: "private"`, when the page or `facts.default_visibility` keeps facts private, or when it replaces a fact on that page, and withdraws a shared fact it reads. An explicit `visibility: "world"` onto a page whose facts are kept private is refused (`share_target_restricted`), as `share: true` is. The reply still names the `page` and `visibility` the fact got. The trade-off: an owner agent that follows a planted instruction can now share a fact without passing a flag, so pass `visibility: "private"` for a fact that must stay with the owner. Member credentials, attested QM calls (`x-qm-actor`), audiences, subagent jobs and slug-fenced clients keep what they had. Works the same on a brain with no Git repository and on a managed one.Reported by @andreineacsu (#9101). First fixed by @Masashi-Ono0611 in #9103.diff --git a/docs/guides/access-designations.md b/docs/guides/access-designations.mdindex 023d6a4983..a299825301 100644--- a/docs/guides/access-designations.md+++ b/docs/guides/access-designations.md@@ -124,10 +124,11 @@ Each fact row has its own visibility. `remember` defaults to `world`, except intexplicit private `facts.default_visibility`. A remote credential bound to a member saves `private` on its own memberpage (`memory/members/<member>`) unless the call passes `share: true`, and its `visibility: "world"` is refused; itwithdraws only facts on that page, and the brain host withdraws the rest (`gbrain forget <id>`). The owner's own-credential, speaking for itself (no audience, not a subagent job, no slug fence), saves like a credential bound to no-member: shared on the subject's page, or `private` on its member page when it passes `visibility: "private"` or the-page or `facts.default_visibility` keeps facts private (the reply names the `page` and `visibility`), and its `forget`-withdraws a shared fact it reads. The trade-off: an owner agent that follows a planted instruction can share a fact+credential (or a stdio server started with `--stdio-member <owner>`), speaking for itself (no audience, not a+subagent job, no slug fence), saves like a credential bound to no member: shared on the subject's page, or `private` on its member page when it passes `visibility: "private"` or the+page or `facts.default_visibility` keeps facts private (the reply names the `page` and `visibility`; an explicit+`visibility: "world"` onto a page whose facts are kept private is refused, `share_target_restricted`), and its+`forget` withdraws a shared fact it reads. The trade-off: an owner agent that follows a planted instruction can share a factwithout passing any flag, so pass `visibility: "private"` for a fact that must stay with the owner. Extracted facts follow `facts.default_visibility` (private when unset)and are never wider than their page. Remote fact reads return private facts to the owner only.diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 589cb311ea..12e335e593 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1536,7 +1536,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.676.0', id: 'write_capacity_low_saved_gst2107', text: 'The `write_capacity_low` notice a write receipt carries now opens with "This write was saved" and its fix is the read-only `gbrain doctor --only persistence_capacity --json` (actor agent) instead of a `gbrain config set` cap raise for the user, so an agent reading the end of a successful write no longer reports it as refused. The one-more-year value doctor, the notice snapshot and `/metrics` recommend now uses the 7-day mean rate, so one bulk day is no longer projected for a year; days-to-exhaustion still uses the larger of the mean and the last 24 hours. A `write_quota_exhausted`, `write_quota_insufficient` or background-pause refusal names the same value doctor does instead of sizing the year from the latest 1,000 admissions.' },{ since: '0.60.676.0', id: 'ingest_backfill_409_recovery_gst2112', text: 'A `revision_backfill_pending` refusal (a write to a page the revision backfill has not reached, including the 409 a webhook capture to such a page gets from `POST /ingest`) now names the command that resumes the backfill, `gbrain apply-migrations --force-schema` on the brain host, instead of `gbrain apply-migrations --yes`, which does not resume it once the schema is current. A capture answered 409 stores and queues nothing, so its sender sends it again after the backfill; an `ingest_capture` job already queued for such a page goes straight to dead and is re-run with `gbrain jobs retry <id>`.' },{ since: '0.60.678.0', id: 'unmanaged_push_history_scan_8902', text: 'Four pushes from a checkout that is not a managed worktree now scan every local commit they publish for secrets, not only what they just wrote: the access-policy commit (`gbrain access rule` and the other policy writers), the durability-scaffolding commit of `gbrain sources harden`, `gbrain sources push`, and the first push of `gbrain bootstrap repo` (the whole history, since the remote has no such branch yet). A credential that a commit made with plain `git commit` added, even one a later commit removed, or one in a commit message, now refuses `publish_secret_found` naming the file, line, rule and commit (never the value), and nothing is pushed; history the scan cannot read in full refuses `publish_scan_unreadable`. The local commits stay where they are. `gbrain sources push` now pushes the exact commit it scanned, leased on the remote tip it read, and an allowlist (`.gbrain-scan-allow`) edit it commits itself still publishes; one a script committed is left for the user to review and push. Remove the value from the unpublished commits, or allowlist a false positive by fingerprint, then rerun.' },- { since: 'TBD', id: 'owner_facts_shared_gst2346', text: 'A credential bound to the brain owner (`gbrain access owner set`), speaking for itself, now saves `remember` facts the way a credential bound to no member does: with no `visibility`, a fact is shared on its subject\'s page and every reader of the source recalls it, where it used to be kept private on the owner\'s member page. It stays private on that page when the call passes `visibility: "private"` or the subject\'s page or `facts.default_visibility` keeps facts private, and the reply names the `page` and `visibility` either way. Its `visibility: "world"` is saved instead of refused (`member_share_required`), and its `forget` withdraws a shared fact it reads instead of saying only the brain host can. An owner agent that follows a planted instruction can therefore share a fact without passing any flag; to keep a fact private, pass `visibility: "private"`. Member credentials, attested QM calls (`x-qm-actor`), audiences (`X-Gbrain-On-Behalf-Of`), subagent jobs and slug-fenced clients are unchanged, and with writeback on the owner\'s credential is no longer told its saves stay private.' },+ { since: 'TBD', id: 'owner_facts_shared_gst2346', text: 'A credential bound to the brain owner (`gbrain access owner set`), or a stdio server started with `--stdio-member <owner>`, speaking for itself, now saves `remember` facts the way a credential bound to no member does: with no `visibility`, a fact is shared on its subject\'s page and every reader of the source recalls it, where it used to be kept private on the owner\'s member page. It stays private on that page when the call passes `visibility: "private"` or the subject\'s page or `facts.default_visibility` keeps facts private, and the reply names the `page` and `visibility` either way. Its `visibility: "world"` is saved instead of refused (`member_share_required`), except onto a page whose facts are kept private (`share_target_restricted`, as `share: true`), and its `forget` withdraws a shared fact it reads instead of saying only the brain host can. An owner agent that follows a planted instruction can therefore share a fact without passing any flag; to keep a fact private, pass `visibility: "private"`. Member credentials, attested QM calls (`x-qm-actor`), audiences (`X-Gbrain-On-Behalf-Of`), subagent jobs and slug-fenced clients are unchanged, and with writeback on the owner\'s credential is no longer told its saves stay private.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/persistence/memory-mutations.ts b/src/core/persistence/memory-mutations.tsindex 3c5a59ac2d..ef6a81d0bd 100644--- a/src/core/persistence/memory-mutations.ts+++ b/src/core/persistence/memory-mutations.ts@@ -32,6 +32,7 @@ import { callerMember, factVisibilitySql, memberFactPage, memberPageIsOwn, membeimport { perCallWriteSource } from '../access/attest-sources.ts';import { ownerSpeaksForItself } from '../access/member-facts.ts';+import { isDerivationPrivate } from '../search/private-visibility.ts';export { prepareMemoryMutation } from './memory-prepare.ts';/** Only semantic appends without an explicit caller revision can be recomputed. */@@ -158,6 +159,14 @@ async function rememberVisibility(ctx: OperationContext, call: RememberCall, pagreturn resolveRememberVisibility(ctx.engine, page && await withFolderRestricted(ctx.engine, page));}+/** GST-2346 D1: whether the owner's default save stays on its member page: it replaces a fact there, or the target page or the brain's default keeps facts private. */+async function ownerDefaultKeptPrivate(ctx: OperationContext, sourceId: string, slug: string | null, replaces: unknown): Promise<boolean> {+ const id = Number(replaces);+ if (replaces !== undefined && replaces !== null && Number.isSafeInteger(id) && (await ownMemberFactIds(ctx.engine, sourceId, [id])).has(id)) return true;+ const snapshot = slug ? await ctx.engine.readPageSnapshot(slug, { sourceId }) : null;+ return await rememberVisibility(ctx, { p: {}, visibilityDefaulted: true }, snapshot && { ...snapshot.page, source_id: sourceId, slug: slug! }) === 'private';+}+async function rememberCarry(ctx: OperationContext, call: RememberCall, page: PageLabel): Promise<RememberCarry> {const { p } = call;return { visibility: await rememberVisibility(ctx, call, page), ...(typeof p.kind === 'string' ? { kind: p.kind } : {}),@@ -209,7 +218,8 @@ export async function submitRememberMutation(ctx: OperationContext, params: Recoconst scopePage = perCallWriteSource(ctx, sourceId);const ownPage = scopePage ? null : memberFactPage(ctx);// GST-2346 D1: the brain owner speaking for itself saves as a caller with no member page does, unless it asks for private.- const ownerShares = ownPage !== null && p.share !== true && ownerSpeaksForItself(ctx) && (opts.visibilityDefaulted === true || p.visibility !== 'private');+ const ownerShares = ownPage !== null && p.share !== true && ownerSpeaksForItself(ctx) && (opts.visibilityDefaulted === true+ ? !await ownerDefaultKeptPrivate(ctx, sourceId, resolved?.slug ?? null, p.replaces) : p.visibility !== 'private');let memberPage = scopePage ? SCOPE_PAGE_SLUG : p.share === true || ownerShares ? null : ownPage;let call: RememberCall = memberPage ? { p: { ...p, visibility: scopePage ? 'world' : 'private', infer_entity: false }, visibilityDefaulted: false }: { p, visibilityDefaulted: opts.visibilityDefaulted === true || p.share === true };@@ -230,9 +240,12 @@ export async function submitRememberMutation(ctx: OperationContext, params: Recoinference = null; linked = null; entitySlug = resolved?.slug ?? null;({ slug, authority, snapshot, fence, binding, writeThrough } = await planRememberTarget(ctx, sourceId, source, entitySlug, null, call, memberPage));}- if (p.share === true && visibility !== 'world') {- throw Object.assign(verbError('invalid_params', `remember: share: true cannot share a fact on ${slug}, whose facts are kept private (restricted page or the brain's private fact default); nothing was saved.`,- 'Share it on a page every reader of this source can read, or drop share to keep the fact on your own page.'), { reason: 'share_target_restricted' });+ // D1: the owner's explicit visibility "world" onto a page whose facts are kept private is refused like share: true.+ const ownerWorldRestricted = ownerShares && !call.visibilityDefaulted && snapshot !== null && isDerivationPrivate(await withFolderRestricted(ctx.engine, { ...snapshot.page, source_id: sourceId, slug }));+ if (p.share === true && visibility !== 'world' || ownerWorldRestricted) {+ throw Object.assign(verbError('invalid_params', `remember: ${p.share === true ? 'share: true' : 'visibility "world"'} cannot share a fact on ${slug}, whose facts are kept private (restricted page or the brain's private fact default); nothing was saved.`,+ p.share === true ? 'Share it on a page every reader of this source can read, or drop share to keep the fact on your own page.'+ : 'Share it on a page every reader of this source can read, or pass visibility "private" to keep the fact on your own page.'), { reason: 'share_target_restricted' });}const factIntent = { fact: String(p.fact).trim(), kind: (p.kind ?? 'fact') as never, visibility, entity_slug: entitySlug, ...(memberPage ? { page_slug: memberPage } : {}) };// Fail fast on an invalid target or a withdrawn claim; the coordinator re-checks both under its locks before publishing.diff --git a/test/owner-facts-d1-gst2346.test.ts b/test/owner-facts-d1-gst2346.test.tsindex 097c41ab3f..e1e2473c2d 100644--- a/test/owner-facts-d1-gst2346.test.ts+++ b/test/owner-facts-d1-gst2346.test.ts@@ -41,6 +41,7 @@ import { managedBrain, settleManagedGitEffects } from './helpers/managed-brain.tconst ACME = 'companies/acme-example';const GLOBEX = 'companies/globex-example';+const INITECH = 'companies/initech-example';const OWNER = 'carol-example';const OWNER_PAGE = 'memory/members/' + OWNER;const ATTEST_OPS = ['forget', 'forget_fact', 'get_write_request', 'memory_recall', 'memory_write', 'recall', 'remember'];@@ -57,6 +58,7 @@ async function seedCallers(engine: BrainEngine, sourceId: string,await setOwner(engine, OWNER);await writePage(ACME, '---\ntype: company\ntitle: Acme Example\n---\n# Acme Example\n\nAcme example builds harbor ledgers.');await writePage(GLOBEX, '---\ntype: company\ntitle: Globex Example\nreadable_by: [' + OWNER + ']\n---\n# Globex Example\n\nGlobex example runs a quiet pilot.');+ await writePage(INITECH, '---\ntype: company\ntitle: Initech Example\nvisibility: private\n---\n# Initech Example\n\nInitech example audits printers.');const tokens: Record<string, string> = {};const bindings: Record<string, Parameters<typeof bindCredential>[2] | null> = {owner: { member: OWNER }, alice: { member: 'alice-example' }, bob: { member: 'bob-example' }, plain: null,@@ -154,6 +156,22 @@ for (const kind of testBackends()) {expect(await h.row('canaryownerglobex')).toMatchObject({ visibility: 'private', source_markdown_slug: OWNER_PAGE, entity_slug: GLOBEX });}, 120_000);+ test("a visibility: private page keeps the owner's default save private on its own page; its explicit world onto a page that names readers is refused", async () => {+ const out = await h.remember('owner', 'Initech audit moved canaryownerinitech', { entity: INITECH });+ expect([out.isError ? out.text : 'ok', out.json.page, out.json.visibility]).toEqual(['ok', OWNER_PAGE, 'private']);+ expect(await h.row('canaryownerinitech')).toMatchObject({ visibility: 'private', source_markdown_slug: OWNER_PAGE, entity_slug: INITECH });+ const world = await h.remember('owner', 'Globex pilot in public canaryownerglobexworld', { entity: GLOBEX, visibility: 'world' });+ expect([world.isError, world.json.reason]).toEqual([true, 'share_target_restricted']);+ expect(await h.row('canaryownerglobexworld')).toBeUndefined();+ }, 120_000);++ test("the owner's default save that replaces a fact on its own page supersedes it there, private", async () => {+ const old = await h.remember('owner', 'Acme margin is thin canaryownerreplaceold', { visibility: 'private' });+ const out = await h.remember('owner', 'Acme margin recovered canaryownerreplacenew', { replaces: String(old.json.id) });+ expect([out.isError ? out.text : 'ok', out.json.status, out.json.page, out.json.visibility]).toEqual(['ok', 'superseded', OWNER_PAGE, 'private']);+ expect(await h.row('canaryownerreplacenew')).toMatchObject({ visibility: 'private', source_markdown_slug: OWNER_PAGE });+ }, 120_000);+test("the brain's private fact default keeps the owner's default save private, on its own page, and the reply says so", async () => {await engine.setConfig(FACTS_DEFAULT_VISIBILITY_KEY, 'private');try {