Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
The brain owner's credential withdraws a private fact the host wrote (GST-2346)
garrytan758c8a690884
diff --git a/src/core/persistence/forget-prepare.ts b/src/core/persistence/forget-prepare.tsindex 74a9335d00..937a314501 100644--- a/src/core/persistence/forget-prepare.ts+++ b/src/core/persistence/forget-prepare.ts@@ -26,7 +26,8 @@ import { remoteForgetRaced, supersessionGuarded } from '../trust/supersede-handlimport { materializedPage } from './segmented-apply.ts';import { prepareFileTarget, snapshotLedger, unreadPageFile } from './page-prepare.ts';import { pageIdentityError } from './page-identity.ts';-import { MEMBER_PAGE_PREFIX } from '../access/member-facts.ts';+import { MEMBER_PAGE_PREFIX, onOwnedMemoryPageSql } from '../access/member-facts.ts';+import { storedOwnerSpeaksForItself } from './page-visibility.ts';import type { CompanionPage, PageMutationFile, PreparedMutation } from './coordinator.ts';import type { WriteRequest } from './model.ts';import { UNATTRIBUTED_MEMORY_SLUG } from '../facts-fence.ts';@@ -71,6 +72,16 @@ export async function refuseForgetReachingOtherCopies(tx: BrainEngine, sourceId:'Keep the fact. To withdraw the claim everywhere, ask the user to forget it on the brain host.');}+/**+ * GST-2346 D1: whether fact id is one the brain owner's own credential withdraws besides shared facts and the facts on+ * its member page: a private fact on no member or scope page, held by a page no remote writer is kept from (or by no+ * page). A fact on a private page or on a page that names readers stays with the brain host.+ */+export async function ownerReachesPrivateFact(engine: BrainEngine, id: number, sourceId: string): Promise<boolean> {+ return (await engine.executeRaw(`SELECT 1 FROM facts WHERE id=$1 AND source_id=$2 AND visibility='private'+ AND NOT ${onOwnedMemoryPageSql('facts')} AND ${privateProvenanceFilterFragment('facts')}`, [id, sourceId])).length > 0;+}+/*** The fact a forget names, under the caller's visibility (locked inside a transaction when `lock`); null when it is not* visible. GST-359 D: a member's forget (`ownPage`, its member page) reads only the private facts on that page while@@ -93,15 +104,21 @@ export async function prepareForgetMutation(engine: BrainEngine, row: WriteRequeconst sourceId = row.source_id;const remote = row.authority.remote !== false;const reason = typeof p.reason === 'string' && p.reason.trim() ? p.reason.trim() : null;- const excludePrivate = await resolveExcludePrivatePages(engine, remote);// GST-359 D: a member's withdrawal of a fact on its own member page (submitForgetMutation records the page).const ownPage = remote && typeof p.member_page === 'string' && p.member_page === row.slug && row.slug.startsWith(MEMBER_PAGE_PREFIX) ? row.slug : null;+ // GST-2346 D1: the owner's withdrawal of a private fact off its member page (submitForgetMutation marks it). The owner+ // is judged again here from the stored principal, so a request whose writer is no longer the owner reads the fact as+ // any remote caller does: not found. Such a withdrawal never reaches a copy on a page kept from remote writers.+ const ownerReach = remote && !ownPage && p.owner_reach === true && Number.isSafeInteger(id) && id > 0+ && await storedOwnerSpeaksForItself(engine, row.authority) && await ownerReachesPrivateFact(engine, id, sourceId);+ const worldOnly = remote && !ownerReach;+ const excludePrivate = ownerReach || await resolveExcludePrivatePages(engine, remote);const missing = () => verbError(row.operation === 'forget' ? 'not_found' : 'fact_not_found',`No fact with id "${rawId}".`, 'Ids come from remember/recall. Recall the entity first to find the right fact.');if (!Number.isSafeInteger(id) || id <= 0) throw missing();- const fact = await readForgetTarget(engine, id, sourceId, remote, excludePrivate, false, ownPage);+ const fact = await readForgetTarget(engine, id, sourceId, worldOnly, excludePrivate, false, ownPage);if (!fact) throw missing();- const plan = await planFactWithdrawal(engine, id, sourceId, remote, ownPage ? undefined : excludePrivate, ownPage);+ const plan = await planFactWithdrawal(engine, id, sourceId, worldOnly, ownPage ? undefined : excludePrivate, ownPage);if (!plan) throw missing();// The files are struck with this timestamp, and the ledger row records it, so the file and the read overlay agree.const withdrawnAt = new Date().toISOString();@@ -151,17 +168,17 @@ export async function prepareForgetMutation(engine: BrainEngine, row: WriteReque...(row.operation === 'forget_fact' && fact.expired_at !== null ? { failure: { code: 'fact_already_expired', message: `Fact id ${id} already expired.` } } : {}),validate: async tx => {// Under the publication's locks: the fact is still visible, no more trusted than a remote caller, and reaches no other copy.- const current = await readForgetTarget(tx, id, sourceId, remote, excludePrivate, true, ownPage);+ const current = await readForgetTarget(tx, id, sourceId, worldOnly, excludePrivate, true, ownPage);if (!current) throw missing();if (remote && supersessionGuarded('agent_written', current.trust_tier)) throw remoteForgetRaced(id);- if (!ownPage) await refuseForgetReachingOtherCopies(tx, sourceId, current, remote, excludePrivate);+ if (!ownPage) await refuseForgetReachingOtherCopies(tx, sourceId, current, worldOnly, excludePrivate);await held?.validate?.(tx);},apply: async (tx, preimage) => {if (held) await held.apply(tx, preimage ?? null);// Even an expired legacy fact acquires a ledger row (forget_fact then finishes failed), so a stale import cannot reactivate it.const publication = { withdrawnAt, expectedSlugs: plan.slugs };- pages = (await recordFactWithdrawal(tx, id, sourceId, remote, ownPage+ pages = (await recordFactWithdrawal(tx, id, sourceId, worldOnly, ownPage? { requestId: row.id, semanticReview: false, memberPage: ownPage, publication }: { requestId: row.id, semanticReview: p.semantic_review !== false, excludePrivate, publication })).pages.map(page => page.slug);if (reason) await tx.executeRaw(`UPDATE facts SET context=concat_ws(' | ',NULLIF(context,''),$3::text)diff --git a/src/core/persistence/memory-mutations.ts b/src/core/persistence/memory-mutations.tsindex 0df8691317..306930e6f0 100644--- a/src/core/persistence/memory-mutations.ts+++ b/src/core/persistence/memory-mutations.ts@@ -1,5 +1,6 @@import { throwIfHeld } from '../trust/gate-outcomes.ts';-import { guardRemoteForget, remoteForgetRaced, supersessionGuarded } from '../trust/supersede-handlers.ts';+import { forgetRequiresOwner, guardRemoteForget, remoteForgetRaced, supersessionGuarded } from '../trust/supersede-handlers.ts';+import { storedTrustTier } from '../trust/tier.ts';import { randomUUID } from 'node:crypto';import { isAbsolute } from 'node:path';import type { OperationContext } from '../ops/contract.ts';@@ -13,7 +14,7 @@ import { parseFactsFence } from '../facts-fence.ts';import { isSegmentedPage } from '../page-body/page-shape.ts';import { segmentedRememberRefusal, type RememberCarry } from './verb-errors.ts';import { materializedPage, segmentedOverCeiling } from './segmented-apply.ts';-import { excludesPrivateWrites } from './page-visibility.ts';+import { excludesPrivateWrites, storedOwnerSpeaksForItself } from './page-visibility.ts';import { emitFenceNotice, initializeLocalPersistence, requestPrincipalForContext } from './page-mutations.ts';import { authorizeStoredRequest, submissionAuthority } from './authority.ts';import { admitWrite, assertPageRequestIdentity, assertReplayIntent, getWriteRequest, intentDigest } from './journal.ts';@@ -24,7 +25,7 @@ import { clientRequestIdOf, parseMutationPrecondition } from './preconditions.tsimport { grantedWriteSource, writeGrantRefusal } from './write-grant.ts';import type { WriteRequest } from './model.ts';import { prepareMemoryMutation } from './memory-prepare.ts';-import { readForgetTarget, refuseForgetReachingOtherCopies } from './forget-prepare.ts';+import { ownerReachesPrivateFact, readForgetTarget, refuseForgetReachingOtherCopies } from './forget-prepare.ts';import { UNATTRIBUTED_MEMORY_SLUG } from '../facts/extract-from-fence.ts';import { callerIsOwner, currentCallerAccess, folderRestricted, privateProvenanceFilterUnderPolicy, resolveExcludePrivatePages, withFolderRestricted } from '../search/private-visibility.ts';import { projectionEligibleSql } from '../eligibility/sql.ts';@@ -390,7 +391,14 @@ export async function submitForgetMutation(ctx: OperationContext, operation: 'foconst mine = member !== null && (await ownMemberFactIds(ctx.engine, sourceId, [id])).has(id);// GST-2346 D1: the owner speaking for itself withdraws a fact off its member page as a caller with no member page does.const asOwner = member !== null && !mine && ownerSpeaksForItself(ctx) && await readForgetTarget(ctx.engine, id, sourceId, remote, excludePrivate) !== null;- const ownPage = member && !asOwner ? memberPageSlug(member) : null;+ let ownPage = member && !asOwner ? memberPageSlug(member) : null;+ const hostWithdraws = () => verbError('permission_denied', ownerSpeaksForItself(ctx)+ ? `Fact #${rawId} is one this credential reads but cannot withdraw. Nothing was forgotten.`+ : `Fact #${rawId} is not on your member page ${ownPage}, so this credential cannot withdraw it. Nothing was forgotten.`,+ ownerSpeaksForItself(ctx)+ ? `The brain owner's credential withdraws shared facts, facts on its member page and private facts on pages it can write. The brain host withdraws this one with gbrain forget ${rawId}.`+ : `A member credential withdraws only the facts on its own member page. The brain host withdraws this one with gbrain forget ${rawId}.`);+ let ownerReach = false;if (ownPage && !mine) {// #9101: a fact the caller reads (one it shared, or a teammate's shared fact) is refused by name; a fact it cannot read stays not_found.// An attested QM actor keeps not_found for every fact off its page, as QM memory-provider contract v3 states.@@ -399,27 +407,37 @@ export async function submitForgetMutation(ctx: OperationContext, operation: 'foconst eligible = projectionEligibleSql('facts', 'facts', await resolveReadEligibility(ctx));const reads = (await ctx.engine.executeRaw(`SELECT 1 FROM facts WHERE id=$1 AND source_id=$2 AND ${readable} AND ${eligible}${excludePrivate ? ` AND ${privateProvenanceFilterUnderPolicy('facts')}` : ''}`, [id, sourceId])).length > 0;if (!reads) throw missing();- throw verbError('permission_denied', `Fact #${rawId} is not on your member page ${ownPage}, so this credential cannot withdraw it. Nothing was forgotten.`,- `A member credential withdraws only the facts on its own member page. The brain host withdraws this one with gbrain forget ${rawId}.`);+ // GST-2346 D1: the owner speaking for itself also withdraws a private fact it reads on a page its credential may+ // write (one the brain host wrote); preparation judges the owner again from the stored principal.+ ownerReach = ownerSpeaksForItself(ctx) && await ownerReachesPrivateFact(ctx.engine, id, sourceId);+ if (!ownerReach) throw hostWithdraws();+ ownPage = null;}+ // The owner's private-fact withdrawal reads the fact as the brain host does, and never reaches a copy on a page kept from remote writers.+ const worldOnly = remote && !ownerReach;+ const hidePrivate = ownerReach || excludePrivate;// #5575 I3: a remote caller cannot forget a fact more trusted than its own writes; the owner is asked instead.if (remote) await guardRemoteForget(ctx.engine, { sourceId, factId: id, principal, reason, excludePrivate });const [source] = await ctx.engine.executeRaw<RememberSource>("SELECT incarnation,archived,local_path,config->>'kind' AS kind FROM sources WHERE id=$1", [sourceId]);if (!source || source.archived) throw sourceInactive(sourceId);- const fact = await readForgetTarget(ctx.engine, id, sourceId, remote, excludePrivate, false, ownPage);+ const fact = await readForgetTarget(ctx.engine, id, sourceId, worldOnly, hidePrivate, false, ownPage);if (!fact) throw missing();- if (remote && supersessionGuarded('agent_written', fact.trust_tier)) throw remoteForgetRaced(id);- if (!ownPage) await refuseForgetReachingOtherCopies(ctx.engine, sourceId, fact, remote, excludePrivate);+ if (remote && supersessionGuarded('agent_written', fact.trust_tier)) {+ // guardRemoteForget reads shared facts only: a more trusted private fact the owner reaches asks the owner the same way.+ throw ownerReach ? await forgetRequiresOwner(ctx.engine, { sourceId, factId: id, principal, reason, factTier: storedTrustTier(fact.trust_tier), writerTier: 'agent_written' }) : remoteForgetRaced(id);+ }+ if (!ownPage) await refuseForgetReachingOtherCopies(ctx.engine, sourceId, fact, worldOnly, hidePrivate);const slug = fact.source_markdown_slug ?? fact.entity_slug ?? UNATTRIBUTED_MEMORY_SLUG;enforceClientSlugFence(ctx, slug, operation); enforceSubagentSlugFence(ctx, slug, operation);const authority = await submissionAuthority(ctx, operation, sourceId, source.incarnation, slug);+ if (ownerReach && !await storedOwnerSpeaksForItself(ctx.engine, authority)) throw hostWithdraws();const snapshot = await ctx.engine.readPageSnapshot(slug, { sourceId, includeDeleted: true });const sandbox = ctx.viaSubagent === true && !(ctx.allowedSlugPrefixes?.length);// The pages a withdrawal strikes publish through the source's canonical worktree, as remember's do. A source whose// root has no owner refuses when a canonical file carries the claim (Git is the parent: a database-only withdrawal// would come back on a rebuild from Git); a claim only database-only pages carry is withdrawn database-only.- const plan = await planFactWithdrawal(ctx.engine, id, sourceId, remote, ownPage ? undefined : excludePrivate, ownPage);+ const plan = await planFactWithdrawal(ctx.engine, id, sourceId, worldOnly, ownPage ? undefined : hidePrivate, ownPage);// GST-2492: a fact held on memory/unattributed for an entity with no page is struck there too (its row names the entity).const heldOn = fact.source_markdown_slug === UNATTRIBUTED_MEMORY_SLUG && fact.entity_slug !== null ? UNATTRIBUTED_MEMORY_SLUG : null;const struck = plan ? plan.slugs.filter(page => plan.subject === '*' || plan.subject === page || page === heldOn) : [];@@ -443,7 +461,7 @@ export async function submitForgetMutation(ctx: OperationContext, operation: 'fo// GST-359 D: a member's own-page withdrawal is recorded for that page alone and queues no semantic review.const row = await admitWrite(ctx.engine, { origin: ctx.admissionOrigin, principal, operation, sourceId, sourceIncarnation: source.incarnation,slug, pageId: snapshot?.page.id ?? null, requestId, clientRequestId, callerIntent,- intent: { ...callerIntent, reason, semantic_review: !ownPage && p.semantic_review !== false, ...(ownPage ? { member_page: ownPage } : {}) }, authority,+ intent: { ...callerIntent, reason, semantic_review: !ownPage && p.semantic_review !== false, ...(ownPage ? { member_page: ownPage } : {}), ...(ownerReach ? { owner_reach: true } : {}) }, authority,worktreeId: binding?.worktree_id ?? null, topologyGeneration: binding?.topology_generation ?? null, deferrable: true });const written = await waitForWrite(ctx.engine, row, ctx.config, waitMs ?? ctx.writeWaitMs);return withSimilarActive(ctx, operation, sourceId, p, writeResponse(written));diff --git a/src/core/persistence/page-visibility.ts b/src/core/persistence/page-visibility.tsindex e04873559a..8e6f38a841 100644--- a/src/core/persistence/page-visibility.ts+++ b/src/core/persistence/page-visibility.ts@@ -206,6 +206,17 @@ export async function defaultSourceWriterIsOwner(engine: SqlEngine, writer: strireturn !!live;}+/**+ * GST-2346 D1: whether a stored remote write came from the brain owner's own credential speaking for itself, judged+ * live from the stored authority (the request-time twin is ownerSpeaksForItself): no attested actor, no audience, no+ * subagent and no slug fence, and the principal's member is the enabled owner now. A credential unbound, a member+ * disabled or an owner changed after submission is not the owner here.+ */+export async function storedOwnerSpeaksForItself(engine: SqlEngine, authority: WriteAuthority): Promise<boolean> {+ if (!authority.remote || authority.actingFor || authority.restrictedNamespace || authority.slugPrefixes != null) return false;+ return defaultSourceWriterIsOwner(engine, (await memberIdentityFor(engine, authority)).find(p => p.startsWith('member:')) ?? null);+}+/*** GST-2051: the readers a page written by a default-source member writer (defaultSourceMemberWriter) keeps when its content* names none: the stored page's readers when it has them, else the writer alone for a page this write creates, unlessdiff --git a/test/owner-facts-d1-gst2346.test.ts b/test/owner-facts-d1-gst2346.test.tsindex e1e2473c2d..e026e90907 100644--- a/test/owner-facts-d1-gst2346.test.ts+++ b/test/owner-facts-d1-gst2346.test.ts@@ -31,6 +31,11 @@ import { setOwner } from '../src/core/access/owner.ts';import { linkMember } from '../src/core/access/actor.ts';import { remoteCallerAccess } from '../src/core/access/caller.ts';import { operationsByName } from '../src/core/operations.ts';+import { prepareForgetMutation } from '../src/core/persistence/forget-prepare.ts';+import { withCoordinatedWrite, withTrustPromotion } from '../src/core/persistence/context.ts';+import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';+import { decideTrustProposal } from '../src/core/trust/decide.ts';+import { parseTrustProposalRef } from '../src/core/trust/proposals.ts';import { FACTS_DEFAULT_VISIBILITY_KEY } from '../src/core/facts/visibility.ts';import { ambientOptsFrom, writebackCaller } from '../src/core/facts/writeback-config.ts';import { buildAmbientWritebackSection } from '../src/core/facts/writeback-instructions.ts';@@ -273,6 +278,91 @@ for (const kind of testBackends()) {} finally { await engine.setConfig('memory.auto_writeback', 'off'); }}, 120_000);+ /** A private fact the brain host wrote (the trusted local caller) about Acme, or about the entity extra names. */+ const hostFact = async (fact: string, extra: Record<string, unknown> = {}) => {+ const out = await dispatchToolCall(engine, 'remember', { fact, entity: ACME, provenance: 'owner facts test', visibility: 'private', ...extra }, { remote: false, sourceId: SRC });+ expect(out.isError === true ? out.content[0]?.text : 'ok').toBe('ok');+ return String(JSON.parse(out.content[0]!.text).id);+ };++ test("the owner withdraws a private fact the brain host wrote, by forget and by forget_fact; a member never read it", async () => {+ const id = await hostFact('Acme host kept a quiet reserve canaryhostprivate');+ expect(await h.row('canaryhostprivate')).toMatchObject({ visibility: 'private', source_markdown_slug: ACME });+ expect((await h.call('owner', 'recall', { entity: ACME })).text).toContain('canaryhostprivate');+ expect((await h.call('alice', 'recall', { entity: ACME })).text).not.toContain('canaryhostprivate');+ const out = await h.call('owner', 'forget', { id });+ expect(out.isError ? out.text : 'ok').toBe('ok');+ expect((await h.row('canaryhostprivate'))!.active).toBe(false);+ const second = await hostFact('Acme host kept a second reserve canaryhostsecond');+ const viaFact = await h.call('owner', 'forget_fact', { id: Number(second) });+ expect(viaFact.isError ? viaFact.text : 'ok').toBe('ok');+ expect((await h.row('canaryhostsecond'))!.active).toBe(false);+ }, 120_000);++ test("a member, an attested actor, a shared room, a subagent and a fenced owner credential still cannot withdraw a host-written private fact", async () => {+ const id = await hostFact('Acme host kept a sealed note canaryhostsealed');+ const room = { audience: 'member:' + OWNER + ', member:alice-example' };+ const answers = {+ member: (await h.call('alice', 'forget', { id })).json.error,+ unbound: (await h.call('plain', 'forget', { id })).json.error,+ actor: (await h.call('qm', 'forget', { id }, { actor: 'U0CAROL' })).json.error,+ room: (await h.call('room', 'forget', { id }, room)).json.error,+ ownerRoom: (await h.call('ownerRoom', 'forget', { id }, room)).json.error,+ ownerAlone: (await h.call('ownerRoom', 'forget', { id }, { audience: 'member:' + OWNER })).json.error,+ subagent: (await h.asSubagent('forget', { id })).json.error,+ fenced: (await h.call('fenced', 'forget', { id })).json.error,+ viaFact: (await h.call('alice', 'forget_fact', { id: Number(id) })).json.error,+ };+ // Each answer is the one that caller got before the owner's route existed.+ expect(answers).toEqual({ member: 'not_found', unbound: 'not_found', actor: 'not_found', room: 'not_found', ownerRoom: 'not_found',+ ownerAlone: 'scope_denied', subagent: 'scope_denied', fenced: 'permission_denied', viaFact: 'fact_not_found' });+ expect((await h.row('canaryhostsealed'))!.active).toBe(true);+ }, 120_000);++ test("a private fact on a page kept from remote writers stays with the brain host, and the refusal names it", async () => {+ const id = await hostFact('Initech host kept a sealed audit canaryhostinitech', { entity: INITECH });+ const out = await h.call('owner', 'forget', { id });+ expect([out.isError, out.json.error, out.text.includes('brain host'), out.text.includes('gbrain forget ' + id)]).toEqual([true, 'scope_denied', true, true]);+ expect((await h.row('canaryhostinitech'))!.active).toBe(true);+ }, 120_000);++ test("a host-written private fact more trusted than an agent's writes is not withdrawn: the owner is asked, as for a shared one", async () => {+ const id = await hostFact('Acme host confirmed its charter canaryhostconfirmed');+ await engine.transaction(tx => withCoordinatedWrite(tx, [SRC], () => withTrustPromotion(tx, 'user_confirmed', () =>+ tx.executeRaw("UPDATE facts SET trust_tier='user_confirmed' WHERE id=$1", [Number(id)])), TEST_WRITE_ATTRIBUTION));+ const out = await h.call('owner', 'forget', { id });+ expect([out.isError, out.json.error, out.json.code]).toEqual([true, 'scope_denied', 'forget_requires_owner']);+ expect((await h.row('canaryhostconfirmed'))!.active).toBe(true);+ // The proposal names the fact by id and tier only, and the owner's accept on the brain host applies the forget.+ const ref = JSON.parse(out.json.detail).proposal_ref as string;+ const [proposal] = await engine.executeRaw<{ stored: string }>('SELECT row_to_json(t)::text AS stored FROM trust_proposals t WHERE id=$1', [parseTrustProposalRef(ref)!]);+ expect([proposal!.stored.includes('"forget"'), proposal!.stored.includes('canaryhostconfirmed')]).toEqual([true, false]);+ expect((await decideTrustProposal(engine, parseTrustProposalRef(ref)!, 'accept', { confirmation: { via: 'tty' as const } })).status).toBe('accepted');+ expect((await h.row('canaryhostconfirmed'))!.active).toBe(false);+ }, 120_000);++ test("preparation judges the owner again from the stored principal: a stored request from any other writer reads the fact as not found", async () => {+ const id = await hostFact('Acme host kept a dated note canaryhostprepare');+ const [page] = await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE source_id=$1 AND slug=$2', [SRC, ACME]);+ const prepare = async (who: string, authority: Record<string, unknown> = {}, intent: Record<string, unknown> = { owner_reach: true }) => prepareForgetMutation(engine, {+ operation: 'forget', id: randomUUID(), request_id: randomUUID(), source_id: SRC, slug: ACME, page_id: page!.id, worktree_id: null, intent: { id, ...intent },+ authority: { version: 1, remote: true, principal: (await h.auth(who) as unknown as { principal: unknown }).principal, sourceId: SRC, slugPrefixes: null, ...authority },+ } as never, {} as never).then(() => 'prepared', (error: { code?: string }) => error.code);+ expect(await prepare('owner')).toBe('prepared');+ expect(await prepare('owner', {}, {})).toBe('not_found');+ expect(await prepare('alice')).toBe('not_found');+ expect(await prepare('plain')).toBe('not_found');+ expect(await prepare('owner', { actingFor: ['member:' + OWNER] })).toBe('not_found');+ expect(await prepare('owner', { restrictedNamespace: true })).toBe('not_found');+ expect(await prepare('owner', { slugPrefixes: ['companies/'] })).toBe('not_found');+ await setOwner(engine, 'bob-example');+ try {+ expect(await prepare('owner')).toBe('not_found');+ expect(await prepare('bob')).toBe('prepared');+ } finally { await setOwner(engine, OWNER); __resetPrivateVisibilityCacheForTests(); }+ expect((await h.row('canaryhostprepare'))!.active).toBe(true);+ }, 120_000);+test("an unbound connection never reads or withdraws the owner's private fact", async () => {const kept = await h.remember('owner', 'Acme private owner note canaryunboundhidden', { visibility: 'private' });expect((await h.call('plain', 'recall', { entity: ACME })).text).not.toContain('canaryunboundhidden');@@ -298,6 +388,15 @@ for (const kind of testBackends()) {const forget = await h.call('owner', 'forget', { id: String(out.json.id) });expect(forget.isError ? forget.text : 'ok').toBe('ok');expect((await h.row('canarymanagedowner'))!.active).toBe(false);+ // A private fact the brain host wrote sits in the page's file; the owner's forget strikes it there.+ const kept = await operationsByName.remember!.handler(ctx, { fact: 'Acme host kept a ledger canarymanagedhost', entity: ACME, provenance: 'owner facts test', visibility: 'private' }) as { id: string };+ await settleManagedGitEffects(engine);+ expect(readFileSync(file, 'utf8')).toContain('| Acme host kept a ledger canarymanagedhost |');+ const hostForget = await h.call('owner', 'forget', { id: String(kept.id) });+ expect(hostForget.isError ? hostForget.text : 'ok').toBe('ok');+ expect((await h.row('canarymanagedhost'))!.active).toBe(false);+ await settleManagedGitEffects(engine);+ expect(readFileSync(file, 'utf8')).toContain('~~Acme host kept a ledger canarymanagedhost~~');const member = await h.remember('alice', 'Acme member note canarymanagedmember');expect([member.isError, member.json.page, member.json.visibility]).toEqual([false, 'memory/members/alice-example', 'private']);}, kind === 'postgres' ? { databaseUrl: process.env.DATABASE_URL! } : {});