Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(e2e): count the consumer's no-op embedding settle pass as a scan in the #6007 statement budget
garrytan65861da09467
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex acc70cff10..d1c14c94a1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,7 @@ identifiers and attribution are available in the pre-removal Git revision- **Docs**: the v0.60.218.0 fact-fence row in `src/core/behavior-change-notice.ts` (wording only) and the `fence_unrenderable` entry in `docs/guides/write-refusals.md` name the unmanaged path.- **Regression test**: `test/fact-fence-adoption-exits.test.ts` covers an unmanaged brain (PGLite and Postgres): a leftover world cell plus a private legacy fact with the same claim and source keeps the fact private in the file and the database after `extract_facts`. It fails on the build before v0.60.218.0 and passes now.+- **Flake fix**: the #6007 put_page statement-budget e2e test could count 26 or 27 statements against the preparation budget of 25 on a measured write. The consumer's idle no-op embedding settle pass runs two statements on its own connection (the embedding config read and its effect probe). They normally land before the claim commit; when one lands after it, the classifier counted it as preparation. Both now count as a consumer scan, and only when the probe follows the read on that connection, because write paths share the config read. Budgets are unchanged. A synthetic-trace test fails before the change and passes after.## [0.60.234.0] - 2026-10-15diff --git a/test/e2e/persistence-statement-budget.test.ts b/test/e2e/persistence-statement-budget.test.tsindex d60f808005..b41d5e8445 100644--- a/test/e2e/persistence-statement-budget.test.ts+++ b/test/e2e/persistence-statement-budget.test.ts@@ -10,7 +10,9 @@* Phases come from the transaction each statement runs in (begin..commit on* one connection, labelled by its signature statement) and, for statements* outside a transaction, from known consumer-scan and effect statements or- * the statement's position between the transactions.+ * the statement's position between the transactions. Consumer passes run on+ * their own connections concurrently with the write, so one that lands after+ * the claim commit would otherwise count as preparation.*/import { describe, expect, test } from 'bun:test';import { mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';@@ -53,7 +55,14 @@ const SCAN = [/FROM persistence_effects e JOIN persistence_worktrees w ON w\.id=e\.worktree_id WHERE e\.recovery IS NOT NULL/,/FROM persistence_topology_changes c/, /FROM persistence_worktree_refreshes f JOIN/, /^WITH expired AS/, /page_projection_jobs/,/^WITH purged AS \( DELETE FROM persistence_consumers/,+ /^SELECT 1 FROM persistence_effects e WHERE e\.id>\$1::bigint AND e\.kind='embedding' AND e\.state='queued' AND e\.attempts=0/,];+/**+ * The consumer's idle no-op embedding settle pass (embedding-noop-settle.ts) reads the embedding write target, then+ * runs the probe above on the same connection, concurrently with the measured write. Write paths share that config+ * read, so it is a scan only when the probe follows it on its connection.+ */+const SETTLE_TARGET_READ = /^SELECT key,value FROM config WHERE key IN \('search_embedding_column','embedding_columns','embedding_model'/;const statementKinds = new Set(['execute', 'simple']);const flat = (sql: string) => sql.replace(/\s+/g, ' ').trim();@@ -74,6 +83,8 @@ function classify(records: TraceRecord[]) {}}for (const group of open.values()) groups.push({ records: group, begin: group[0]!.t, end: group[group.length - 1]!.t });+ const settleReads = new Set(standalone.filter((record, i) => SETTLE_TARGET_READ.test(flat(record.sql))+ && SCAN.some(pattern => pattern.test(flat(standalone.slice(i + 1).find(next => next.conn === record.conn)?.sql ?? '')))));const labelled = groups.map(group => {const text = group.records.map(r => flat(r.sql)).join('\n');let phase: Phase = 'other';@@ -98,7 +109,7 @@ function classify(records: TraceRecord[]) {const publicationEnd = anchor('publication', 'end') ?? Infinity;const phaseOf = (record: TraceRecord): Phase => {const text = flat(record.sql);- if (SCAN.some(pattern => pattern.test(text))) return 'consumer_scan';+ if (settleReads.has(record) || SCAN.some(pattern => pattern.test(text))) return 'consumer_scan';if (/^SELECT state,error_code,error_message,completed_at,updated_at,blocked_reason,outcome FROM persistence_requests/.test(text)) return 'wait_poll';if (/^UPDATE persistence_requests SET state='running'/.test(text) || /FOR UPDATE OF r SKIP LOCKED\) RETURNING/.test(text)) return 'claim';if (/persistence_effects/.test(text) && record.t > publicationEnd) return 'effects';@@ -126,6 +137,22 @@ function classify(records: TraceRecord[]) {return result;}+test('the consumer\'s no-op embedding settle pass landing after the claim commit is a consumer scan, not preparation', () => {+ const at = (t: number, conn: number, kind: string, sql: string): TraceRecord => ({ t, ms: 0, conn, kind, sql });+ const records = [+ at(1, 1, 'simple', 'begin'), at(2, 1, 'execute', 'INSERT INTO persistence_requests (id) VALUES ($1)'), at(3, 1, 'simple', 'commit'),+ at(10, 2, 'execute', "UPDATE persistence_requests SET state='running', execution_token=$2::uuid WHERE id=$1"),+ at(11, 3, 'simple', "SELECT key,value FROM config WHERE key IN ('search_embedding_column','embedding_columns','embedding_model','embedding_dimensions','contextual_retrieval.mode') ORDER BY key"),+ at(12, 4, 'execute', "SELECT config->>'slug_root_mode' AS mode FROM sources WHERE id = $1"),+ at(13, 3, 'execute', "SELECT 1 FROM persistence_effects e WHERE e.id>$1::bigint AND e.kind='embedding' AND e.state='queued'\n AND e.attempts=0 AND e.recovery IS NULL ORDER BY e.id LIMIT 1"),+ at(14, 4, 'simple', "SELECT key,value FROM config WHERE key IN ('search_embedding_column','embedding_columns','embedding_model','embedding_dimensions','contextual_retrieval.mode') ORDER BY key"),+ at(20, 5, 'simple', 'begin'), at(21, 5, 'execute', 'UPDATE persistence_requests SET publication_started=true WHERE id=$1'), at(22, 5, 'simple', 'commit'),+ ];+ const phases = classify(records);+ expect(phases.consumer_scan).toEqual({ statements: 2, describes: 0 });+ expect(phases.prepare).toEqual({ statements: 2, describes: 0 });+});+const d = hasDatabase() ? describe : describe.skip;d('#6007 put_page statement budget (Postgres)', () => {test('one remote put_page of a new 60 KB page stays within its per-phase statement budget', async () => {