Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(salience): exclude briefings/* from their own Brain Pulse (TIM-37) (#1202)

Richard Bakere78ad9ff9e2e
diff --git a/src/core/pglite-engine.ts b/src/core/pglite-engine.ts
index 257090a23e..e11eeb3fb2 100644
--- a/src/core/pglite-engine.ts
+++ b/src/core/pglite-engine.ts
@@ -5837,6 +5837,11 @@ export class PGLiteEngine implements BrainEngine {
params.push(escaped);
prefixCondition = `AND p.slug LIKE $${params.length} ESCAPE '\\'`;
}
+ // TIM-37: exclude briefing pages from their own Brain Pulse. See the
+ // matching block in postgres-engine.ts getRecentSalience() for context.
+ const excludeBriefings = !(slugPrefix && slugPrefix.startsWith('briefings'))
+ ? `AND p.slug NOT LIKE 'briefings/%'`
+ : '';
params.push(limit);
const limitParam = `$${params.length}`;
@@ -5872,6 +5877,7 @@ export class PGLiteEngine implements BrainEngine {
LEFT JOIN takes t ON t.page_id = p.id AND t.active = TRUE
WHERE GREATEST(p.updated_at, COALESCE(p.salience_touched_at, p.updated_at)) >= $1::timestamptz
${prefixCondition}
+ ${excludeBriefings}
GROUP BY p.id
ORDER BY score DESC
LIMIT ${limitParam}`,
diff --git a/src/core/postgres-engine.ts b/src/core/postgres-engine.ts
index 0e8f658f81..d3b3892937 100644
--- a/src/core/postgres-engine.ts
+++ b/src/core/postgres-engine.ts
@@ -6153,6 +6153,13 @@ export class PostgresEngine implements BrainEngine {
const prefixCondition = slugPrefix
? sql`AND p.slug LIKE ${slugPrefix.replace(/[\\%_]/g, (c) => '\\' + c) + '%'} ESCAPE '\\'`
: sql``;
+ // TIM-37: exclude briefing pages from their own Brain Pulse. The cron
+ // briefing writes to 90_Briefings/, gets re-ingested, and would otherwise
+ // top tomorrow's salience as pure self-reference. Suppress unless the
+ // caller explicitly asked for the briefings/ prefix.
+ const excludeBriefings = !(slugPrefix && slugPrefix.startsWith('briefings'))
+ ? sql`AND p.slug NOT LIKE 'briefings/%'`
+ : sql``;
// v0.29.1: third score term via buildRecencyComponentSql. Default
// 'flat' = v0.29.0 behavior (1 / (1 + days_old)). 'on' opts into the
// per-prefix decay map (concepts/ evergreen, daily/ aggressive, etc.).
@@ -6186,6 +6193,7 @@ export class PostgresEngine implements BrainEngine {
LEFT JOIN takes t ON t.page_id = p.id AND t.active = TRUE
WHERE GREATEST(p.updated_at, COALESCE(p.salience_touched_at, p.updated_at)) >= ${boundaryIso}::timestamptz
${prefixCondition}
+ ${excludeBriefings}
GROUP BY p.id
ORDER BY score DESC
LIMIT ${limit}
diff --git a/test/e2e/salience-pglite.test.ts b/test/e2e/salience-pglite.test.ts
index aa959031ee..98d46604ac 100644
--- a/test/e2e/salience-pglite.test.ts
+++ b/test/e2e/salience-pglite.test.ts
@@ -112,4 +112,27 @@ describe('v0.29 E2E — getRecentSalience (Garry test)', () => {
const rows = await engine.getRecentSalience({ days: 7, slugPrefix: 'nope/does-not-exist/' });
expect(rows).toEqual([]);
});
+
+ // TIM-37: the daily briefing writes to the vault and re-ingests as
+ // `briefings/<date>`. Without this filter the briefing itself would top
+ // every subsequent Brain Pulse — self-reference with no signal.
+ describe('TIM-37 — briefings excluded from their own Brain Pulse', () => {
+ test('default query hides briefings/* slugs', async () => {
+ await engine.putPage('briefings/2026-05-19', {
+ type: 'note',
+ title: 'Daily Briefing — 2026-05-19',
+ compiled_truth: 'Auto-generated cron briefing.',
+ });
+ const rows = await engine.getRecentSalience({ days: 7, limit: 50 });
+ expect(rows.some(r => r.slug.startsWith('briefings/'))).toBe(false);
+ });
+
+ test('explicit slugPrefix=briefings/ still returns them', async () => {
+ const rows = await engine.getRecentSalience({ days: 7, slugPrefix: 'briefings/' });
+ expect(rows.length).toBeGreaterThan(0);
+ for (const r of rows) {
+ expect(r.slug.startsWith('briefings/')).toBe(true);
+ }
+ });
+ });
});