Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

claim lane: pair member-page facts only on their own page (port master's onMemberPageSql guard)

garrytanbf5e1e7270fb
diff --git a/src/core/facts/claim-conflicts.ts b/src/core/facts/claim-conflicts.ts
index 5047248e0e..7130b88c9c 100644
--- a/src/core/facts/claim-conflicts.ts
+++ b/src/core/facts/claim-conflicts.ts
@@ -8,8 +8,9 @@
* visibility, the same non-null entity_slug, the same claim_metric, the same
* claim_unit and claim_period (null-safe), the same as-of bucket
* (typed-claim.ts claimBucket) and different claim_value. Points in different
- * buckets are history and are never proposed. The newer fact (valid_from, then
- * id) is proposed to supersede the older one.
+ * buckets are history and are never proposed. A fact on a member page pairs
+ * only with another fact on that same page (access/member-facts.ts onMemberPageSql).
+ * The newer fact (valid_from, then id) is proposed to supersede the older one.
*
* Bounded: at most max_pairs pairs per source per run, and a pair that already
* has a proposal (any lane, any status) or a pending trust supersede_fact
@@ -25,6 +26,7 @@ import type { PhaseResult } from '../cycle.ts';
import { AUDIT_ROW_SOURCES } from './audit-sources.ts';
import { insertProposal } from '../ai/decide/proposals-store.ts';
import { claimBucketSql } from './typed-claim.ts';
+import { onMemberPageSql } from '../access/member-facts.ts';
import { CLAIM_CONFLICTS_MAX_PAIRS_KEY, readPhaseConfigNumber } from '../cycle/phase-config-values.ts';
export const CLAIM_CONFLICTS_MODE_KEY = 'dream.claim_conflicts.mode';
@@ -76,7 +78,7 @@ export function claimConflictsModeRefusal(value: string): string | null {
}
const ACTIVE_CLAIMS = 'WITH f AS (\n'
- + ' SELECT id, entity_slug, visibility, claim_metric, claim_value, claim_unit, claim_period, valid_from, ' + claimBucketSql('facts') + ' AS bucket\n'
+ + ' SELECT id, entity_slug, visibility, claim_metric, claim_value, claim_unit, claim_period, valid_from, source_markdown_slug, ' + claimBucketSql('facts') + ' AS bucket\n'
+ ' FROM facts\n'
+ ' WHERE source_id = $1 AND expired_at IS NULL AND (valid_until IS NULL OR valid_until > now())\n'
+ ' AND entity_slug IS NOT NULL AND claim_metric IS NOT NULL AND claim_value IS NOT NULL AND source <> ALL($2::text[]))';
@@ -84,6 +86,7 @@ const PAIR_JOIN = 'FROM f n JOIN f o\n'
+ ' ON o.entity_slug = n.entity_slug AND o.visibility = n.visibility AND o.claim_metric = n.claim_metric\n'
+ ' AND o.claim_unit IS NOT DISTINCT FROM n.claim_unit AND o.claim_period IS NOT DISTINCT FROM n.claim_period\n'
+ ' AND o.bucket = n.bucket AND o.claim_value <> n.claim_value\n'
+ + ' AND (NOT (' + onMemberPageSql('n') + ' OR ' + onMemberPageSql('o') + ') OR o.source_markdown_slug = n.source_markdown_slug)\n'
+ ' AND (o.valid_from < n.valid_from OR (o.valid_from = n.valid_from AND o.id < n.id))\n'
+ ' WHERE NOT EXISTS (SELECT 1 FROM decide_proposals p WHERE p.source_id = $1\n'
+ ' AND LEAST(p.new_fact_id, p.old_fact_id) = LEAST(n.id, o.id) AND GREATEST(p.new_fact_id, p.old_fact_id) = GREATEST(n.id, o.id))\n'
diff --git a/test/claim-conflicts.test.ts b/test/claim-conflicts.test.ts
index 2de01d0dbb..ac6d1fdb45 100644
--- a/test/claim-conflicts.test.ts
+++ b/test/claim-conflicts.test.ts
@@ -149,6 +149,19 @@ for (const kind of testBackends()) {
rmSync(home, { recursive: true, force: true });
});
+ test('member facts pair only on their own member page, never across member pages or with a fact elsewhere', async () => {
+ const src = await source();
+ const own = { metric: 'mrr', visibility: 'private' as const };
+ const onPage = async (f: F) => { const id = await fact(src, f); await engine.executeRaw('UPDATE facts SET row_num = id + 100000 WHERE id = $1', [id]); return id; };
+ await onPage({ ...own, value: 40000, at: '2026-10-02T09:00:00Z', provenancePage: 'memory/members/alice-example' });
+ await onPage({ ...own, value: 41000, at: '2026-10-03T09:00:00Z', provenancePage: 'memory/members/bob-example' });
+ await onPage({ ...own, value: 42000, at: '2026-10-04T09:00:00Z', provenancePage: 'companies/acme-example' });
+ const aliceOld = await onPage({ ...own, metric: 'arr', value: 1, at: '2026-10-05T09:00:00Z', provenancePage: 'memory/members/alice-example' });
+ const aliceNew = await onPage({ ...own, metric: 'arr', value: 2, at: '2026-10-06T09:00:00Z', provenancePage: 'memory/members/alice-example' });
+ const run = await runClaimConflicts(engine, { sourceIds: [src], dryRun: true });
+ expect(pairKeys(run.sources[0]!.pairs)).toEqual(pairKeys([{ new_fact_id: aliceNew, old_fact_id: aliceOld }]));
+ });
+
test('the bucket SQL agrees with claimBucket on this engine', async () => {
const cases: Array<[string | null, string]> = [[null, '2026-03-20T23:30:00Z'], ['monthly', '2026-03-02T00:00:00Z'], ['quarterly', '2026-03-30T00:00:00Z'],
['annual', '2026-12-31T12:00:00Z'], ['weekly', '2025-12-29T00:00:00Z'], ['weekly', '2027-01-03T00:00:00Z'], ['per launch', '2026-05-05T05:00:00Z']];