From c938bdfee41e75181ee1ede3f46f43577e6ecfea Mon Sep 17 00:00:00 2001 From: Devin Foley Date: Mon, 16 Nov 2026 13:07:15 -0800 Subject: [PATCH] perf(ci): stop printing Postgres TRUNCATE notices in server test shards (#21903) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The server test suites run on 12 CI shards. Each suite gets a disposable Postgres database from `packages/db`. > - Many suites reset their state with `TRUNCATE ... CASCADE`. Postgres sends one `NOTICE` for each cascaded table. > - postgres.js prints each notice with `console.log` when a client sets no `onnotice`. Vitest then carries each line from the worker to the reporter. > - On the slowest shard of a recent run, about 600k of the 760k log lines were these notices. The noise makes the shard slower and the log hard to read. > - This pull request sets `client_min_messages = warning` on each disposable test database. Every client that a suite opens then gets no notices. > - The benefit is a shorter slowest server shard and a much smaller log. ## Linked Issues or Issue Description Refs #21879 (a separate cause of the same slow shard: missing shard-duration weights). **What existing behavior does this improve?** Disposable test databases send every Postgres `NOTICE` to the test clients. The test logs print each notice. **Subsystem affected** Test database fixtures in `packages/db` (`test-embedded-postgres.ts` and `test-postgres-admin.ts`). This change touches only test infrastructure. **Current behavior** On PR #21872 (run [43858567594](https://github.com/paperclipai/paperclip/actions/runs/43858567594)), the longest check was `ci / General tests (server (10/12))` at 768s. The Vitest step took 722s of that. The other server shards took 597–729s. The shard log had 760k lines. About 600k lines were `truncate cascades to table "…"` notices (about 77k notice objects): | suite | notices | |---|---| | heartbeat/workspace-preparation.test.ts | 19,089 | | agent-timer-deadlines.test.ts | 16,445 | | idle-incoming-wake.test.ts | 13,846 | | public-mcp/events-work.test.ts | 13,156 | | execution-control-work.test.ts | 4,485 | | 6 more suites | about 10k | About 20 suites already stop the notices one session at a time (`SET client_min_messages = warning` or `onnotice = () => {}`). **Proposed behavior** The fixture sets `client_min_messages = warning` on the database itself. It does this for the embedded-cluster path and for the `PAPERCLIP_TEST_POSTGRES_ADMIN_URL` path. Warnings and errors still show. A suite that needs notices can lower the level for its own session. **Reason and benefit** The notice-heavy suites ran 15–50% over their manifest weights in this run (for example, workspace-preparation took 193s against a weight of 173s, and idle-incoming-wake took 40s against 26s). Other suites were near their weights. Estimate: about 0.5–1 min less on the slowest server shard. The log on that shard goes from about 760k lines to about 160k lines. If #21879 also merges, the server lane's critical path should go from about 12.8 min to about 10–11 min. **Breaking changes** None. Only disposable test databases change. ## What Changed - `packages/db/src/test-postgres-admin.ts`: add `QUIET_TEST_DATABASE_SQL`. Run it on each new database on the admin-URL path. - `packages/db/src/test-embedded-postgres.ts`: run the same statement on the `paperclip` database at each embedded start. It runs on each start, not only when the template is built. Thus a template that was cached before this change also gives a quiet database, and the template key stays the same. - `packages/db/src/test-postgres-admin.test.ts`: new test for the admin-URL path. - `packages/db/src/test-embedded-postgres.test.ts`: new tests for the embedded template path and the fresh path. - Each new test opens a new client, checks `SHOW client_min_messages`, and runs a `TRUNCATE ... CASCADE`. The test fails if the client gets a notice. ## Verification - `cd packages/db && npx vitest run src/test-postgres-admin.test.ts src/test-embedded-postgres.test.ts`: 2 files, 25 tests pass. - I changed the statement to `RESET client_min_messages` and ran the new tests again. All 3 new tests failed. Then I restored the statement. - `cd packages/db && npx tsc --noEmit -p .`: no errors. - To measure the time savings, compare the server shard timings of this PR's CI run with run 43858567594. ## Risks - Low risk. The change affects only disposable test databases. Production databases do not use these fixtures. - A test that expects to receive a `NOTICE` on a new client would now not get it. Such a test can set `client_min_messages = notice` for its session. No current suite depends on notices: the full CI run on this PR passed. - The time savings is an estimate. The shard planner and other suites can change the slowest shard. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) by Anthropic, used through Claude Code as a Paperclip agent with tool use (shell, file edits, GitHub CLI, CI log inspection). Standard reasoning mode. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../db/src/test-embedded-postgres.test.ts | 25 +++++++++++++++++++ packages/db/src/test-embedded-postgres.ts | 15 ++++++++++- packages/db/src/test-postgres-admin.test.ts | 15 +++++++++++ packages/db/src/test-postgres-admin.ts | 4 +++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/packages/db/src/test-embedded-postgres.test.ts b/packages/db/src/test-embedded-postgres.test.ts index 84856638701..5a7ea81a1e7 100644 --- a/packages/db/src/test-embedded-postgres.test.ts +++ b/packages/db/src/test-embedded-postgres.test.ts @@ -412,6 +412,31 @@ describeWithPostgres("startEmbeddedPostgresTestDatabase template path", () => { } }); + it.each([ + { mode: "template", setting: undefined }, + { mode: "fresh", setting: "0" }, + ])("hides NOTICE messages from new clients on the $mode path", { timeout: EMBEDDED_POSTGRES_TEST_TIMEOUT_MS }, async ({ mode, setting }) => { + if (setting === undefined) delete process.env.PAPERCLIP_TEST_POSTGRES_TEMPLATE; + else process.env.PAPERCLIP_TEST_POSTGRES_TEMPLATE = setting; + const database = await startEmbeddedPostgresTestDatabase("paperclip-quiet-notices-"); + try { + expect(lastStartMode()).toBe(mode); + const notices: unknown[] = []; + const sql = postgres(database.connectionString, { max: 1, onnotice: (notice) => notices.push(notice) }); + try { + expect((await sql`show client_min_messages`)[0]?.client_min_messages).toBe("warning"); + await sql`create table quiet_parent (id int primary key)`; + await sql`create table quiet_child (parent_id int references quiet_parent (id))`; + await sql`truncate quiet_parent cascade`; + expect(notices).toEqual([]); + } finally { + await sql.end(); + } + } finally { + await database.cleanup(); + } + }); + describeOnPosix("cache root safety", () => { it("uses fresh clusters when the cache root is not a private directory of this user", { timeout: EMBEDDED_POSTGRES_TEST_TIMEOUT_MS }, async () => { delete process.env.PAPERCLIP_TEST_POSTGRES_TEMPLATE; diff --git a/packages/db/src/test-embedded-postgres.ts b/packages/db/src/test-embedded-postgres.ts index c2a4b4fa984..0e2488523c6 100644 --- a/packages/db/src/test-embedded-postgres.ts +++ b/packages/db/src/test-embedded-postgres.ts @@ -15,7 +15,13 @@ import { import { prepareEmbeddedPostgresNativeRuntime } from "./embedded-postgres-native.js"; import { loadWithoutEmbeddedPostgresExitHooks } from "./embedded-postgres-lifecycle.js"; import { ownTestPostgres, TestPostgresShutdownError, type TestPostgresInstance } from "./test-postgres-owner.js"; -import { checkTestPostgresAdmin, startTestPostgresDatabase, testPostgresAdminUrl } from "./test-postgres-admin.js"; +import postgres from "postgres"; +import { + checkTestPostgresAdmin, + QUIET_TEST_DATABASE_SQL, + startTestPostgresDatabase, + testPostgresAdminUrl, +} from "./test-postgres-admin.js"; // Time budget (ms) for a vitest test in the embedded-Postgres cost class: a // test that starts an embedded Postgres cluster and runs migrations. Measured @@ -156,6 +162,12 @@ async function createEmbeddedPostgresTestInstanceAt(dataDir: string) { return { dataDir, port, instance, getRecentLogs: () => logBuffer.getRecentLogs() }; } +async function quietTestDatabase(adminUrl: string, databaseName: string): Promise { + const sql = postgres(adminUrl, { max: 1, onnotice() {} }); + try { await sql.unsafe(QUIET_TEST_DATABASE_SQL(databaseName)); } + finally { await sql.end({ timeout: 1 }); } +} + function adminConnectionStringFor(port: number): string { return `postgres://${EMBEDDED_POSTGRES_USER}:${EMBEDDED_POSTGRES_PASSWORD}@127.0.0.1:${port}/postgres`; } @@ -667,6 +679,7 @@ export async function startEmbeddedPostgresTestDatabase( // Both calls are no-ops on a template copy and keep the returned database // identical to the fresh path even if the template were ever stale. await ensurePostgresDatabase(adminConnectionStringFor(port), "paperclip"); + await quietTestDatabase(adminConnectionStringFor(port), "paperclip"); const connectionString = databaseConnectionStringFor(port); await applyPendingMigrations(connectionString); diff --git a/packages/db/src/test-postgres-admin.test.ts b/packages/db/src/test-postgres-admin.test.ts index 7498a4a467c..2b7b887a77a 100644 --- a/packages/db/src/test-postgres-admin.test.ts +++ b/packages/db/src/test-postgres-admin.test.ts @@ -1,4 +1,5 @@ import { randomUUID } from "node:crypto"; +import postgres from "postgres"; import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; import { createDb } from "./client.js"; import { @@ -83,4 +84,18 @@ describe.skipIf(!support.supported)("shared PostgreSQL fixtures", () => { } }, 90_000); + it("hides NOTICE messages from new clients of a disposable database", async () => { + __setEmbeddedPostgresCtorProviderForTests(async () => { throw new Error("Must not start another PostgreSQL server"); }); + const database = await startEmbeddedPostgresTestDatabase("ignored-"); + databases.push(database); + const notices: unknown[] = []; + const sql = postgres(database.connectionString, { max: 1, onnotice: (notice) => notices.push(notice) }); + try { + expect((await sql`SHOW client_min_messages`)[0]?.client_min_messages).toBe("warning"); + await sql`CREATE TABLE quiet_parent (id integer PRIMARY KEY)`; + await sql`CREATE TABLE quiet_child (parent_id integer REFERENCES quiet_parent (id))`; + await sql`TRUNCATE quiet_parent CASCADE`; + expect(notices).toEqual([]); + } finally { await sql.end(); } + }, 90_000); }); diff --git a/packages/db/src/test-postgres-admin.ts b/packages/db/src/test-postgres-admin.ts index a76848fcc05..95e91a447ab 100644 --- a/packages/db/src/test-postgres-admin.ts +++ b/packages/db/src/test-postgres-admin.ts @@ -2,6 +2,9 @@ import { randomUUID } from "node:crypto"; import postgres from "postgres"; import { applyPendingMigrations, closeRegisteredClients } from "./client.js"; +export const QUIET_TEST_DATABASE_SQL = (databaseName: string) => + `ALTER DATABASE "${databaseName}" SET client_min_messages = warning`; + export function testPostgresAdminUrl(): string | undefined { const value = process.env.PAPERCLIP_TEST_POSTGRES_ADMIN_URL?.trim(); if (!value) return undefined; @@ -41,6 +44,7 @@ export async function startTestPostgresDatabase(adminUrl: string): Promise<{ })(); try { await admin.unsafe(`CREATE DATABASE "${name}"${template ? ` TEMPLATE "${template}"` : ""}`); + await admin.unsafe(QUIET_TEST_DATABASE_SQL(name)); await applyPendingMigrations(connectionString); return { connectionString, cleanup }; } catch (error) {