Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep the saved-fact keyword scan on its index when the entity-page check is added
garrytanc7972fb55efc
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.tsindex 598841a2de..3463856f11 100644--- a/src/core/search/private-visibility.ts+++ b/src/core/search/private-visibility.ts@@ -689,13 +689,17 @@ export function privateProvenanceFilterUnderPolicy(factAlias: string): string {* name keeps the fact and every other remote caller loses it. A fact with no entity page passes. Read sites only; it* only ever narrows.*/-export function privateEntityFilterForCaller(factAlias: string): string {- return `NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = ${factAlias}.source_id AND entity_pp.slug = ${factAlias}.entity_slug AND NOT ${privatePagesFilterForCaller('entity_pp')})`;+export function privateEntityFilterForCaller(factAlias: string, perCandidate = false): string {+ return `NOT EXISTS (SELECT 1 FROM pages entity_pp WHERE entity_pp.source_id = ${factAlias}.source_id AND entity_pp.slug = ${factAlias}.entity_slug AND NOT ${privatePagesFilterForCaller('entity_pp')}${perCandidate ? ' OFFSET 0' : ''})`;}-/** privateProvenanceFilterFragment for a remote fact read: the provenance page gate plus the caller's entity-page gate. */-export function privateFactFilterForCaller(factAlias: string): string {- return `(${privateProvenanceFilterFragment(factAlias)} AND ${privateEntityFilterForCaller(factAlias)})`;+/**+ * privateProvenanceFilterFragment for a remote fact read: the provenance page gate plus the caller's entity-page gate.+ * perCandidate keeps the entity gate a lookup per candidate row (OFFSET 0 stops the planner turning it into a join), so+ * a scan an index serves, such as the saved-fact keyword match, keeps that index.+ */+export function privateFactFilterForCaller(factAlias: string, perCandidate = false): string {+ return `(${privateProvenanceFilterFragment(factAlias)} AND ${privateEntityFilterForCaller(factAlias, perCandidate)})`;}/** True only inside a remote caller record whose read an operator relaxed (the env hatch or the config opt-out). */diff --git a/src/core/search/saved-facts-match.ts b/src/core/search/saved-facts-match.tsindex 357d2dae94..0422630e90 100644--- a/src/core/search/saved-facts-match.ts+++ b/src/core/search/saved-facts-match.ts@@ -97,7 +97,7 @@ export async function matchingSavedFacts(ctx: OperationContext, scope: { sourceIAND f.expired_at IS NULL AND (f.valid_until IS NULL OR f.valid_until > now())AND f.source != ALL($2::text[])${ctx.remote !== false ? `AND f.visibility = 'world'` : ''}`;- const eligible = `${excludePrivate ? `AND ${privateFactFilterForCaller('f')}` : ''}+ const eligible = `${excludePrivate ? `AND ${privateFactFilterForCaller('f', true)}` : ''}AND ${projectionEligibleSql('facts', 'f', { floor: scope.minTrust })}`;const lang = getFtsLanguage();const doc = factsFtsDocument('f');