Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(large-pages): merge follow-ups with master v0.60.452.0 — keyed page-embedding lease upsert (#7442), per-pass transcripts and a fresh brain where #7043 dedups claims
garrytanad58bae820eb
diff --git a/src/core/page-embedding-lease.ts b/src/core/page-embedding-lease.tsindex 63c1c24f77..27e7f3de74 100644--- a/src/core/page-embedding-lease.ts+++ b/src/core/page-embedding-lease.ts@@ -87,7 +87,7 @@ export async function acquirePageEmbeddingLease(engine: BrainEngine, pageId: numconst take = async () => (await engine.executeRaw(`INSERT INTO gbrain_cycle_locks (id, holder_pid, holder_host, acquired_at, ttl_expires_at, last_refreshed_at, acquisition_token)VALUES ($1, $2, $3, now(), now() + make_interval(mins => $4::int), now(), $5::uuid)- ON CONFLICT (id) DO UPDATE SET holder_pid = EXCLUDED.holder_pid, holder_host = EXCLUDED.holder_host, acquired_at = now(),+ ON CONFLICT (id) DO UPDATE SET id = EXCLUDED.id, holder_pid = EXCLUDED.holder_pid, holder_host = EXCLUDED.holder_host, acquired_at = now(),ttl_expires_at = EXCLUDED.ttl_expires_at, last_refreshed_at = now(), acquisition_token = EXCLUDED.acquisition_tokenWHERE gbrain_cycle_locks.ttl_expires_at < now()RETURNING id`, [id, process.pid, hostname(), PAGE_EMBEDDING_LEASE_TTL_MINUTES, token])).length > 0;diff --git a/test/e2e/conversation-facts-incremental-grammar-choice-postgres.test.ts b/test/e2e/conversation-facts-incremental-grammar-choice-postgres.test.tsindex 2032aac77b..ad2b651500 100644--- a/test/e2e/conversation-facts-incremental-grammar-choice-postgres.test.ts+++ b/test/e2e/conversation-facts-incremental-grammar-choice-postgres.test.ts@@ -12,7 +12,8 @@ import { hasDatabase } from './helpers.ts';(hasDatabase() ? describe : describe.skip)('conversation facts incremental, grammar-choice [postgres]', () => {let brain: AppendBrain;- beforeAll(async () => { brain = await openAppendBrain('postgres'); }, 120_000);- afterAll(async () => { await brain.close(); }, 120_000);- defineConversationFactsGrammarChoiceCases({ getBrain: () => brain });+ let fresh: AppendBrain;+ beforeAll(async () => { brain = await openAppendBrain('postgres'); fresh = await openAppendBrain('postgres'); }, 120_000);+ afterAll(async () => { await brain.close(); await fresh.close(); }, 120_000);+ defineConversationFactsGrammarChoiceCases({ getBrain: () => brain, getFresh: () => fresh });});diff --git a/test/helpers/conversation-facts-invariant-cases.ts b/test/helpers/conversation-facts-invariant-cases.tsindex 5954fe49d5..06cd3ed45e 100644--- a/test/helpers/conversation-facts-invariant-cases.ts+++ b/test/helpers/conversation-facts-invariant-cases.ts@@ -265,7 +265,9 @@ export function defineConversationFactsHeldCases(opts: { getBrain: () => AppendBfor (const quoted of [1, 3]) {const slug = `notes/quoted-line-${randomUUID().slice(0, 8)}`;await caps(brain.engine, 'off');- await brain.seed(slug, chatPage('Was a chat', chatDays(4600, 100, 38)));+ // Each pass seeds its own transcript: a source never stores a claim twice (#7043), so a repeat of the first pass's+ // transcript would extract no new facts.+ await brain.seed(slug, chatPage('Was a chat', chatDays(4600, 100, 380 + quoted)));await extract(brain.engine, slug);const facts = (await factsOf(brain.engine, slug)).length;expect(facts).toBeGreaterThan(100);@@ -551,7 +553,7 @@ export function defineConversationFactsGrammarFlagCases(opts: { getBrain: () =>}/** How long an operator's format choice lasts: one page version, and a detected format after it streams from the head. */-export function defineConversationFactsGrammarChoiceCases(opts: { getBrain: () => AppendBrain }): void {+export function defineConversationFactsGrammarChoiceCases(opts: { getBrain: () => AppendBrain; getFresh: () => AppendBrain }): void {test('a choice holds only for the page version it was made for: after an append the chosen rows do not pin their format, so a page still undetected is held with every fact kept', async () => {const brain = opts.getBrain();const slug = `notes/choice-version-${randomUUID().slice(0, 8)}`;@@ -593,9 +595,14 @@ export function defineConversationFactsGrammarChoiceCases(opts: { getBrain: () =const run = await extract(brain.engine, slug);const after = await factsOf(brain.engine, slug);const freshSlug = `notes/choice-switch-fresh-${randomUUID().slice(0, 8)}`;- await brain.seed(freshSlug, chatPage('Constant title', body));- await extract(brain.engine, freshSlug);- const fresh = await factsOf(brain.engine, freshSlug);+ // The fresh extraction runs on its own brain: in this one the switched page's facts already state every claim, and a+ // source never stores a claim twice (#7043).+ const freshBrain = opts.getFresh();+ await caps(freshBrain.engine, 'off');+ for (const key of ['facts.extraction_model', 'facts.default_visibility']) await freshBrain.engine.setConfig(key, (await brain.engine.getConfig(key)) ?? '');+ await freshBrain.seed(freshSlug, chatPage('Constant title', body));+ await extract(freshBrain.engine, freshSlug);+ const fresh = await factsOf(freshBrain.engine, freshSlug);const shas = (facts: typeof after) => facts.map(f => f.key.split(':')[2]).sort();const forced = await extract(brain.engine, slug, { force: true });const rows = await derivations(brain.engine, slug);diff --git a/test/large-pages/conversation-facts-incremental-grammar-choice.test.ts b/test/large-pages/conversation-facts-incremental-grammar-choice.test.tsindex 2bdd4227b7..87ece5d731 100644--- a/test/large-pages/conversation-facts-incremental-grammar-choice.test.ts+++ b/test/large-pages/conversation-facts-incremental-grammar-choice.test.ts@@ -9,10 +9,11 @@ import { openAppendBrain, type AppendBrain } from '../helpers/append-brain.ts';import { defineConversationFactsGrammarChoiceCases } from '../helpers/conversation-facts-invariant-cases.ts';let brain: AppendBrain;+let fresh: AppendBrain;-beforeAll(async () => { brain = await openAppendBrain('pglite'); }, 120_000);-afterAll(async () => { await brain.close(); }, 120_000);+beforeAll(async () => { brain = await openAppendBrain('pglite'); fresh = await openAppendBrain('pglite'); }, 120_000);+afterAll(async () => { await brain.close(); await fresh.close(); }, 120_000);describe('conversation facts incremental, grammar-choice [pglite]', () => {- defineConversationFactsGrammarChoiceCases({ getBrain: () => brain });+ defineConversationFactsGrammarChoiceCases({ getBrain: () => brain, getFresh: () => fresh });});