Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(entity): batch entity lookups respect quarantine
garrytan613cdd413ab0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cf6b72f7db..bb9e2da9a2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,14 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.178.0] - 2026-10-12++**Batch entity lookups respect quarantine.** `entity` with `names` now hides quarantined pages from remote callers the way a single-name `entity` lookup and `get_page` already do, whichever way the name resolves, and a quarantined identity sibling no longer appears beside a page for remote callers, in batch rows or in a single-name card. Trusted local callers see the same results as before. No migration, no paid call.++### Itemized changes++- **Batch entity lookups respect quarantine.** `lookupEntityNames` passes the remote caller's quarantine rule to the card resolver, and identity-sibling reads (`readIdentitySiblings`, through `readCardIdentity`) leave out quarantined pages when the caller's card does. Covered by remote and local tests in `test/entity-names.test.ts`.+## [0.60.177.0] - 2026-10-12**Fix wave 15: a managed brain can no longer be routed to the wrong writer or lose pages it imported, the pages that refused every write since an old import write again, and every wedge the wave reproduced has a named exit.** A missing or malformed persistence-mode row used to read as "unmanaged" in more than a hundred places, so an impossible empty read on CI sent a managed brain through the legacy writer; it now refuses with `storage_error` everywhere. A `--full` sync kept deleting pages imported from untracked working-tree files; it keeps them. A first or `--full` sync above the cursor bound finishes in slices instead of refusing. Some 80,000 pages whose stored frontmatter still carried the parser's reserved keys refused every write as `source_changed`; the comparison ignores those keys and a consented sweep cleans them. Conversation-facts extraction no longer lists a page twice and blocks the whole batch, `projections drain` no longer spins forever on one stale row, backups no longer fail on a stale socket, prefix-bound agents can `remember`, doctor stops echoing registration credentials, Haiku 5.5 long prompts are charged at the tier Anthropic bills, and Google contacts without an email get a page. Fifty-nine changes across seven areas; one additive migration (v239); no paid model call is added anywhere.diff --git a/src/core/mentions/siblings.ts b/src/core/mentions/siblings.tsindex 4ec1a47492..8b349d48e8 100644--- a/src/core/mentions/siblings.ts+++ b/src/core/mentions/siblings.ts@@ -64,7 +64,7 @@ export interface IdentitySiblings {* candidate (untrusted callers).*/export async function readIdentitySiblings(engine: BrainEngine, sourceId: string, page: { slug: string; title: string | null },- opts: { excludePrivate: boolean; policy?: MentionPolicy; pack?: PackTypes | null }): Promise<IdentitySiblings> {+ opts: { excludePrivate: boolean; excludeQuarantined?: boolean; policy?: MentionPolicy; pack?: PackTypes | null }): Promise<IdentitySiblings> {const subject = normalizeAlias(titleName(page.title ?? ''));if (!subject) return { pages: [], capped: false, verdict: 'subject_mismatch' };try {@@ -73,7 +73,9 @@ export async function readIdentitySiblings(engine: BrainEngine, sourceId: stringconst pack = opts.pack !== undefined ? opts.pack : await loadSourcePack(engine, sourceId);const types = linkableTypesFor(pack, policy);const { privatePagesFilterFragment } = await import('../search/private-visibility.ts');- const privacy = opts.excludePrivate ? ` AND ${privatePagesFilterFragment('pages')}` : '';+ const { quarantineFilterFragment } = await import('../quarantine.ts');+ const privacy = (opts.excludePrivate ? ` AND ${privatePagesFilterFragment('pages')}` : '')+ + (opts.excludeQuarantined ? ` AND ${quarantineFilterFragment('pages')}` : '');const like = `%: ${subject.replace(/[\\%_]/g, m => `\\${m}`)}`;const rows = await engine.executeRaw<{ slug: string; title: string | null; type: string | null; identity: unknown }>(`SELECT slug, title, type, frontmatter->>'identity' AS identity FROM pagesdiff --git a/src/core/verbs/entity-card-identity.ts b/src/core/verbs/entity-card-identity.tsindex 73eb56a12a..47b59c2a68 100644--- a/src/core/verbs/entity-card-identity.ts+++ b/src/core/verbs/entity-card-identity.ts@@ -112,8 +112,8 @@ const GUIDANCE_VERBS = 'aka lists names gbrain recognized as declared on this pa/** The card's identity fields for `row`. Fail-soft: a failed read leaves the field out. */export async function readCardIdentity(engine: BrainEngine, sourceId: string,row: { slug: string; title: string | null; compiled_truth: string | null },- opts: { excludePrivate: boolean; surfaceCeiling?: 'verbs' | 'starter' | 'full'; aka: string[] }): Promise<CardIdentity> {- const siblings = await readIdentitySiblings(engine, sourceId, row, { excludePrivate: opts.excludePrivate });+ opts: { excludePrivate: boolean; excludeQuarantined?: boolean; surfaceCeiling?: 'verbs' | 'starter' | 'full'; aka: string[] }): Promise<CardIdentity> {+ const siblings = await readIdentitySiblings(engine, sourceId, row, { excludePrivate: opts.excludePrivate, excludeQuarantined: opts.excludeQuarantined });const slugs = [row.slug, ...siblings.pages.map(p => p.slug)];const aliasRows = await engine.executeRaw<{ slug: string; alias_norm: string; origin: string | null; alias_text: string | null }>(`SELECT slug, alias_norm, origin, alias_text FROM page_aliases WHERE source_id = $1 AND slug = ANY($2::text[]) ORDER BY alias_norm`,diff --git a/src/core/verbs/entity-card.ts b/src/core/verbs/entity-card.tsindex 1f60e08ef7..8c672fb8a2 100644--- a/src/core/verbs/entity-card.ts+++ b/src/core/verbs/entity-card.ts@@ -325,7 +325,7 @@ export async function buildEntityCard(const card = await assembleCard(engine, sourceId, best.row, opts.remote, excludePrivate, opts.eligibility ?? {});if (opts.includeReferences) {Object.assign(card, await cardReferences(engine, sourceId, best.row, opts, excludePrivate, entityTypes),- await readCardIdentity(engine, sourceId, best.row, { excludePrivate, surfaceCeiling: opts.surfaceCeiling, aka: card.aka }));+ await readCardIdentity(engine, sourceId, best.row, { excludePrivate, excludeQuarantined: opts.omitQuarantined === true, surfaceCeiling: opts.surfaceCeiling, aka: card.aka }));}return {found: true,diff --git a/src/core/verbs/entity-names.ts b/src/core/verbs/entity-names.tsindex cafd6bcc47..d0feb4c358 100644--- a/src/core/verbs/entity-names.ts+++ b/src/core/verbs/entity-names.ts@@ -2,8 +2,8 @@* `entity` with `names`: resolve a list of names, codes and aliases in one* call, the way a reader resolves the account codes and nicknames a batch of* handoff mails names. Each name resolves exactly as `entity name:` does- * (buildEntityCard's alias, slug, title and fuzzy arms, private pages hidden- * from remote callers) and returns a compact row: the page, its names, the+ * (buildEntityCard's alias, slug, title and fuzzy arms; private and+ * quarantined pages, siblings included, hidden from remote callers) and returns a compact row: the page, its names, the* opening lines of its body (`lead`) and its identity siblings with theirs.* No references, facts or open threads: a full card per name is `entity name:`.*@@ -48,7 +48,7 @@ export async function lookupEntityNames(engine: BrainEngine, sourceId: string, nasync function lookupOne(engine: BrainEngine, sourceId: string, name: string,opts: { remote: boolean; surfaceCeiling?: 'verbs' | 'starter' | 'full' }): Promise<EntityNameRow> {- const result = await buildEntityCard(engine, sourceId, name, { remote: opts.remote, includeReferences: false });+ const result = await buildEntityCard(engine, sourceId, name, { remote: opts.remote, includeReferences: false, omitQuarantined: opts.remote });if (!result.found || !result.card) {const suggestions = (result.suggestions ?? []).slice(0, 3).map(s => ({ slug: s.slug, title: s.title }));return { name, found: false, ...(suggestions.length ? { suggestions } : {}) };@@ -58,7 +58,7 @@ async function lookupOne(engine: BrainEngine, sourceId: string, name: string,'SELECT slug, title, compiled_truth FROM pages WHERE source_id = $1 AND slug = $2 AND deleted_at IS NULL', [sourceId, entity.slug]);const { resolveExcludePrivatePages } = await import('../search/private-visibility.ts');const excludePrivate = await resolveExcludePrivatePages(engine, opts.remote ? undefined : false);- const identity = row ? await readCardIdentity(engine, sourceId, row, { excludePrivate, surfaceCeiling: opts.surfaceCeiling, aka }).catch(() => null) : null;+ const identity = row ? await readCardIdentity(engine, sourceId, row, { excludePrivate, excludeQuarantined: opts.remote, surfaceCeiling: opts.surfaceCeiling, aka }).catch(() => null) : null;const siblingPages = identity?.identity_siblings?.pages ?? [];const bodies = new Map<string, string | null>([[entity.slug, row?.compiled_truth ?? null]]);if (siblingPages.length) {diff --git a/test/entity-names.test.ts b/test/entity-names.test.tsindex 27fa3e8fd8..5b2245a6de 100644--- a/test/entity-names.test.ts+++ b/test/entity-names.test.ts@@ -81,6 +81,32 @@ describe('entity names[]', () => {expect((await call({ names: ['Kite Co'] }, false)).body.results[0]).toMatchObject({ found: true, slug: 'crm/kite-co' });});+ test('a quarantined page stays a remote miss by exact slug, exact title and slug suffix, and is found locally', async () => {+ await accounts();+ await engine.executeRaw(`UPDATE pages SET frontmatter = COALESCE(frontmatter, '{}'::jsonb) || '{"quarantine":{"reason":"junk_pattern","detail":"test","assessed_at":"2026-10-07T00:00:00Z"}}'::jsonb WHERE slug = 'crm/kite-co'`);+ const names = ['crm/kite-co', 'CRM record: Kite Co', 'kite-co'];+ const remote = (await call({ names })).body;+ expect(remote.results.map((r: { found: boolean }) => r.found)).toEqual([false, false, false]);+ expect(JSON.stringify(remote)).not.toContain('LATAM');+ const local = (await call({ names }, false)).body;+ expect(local.results.every((r: { found: boolean; slug?: string }) => r.found && r.slug === 'crm/kite-co')).toBe(true);+ });++ test('a quarantined identity sibling is left out for remote callers, in the batch rows and the single-name card', async () => {+ await accounts();+ await engine.executeRaw(`UPDATE pages SET frontmatter = COALESCE(frontmatter, '{}'::jsonb) || '{"quarantine":{"reason":"junk_pattern","detail":"test","assessed_at":"2026-10-07T00:00:00Z"}}'::jsonb WHERE slug = 'accounts/widget-co'`);+ const batch = (await call({ names: ['WGCO'] })).body;+ expect(batch.results[0]).toMatchObject({ found: true, slug: 'crm/widget-co' });+ expect(batch.results[0].siblings ?? []).toEqual([]);+ expect(JSON.stringify(batch)).not.toContain('Copper Fox');+ const card = (await call({ name: 'WGCO' })).body;+ expect(card.found).toBe(true);+ expect(JSON.stringify(card)).not.toContain('accounts/widget-co');+ expect(JSON.stringify(card)).not.toContain('Copper Fox');+ const local = (await call({ names: ['WGCO'] }, false)).body;+ expect(local.results[0].siblings.map((s: { slug: string }) => s.slug)).toEqual(['accounts/widget-co']);+ });+test('the lead drops headings and private fences, redacts secrets and is bounded', () => {const body = '# Heading\n\nFirst line.\n\n## Facts\n\n<!--- gbrain:facts:begin -->\n| # | claim | kind | confidence | visibility | notability | valid_from | valid_until | source | context |\n|---|---|---|---|---|---|---|---|---|---|\n| 1 | Private note | fact | 1.0 | private | medium | 2026-01-01 | | test | |\n<!--- gbrain:facts:end -->\n\nSecond line. ' + 'x'.repeat(400);const lead = pageLead(body);