Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(#6712 PR 4b): the folded pass stamp has its own statement budget inside the publication; the import keeps its 76/74
garrytanbb924af5d264
diff --git a/test/e2e/managed-import-statement-budget.test.ts b/test/e2e/managed-import-statement-budget.test.tsindex 70c8ec11fe..5056943f40 100644--- a/test/e2e/managed-import-statement-budget.test.ts+++ b/test/e2e/managed-import-statement-budget.test.ts@@ -12,7 +12,8 @@* one per 500 rows); the transaction stays within its budget; no statement text* runs per row or per code reference anywhere in the sync.* Fails when: a per-row statement enters the import, a chunked insert loses its- * batching, or the publication transaction grows past its budget.+ * batching, or the publication transaction grows past its budget (the folded pass stamp inside it has its own budget,+ * #6712 PR 4b).*/import { afterAll, describe, expect, test } from 'bun:test';import { mkdtempSync, rmSync } from 'node:fs';@@ -22,12 +23,22 @@ import { hasDatabase } from './helpers.ts';import { isolatedPersistencePostgres } from '../helpers/persistence-postgres.ts';import { disposePersistenceConsumer } from '../../src/core/persistence/service.ts';import { readSqlTrace, type StatementRecord } from '../helpers/statement-counter.ts';-import { byText, chunkOf, CHUNKED, PAGE_SLUG, prepareManagedImport, publicationOf } from '../helpers/managed-import-budget.ts';+import { byText, chunkOf, CHUNKED, PAGE_SLUG, prepareManagedImport, publicationOf, splitFoldBlock } from '../helpers/managed-import-budget.ts';import type { YcShapedPage } from '../helpers/yc-shaped-page.ts';import { withEnv } from '../helpers/with-env.ts';-/** About 10% over the measured publication transaction at 1x (#6712 L6 measured 67 on Postgres; 317 before code references were batched). */+/** About 10% over the import's own statements in the publication transaction at 1x (#6712 L6 measured 67 on Postgres; 317 before code references were batched); the folded stamp is budgeted apart. */const PUBLICATION_BUDGET = 74;+/**+ * #6712 PR 4b: the folded pass stamp, budgeted on its own inside the same transaction (about 10% over 17 measured on+ * Postgres). A writeback import publishes the source checkpoint here instead of as a separate checkpoint request, so these+ * statements replace that request's stamp, admission, claim and effect transactions (a net 46 fewer statements across the+ * PGLite run): the savepoint and its release (2); the sync lease check (1); the pass row read, the recovery and open-work+ * read, the request high-water mark and the open-at-stamp read (4); the source's last_commit and slug mode (1); the+ * fold proof (1) and its SET LOCAL jit = off (1); the checkpoint-blocker check (1); the proof's two page reads (2); the last_commit update, the pass+ * row write, the normalized-fences read and the checkpoint row write (4).+ */+const FOLD_BUDGET = 19;const PER_ROW_CEILING = 40;const SIZES = [0.5, 1, 2] as const;@@ -89,10 +100,15 @@ d('managed import statement budget (Postgres)', () => {test('the publication transaction stays within its budget at 1x', async () => {const { publication } = await measured(1);- const statements = publication.filter(record => record.kind === 'execute' || record.kind === 'simple');- expect(statements.length).toBeLessThanOrEqual(PUBLICATION_BUDGET);+ expect(splitFoldBlock(publication).imported.length).toBeLessThanOrEqual(PUBLICATION_BUDGET);}, 300_000);+ test('the folded pass stamp stays within its own budget at 1x', async () => {+ const { fold } = splitFoldBlock((await measured(1)).publication);+ expect(fold.length).toBeGreaterThan(0);+ expect(fold.length).toBeLessThanOrEqual(FOLD_BUDGET);+ }, 240_000);+test('no statement runs per row or per code reference anywhere in the import', async () => {for (const scale of SIZES) {const { records, page } = await measured(scale);diff --git a/test/helpers/managed-import-budget.ts b/test/helpers/managed-import-budget.tsindex cfad45c47b..896110d024 100644--- a/test/helpers/managed-import-budget.ts+++ b/test/helpers/managed-import-budget.ts@@ -73,6 +73,21 @@ export function publicationOf(records: StatementRecord[]): StatementRecord[] {throw new Error('no committed transaction inserted the page');}+/**+ * #6712 PR 4b: the publication split into the folded pass stamp (its savepoint through its first release or rollback, a+ * writeback import's checkpoint published inside the page's transaction) and the import's own statements around it. A+ * publication without the fold is all import.+ */+export function splitFoldBlock(publication: StatementRecord[]): { fold: StatementRecord[]; imported: StatementRecord[] } {+ const statements = publication.filter(isStatement);+ const texts = statements.map(record => flat(record.sql));+ const start = texts.indexOf('SAVEPOINT gbrain_pass_stamp_fold');+ if (start < 0) return { fold: [], imported: statements };+ const end = texts.findIndex((text, i) => i > start && /^(?:RELEASE|ROLLBACK TO) SAVEPOINT gbrain_pass_stamp_fold$/.test(text));+ if (end < 0) throw new Error('the folded stamp opened its savepoint and never released or rolled it back');+ return { fold: statements.slice(start, end + 1), imported: [...statements.slice(0, start), ...statements.slice(end + 1)] };+}+/** Statement counts by normalized text. */export function byText(records: StatementRecord[]): Map<string, number> {const counts = new Map<string, number>();diff --git a/test/managed-import-statement-budget.test.ts b/test/managed-import-statement-budget.test.tsindex 782ad2ab47..4daead6ae7 100644--- a/test/managed-import-statement-budget.test.ts+++ b/test/managed-import-statement-budget.test.ts@@ -12,7 +12,8 @@* references used to cost one addLink per edge, 100 at 1x).* Fails when: a per-row (or per-reference) statement enters the import, a* chunked insert loses its batching, or the publication transaction grows- * past its budget.+ * past its budget (the folded pass stamp inside it has its own budget,+ * #6712 PR 4b).* Seams: the PGLite statement counter (test/helpers/statement-counter.ts).* Postgres twin: test/e2e/managed-import-statement-budget.test.ts.*/@@ -24,12 +25,22 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';import { publicationStepTotals } from '../src/core/persistence/publication-timing.ts';import { countPgliteStatements, type StatementRecord } from './helpers/statement-counter.ts';-import { byText, chunkOf, CHUNKED, PAGE_SLUG, prepareManagedImport, publicationOf } from './helpers/managed-import-budget.ts';+import { byText, chunkOf, CHUNKED, PAGE_SLUG, prepareManagedImport, publicationOf, splitFoldBlock } from './helpers/managed-import-budget.ts';import type { YcShapedPage } from './helpers/yc-shaped-page.ts';import { withEnv } from './helpers/with-env.ts';-/** About 10% over the measured publication transaction at 1x (#6712 L6 measured 69 on PGLite; 416 before code references were batched). */+/** About 10% over the import's own statements in the publication transaction at 1x (#6712 L6 measured 69 on PGLite; 416 before code references were batched); the folded stamp is budgeted apart. */const PUBLICATION_BUDGET = 76;+/**+ * #6712 PR 4b: the folded pass stamp, budgeted on its own inside the same transaction (about 10% over 16 measured on+ * PGLite). A writeback import publishes the source checkpoint here instead of as a separate checkpoint request, so these+ * statements replace that request's stamp, admission, claim and effect transactions (a net 46 fewer statements across the+ * PGLite run): the savepoint and its release (2); the sync lease check (1); the pass row read, the recovery and open-work+ * read, the request high-water mark and the open-at-stamp read (4); the source's last_commit and slug mode (1); the+ * fold proof (1); the checkpoint-blocker check (1); the proof's two page reads (2); the last_commit update, the pass+ * row write, the normalized-fences read and the checkpoint row write (4).+ */+const FOLD_BUDGET = 18;/** No statement text may run this often in one import: far above any fixed statement, far below one per row or reference. */const PER_ROW_CEILING = 40;const SIZES = [0.5, 1, 2] as const;@@ -97,7 +108,13 @@ describe('managed import statement budget (PGLite)', () => {test('the publication transaction stays within its budget at 1x', async () => {const { publication } = await measured(1);- expect(publication.length).toBeLessThanOrEqual(PUBLICATION_BUDGET);+ expect(splitFoldBlock(publication).imported.length).toBeLessThanOrEqual(PUBLICATION_BUDGET);+ }, 240_000);++ test('the folded pass stamp stays within its own budget at 1x', async () => {+ const { fold } = splitFoldBlock((await measured(1)).publication);+ expect(fold.length).toBeGreaterThan(0);+ expect(fold.length).toBeLessThanOrEqual(FOLD_BUDGET);}, 240_000);test('no statement runs per row or per code reference anywhere in the import', async () => {