Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep a later-quarantined page's creation claims out of belief deltas for remote callers
garrytand0f8bed6ce35
diff --git a/src/core/belief/changes.ts b/src/core/belief/changes.tsindex 484b082407..8a66f07dc4 100644--- a/src/core/belief/changes.ts+++ b/src/core/belief/changes.ts@@ -291,13 +291,16 @@ export async function beliefChanges(engine: BrainEngine, q: BeliefChangesQuery):/*** Fence subjects of a page body, keyed `kind\u0000subject_key`, under the history reader's rules: a subject whose key a- * purge hid is dropped for every caller; a remote caller gets them only where it may read the interval and it was not quarantined, and only+ * purge hid is dropped for every caller; a remote caller gets them only where it may read the interval and neither the interval nor the live page is quarantined, and only* world rows (takes of holders it may read) whose claim was not made private after the interval's event.*/async function subjectsOf(engine: BrainEngine, q: BeliefChangesQuery, at: Awaited<ReturnType<typeof readPageAtTime>>, interval: NonNullable<Awaited<ReturnType<typeof readPageAtTime>>['current']>,privateAfter = interval.event.id) {if (!interval.page || interval.body === 'unavailable' || interval.body === 'segmented' || interval.page.compiled_truth == null) return null;- if (q.remote && (isQuarantined(interval.page.frontmatter) || !await remoteMayRead(engine, at.page_id, interval))) return null;+ if (q.remote) {+ const [live] = at.page_id == null ? [] : await engine.executeRaw<{ frontmatter: Record<string, unknown> | null }>('SELECT frontmatter FROM pages WHERE id = $1', [at.page_id]);+ if (isQuarantined(interval.page.frontmatter) || isQuarantined(live?.frontmatter) || !await remoteMayRead(engine, at.page_id, interval)) return null;+ }const { subjects } = await bodySubjects(engine, interval.lifetime, `${interval.page.compiled_truth}\n${interval.page.timeline ?? ''}`, interval.event.visibility);const holders = new Set(q.takesHolders ?? ['world']);const readable = subjects.filter(s => !q.remote || s.visibility === 'world' && (s.kind !== 'take' || holders.has(String(s.value.holder))));diff --git a/test/recorded-read-gate.test.ts b/test/recorded-read-gate.test.tsindex 97848a91c4..94561efabe 100644--- a/test/recorded-read-gate.test.ts+++ b/test/recorded-read-gate.test.ts@@ -100,5 +100,20 @@ for (const engineCase of testBackends().map(beliefEngineCase)) {expect(out.text).toContain('canaryclaimcontrol');expect(out.text.includes('canaryqclaim')).toBe(false);}), 120_000);++ test('(6) a page created clean and quarantined by a later write: delta {beliefs: true} gives a remote caller none of its creation claims', () => brain(async b => {+ const t0 = await at(b);+ const slug = 'companies/late-quarantine-example';+ await b.put(slug, beliefPage({ facts: ['Canary claim canarylateq'] }));+ await b.put('companies/plain-late-example', beliefPage({ facts: ['Canary claim canarylatecontrol'] }));+ await b.put(slug, beliefPage({ title: 'Attention Required! | Cloudflare', facts: ['Canary claim canarylateq'] }));+ const [row] = await b.engine.executeRaw<{ q: unknown }>(`SELECT frontmatter->'quarantine' AS q FROM pages WHERE source_id = $1 AND slug = $2`, [b.sourceId, slug]);+ expect(row?.q).toMatchObject({ reason: 'junk_pattern' });+ await new Promise(resolve => setTimeout(resolve, 2_500));+ const remote = { ...remoteOf(b), auth: { clientId: 'reader-probe', scopes: ['read'] } } as unknown as BeliefBrain['ctx'];+ const out = await call(b, remote, 'delta', { since: t0, beliefs: true });+ expect(out.text).toContain('canarylatecontrol');+ expect(out.text.includes('canarylateq')).toBe(false);+ }), 120_000);});}