Repository navigation
fix(server): migration 95 finishes on large databases - #37995
juliusmarminge wants to merge 1 commit into
Conversation
Migration 95 flagged inline work output with one bulk UPDATE. SQLite journals every row a statement rewrites, payload included, and temp_store = MEMORY keeps that journal in RAM, so peak memory grew about 1 GB per GB of matching payloads and large databases never finished starting. Page through matching rows by rowid and update them one row per statement, so each statement journal holds a single row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Migration 95 now backfills the same inline-output flags using paged identifiers and single-row updates to reduce memory pressure on large databases. Existing migration transaction boundaries and product behavior remain unchanged. You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
The automated pipeline stopped on this pull request and will not merge it: the fix is written and reviewed, but proving it needs something no worker has:
It stays open for a person to finish or close. |
Migration 95 set inline_work_output with one bulk UPDATE inside the migration transaction. SQLite keeps a copy (the statement journal) of every row a statement rewrites, payload overflow pages included, until the statement ends, and Sqlite.ts sets temp_store = MEMORY, so that copy sat in RAM and peak memory grew about 1 GB per GB of matching payloads. The migration now pages through matching rows by rowid (keyset, 500 per page; same pattern as migration 081) and updates one row per statement, so each journal holds a single row. The WHERE condition, the result and the single migration transaction are unchanged; temp_store is untouched. A small node:sqlite test confirmed the cause: a 510 MB rewrite peaked at 569 MB with temp_store=MEMORY and 53 MB with FILE; UPDATE OR FAIL did not avoid the journal. Measured the way triage did, on Linux: a statev2.sqlite built to migration 94 with the server's own runMigrations, filled with 150 KB dynamic_tool rows (N containing htmlRender, N not), the real server started (
node src/bin.ts serve --base-dir <copy>), VmHWM sampled every second until /.well-known/t3/environment returned 200; fresh copy per run, sync before each, before and after alternated. 2 GB matched (13,400 rows): BEFORE peak RSS 2503, 2480, 2512, 2497, 2509 MB (18-59 s, median 41 s of the 3 alternated runs); AFTER 595, 576, 494, 585, 537, 539 MB (20-54 s, median 23 s of the 3 alternated runs). 4 GB matched (26,800 rows): AFTER 511 MB, 90 s; before not rerun here (triage measured 4483 MB, 93 s on main). Every run reached migration 97 with exactly the matching rows flagged. The 21 GB case was not run, but peak memory stayed flat from 2 GB to 4 GB. No new regex or parser.Fixes #37961
Reproduction on main
Commit 0ff1495 (origin/main). Built a fresh statev2.sqlite at migration 94 with the server's own runMigrations({toMigrationInclusive: 94}). Filled copies with synthetic dynamic_tool rows of about 150 KB each (the reporter's average row size): N rows whose payload contains htmlRender (matched by migration 95's WHERE) plus N that do not. Started the real server on each copy (
node apps/server/src/bin.ts serve --base-dir <copy>), sampled /proc//status VmHWM every second, and stopped when /.well-known/t3/environment returned 200 (migrations then recorded through 97). Peak RSS: empty DB 551 MB (6 s). 1 GB matched (6,700 rows): 1457, 1499, 1510 MB (median 1499), 18-23 s. 2 GB matched (13,400 rows): 2483, 2485, 2499 MB (median 2485), 32-48 s. 4 GB matched (26,800 rows): 4483 MB, 93 s. Control on the same 4 GB DB with onlyPRAGMA temp_store = MEMORYchanged to FILE in Sqlite.ts (temporary, reverted): peak 486 MB, 99 s. So peak memory grows about 1 GB per GB of payload rewritten, entirely from the in-memory temp store. Extrapolated to the reporter's 21 GB rewrite that is about 21 GB of extra RAM, consistent with their 15 GB footprint and stall on a 36 GB Mac. The full 21 GB case was not run (this VM has 15 GB RAM), so the final stall itself was not observed. Driver scripts: https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/8357baac1d07e609/seed94.ts https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/d57fe59040998eb1/fill.sh https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/eead16d544dd71e7/run.shEvidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/persistence/Migrations/095_TurnItemInlineWorkOutput.test.ts src/persistence/Migrations.test.ts: 12 passed. Extended the 095 test with 1001 more matching rows; checked that it fails when paging is broken (always breaking after the first page), then restored. vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (2 files) all pass. Before/after real-server measurements: see summary.
Not in this change
Who did the work
Run by the t3code factory in T3 Code.