Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(facts): a managed brain skips multi-message email threads instead of writing conversation facts without a receipt
time-attack1db499b5edb4
diff --git a/TODOS.md b/TODOS.mdindex 954b1abb5a..28af5e6f7e 100644--- a/TODOS.md+++ b/TODOS.md@@ -1,5 +1,9 @@# TODOS+## Fix wave 9 follow-ups (filed 2026-10-05, fix wave 9)++- [ ] **P2 — Receipted publication for managed conversation facts.** **What:** `extract-conversation-facts` replaces a page's derived fact batch through `replaceDerivedFactsForPage` (`src/core/persistence/derived-facts.ts`), a coordinated transaction with no persistence request. On a managed brain a multi-message email thread is therefore skipped without writing and retried every run (`src/core/facts/conversation-skip.ts`), as are the single-email and prose outcomes; `test/helpers/managed-connector-job-contract.ts` case `extract_conversation_facts_thread` pins it. **Fix:** admit a persistence request for the derived batch (delete-by-prefix plus insert, page revision as the CAS) in the same transaction, so the write carries a receipt; then drop the managed gate and record the single-email/prose outcomes durably there too. **Effort:** M. **Priority:** P2.+## Contributor audit wave follow-ups (filed 2026-10-05, GBRA-40)### delta (owner: GBRA-40 (delta follow-ups))diff --git a/src/core/facts/conversation-skip.ts b/src/core/facts/conversation-skip.tsindex be21af0c8d..de60c996a5 100644--- a/src/core/facts/conversation-skip.ts+++ b/src/core/facts/conversation-skip.ts@@ -16,6 +16,10 @@* On a managed brain the single-email and prose outcomes are not durable:* recording them would turn a page that wrote nothing into a derived-facts* write without a persistence receipt, so those pages stay retryable there.+ * A multi-message email thread on a managed brain is skipped the same way:+ * replacing a page's conversation facts has no receipted publication path+ * yet, so it writes nothing and is retried (TODOS.md, managed conversation+ * facts).*/import { looksLikeMeetingNotes } from '../conversation-parser/builtins.ts';import { deriveDateContext } from '../conversation-parser/parse.ts';@@ -48,6 +52,13 @@ export function conversationSkip(durable: true,};}+ if (opts.managed && messages.length > 1 && parse.matched_pattern_id === 'email-thread-heading') {+ return {+ reason: `an email thread in this ${page.type} page`,+ message: `an email thread in this ${page.type} page; managed brains do not extract email-thread conversation facts yet (no receipted publication path); skipped`,+ durable: false,+ };+ }let reason: string | null = null;if (messages.length === 1 && parse.matched_pattern_id === 'email-thread-heading') {reason = `a single email message in this ${page.type} page, not a conversation`;diff --git a/test/helpers/managed-connector-job-contract.ts b/test/helpers/managed-connector-job-contract.tsindex 71f60e1ccc..a45b481199 100644--- a/test/helpers/managed-connector-job-contract.ts+++ b/test/helpers/managed-connector-job-contract.ts@@ -69,6 +69,7 @@ export const contractCases = ['cycle_extract_loops_race','cycle_extract_facts','extract_conversation_facts',+ 'extract_conversation_facts_thread','facts_absorb','atom_drain_opted_out','atom_drain_default_on',@@ -153,6 +154,8 @@ const CHAT_MODEL = 'anthropic:claude-sonnet-4-6';const FAKE_ENV = { ANTHROPIC_API_KEY: 'sk-ant-contract-fake', OPENAI_API_KEY: 'sk-contract-fake', VOYAGE_API_KEY: undefined };const THREAD_ID = '17aa00000000c001';const MESSAGE_ID = '18c2f4a9b3d20001';+const REPLY_ID = '18c2f4a9b3d20002';+const REPLY_BODY = 'Sure, I will send the quarterly plan on Thursday with the finance appendix attached to the first draft.';const EMAIL_BODY = ['Hi, can you send me the quarterly plan by Friday? I will review it on Monday.','',@@ -442,9 +445,12 @@ async function connectorSource(brain: ContractBrain): Promise<CaseState> {}/** The managed Gmail sweep with the autopilot sync defaults (noExtract: true, as the sync handler sets it). */-async function gmailSweep(state: CaseState) {+async function gmailSweep(state: CaseState, opts: { reply?: boolean } = {}) {const cfg = parseGoogleSourceConfig({ ...googleConfig, g_services: 'gmail', g_history_days: 7 }, state.dir);const sent = Date.now() - 3 * 3600_000;+ const reply = opts.reply ? [{ id: REPLY_ID, threadId: THREAD_ID, labelIds: ['SENT'], internalDate: String(sent + 3600_000),+ payload: { mimeType: 'text/plain', headers: [{ name: 'From', value: `Owner Example <${cfg.account}>` }, { name: 'To', value: 'Alice Example <[email protected]>' },+ { name: 'Subject', value: 'Re: Quarterly plan' }], body: { data: b64url(REPLY_BODY) } } }] : [];let listed = false;const fetcher = async (url: string) => {const u = new URL(url);@@ -459,7 +465,7 @@ async function gmailSweep(state: CaseState) {if (/\/users\/me\/threads\/[^/]+$/.test(u.pathname)) {return json({ id: THREAD_ID, messages: [{ id: MESSAGE_ID, threadId: THREAD_ID, labelIds: ['INBOX'], internalDate: String(sent),payload: { mimeType: 'text/plain', headers: [{ name: 'From', value: 'Alice Example <[email protected]>' }, { name: 'To', value: cfg.account },- { name: 'Subject', value: 'Quarterly plan' }], body: { data: b64url(EMAIL_BODY) } } }] });+ { name: 'Subject', value: 'Quarterly plan' }], body: { data: b64url(EMAIL_BODY) } } }, ...reply] });}return json({ error: { message: `unexpected fixture route ${u.pathname}` } }, 400);};@@ -609,6 +615,18 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {requireCompleted([job]);},+ /**+ * #5025: a multi-message Gmail thread parses into turns. Replacing a page's+ * conversation facts has no persistence request, so on a managed brain the+ * page is skipped without writing and stays retryable.+ */+ async extract_conversation_facts_thread(state) {+ await gmailSweep(state, { reply: true });+ const [job] = await runJobs(state.brain.engine, [{ name: 'extract-conversation-facts', data: { sourceId: state.sourceId } }]);+ requireCompleted([job]);+ expect((await changesSince(state)).filter(c => c.tbl === 'facts')).toEqual([]);+ },+async facts_absorb(state) {await gmailSweep(state);const { engine } = state.brain;@@ -805,7 +823,7 @@ const cases: Record<ContractCase, (state: CaseState) => Promise<void>> = {};const ATOM_CASES: ReadonlySet<ContractCase> = new Set(['atom_drain_opted_out', 'atom_drain_default_on', 'atom_dispatch']);-const FACTS_CASES: ReadonlySet<ContractCase> = new Set(['cycle_extract_facts', 'extract_conversation_facts', 'facts_absorb']);+const FACTS_CASES: ReadonlySet<ContractCase> = new Set(['cycle_extract_facts', 'extract_conversation_facts', 'extract_conversation_facts_thread', 'facts_absorb']);async function runCase(brain: ContractBrain, id: ContractCase): Promise<void> {const { model, dimensions } = brain.embedding;