Public: anyone can read this; the crew can change it.
The database keeps what it needs: deploy_pull, event and machine_sample have… #11974
Three of the four parts are built. I could not verify the "done when" targets, and the index diet is a tool with no drops yet. All of it was tested on fresh databases only; I had no production copy.
stopped parked by the crew deploy 5812900
2 earlier comments
Three of the four parts are built. I could not verify the "done when" targets, and the index diet is a tool with no drops yet. All of it was tested on fresh databases only; I had no production copy.
What changed
- Retention rules (
src/core/retention.ts). Each of the three tables has one rule, andretention, a new maintenance duty, runs a batch of it every minute. A batch deletes in 500-row transactions, starts none after 40 ms, and stops at 20,000 rows. Where each walk stopped is kept in a newretention_cursortable.deploy_pullkeeps rows of deploys from the last 30 days and of the deploy each production app serves now. It drops rows of older deploys and of runs that no longer exist.eventnever drops audit kinds (account.,token.,repo.and similar). It drops machine chatter (usage.delta,run.shardand a few more) after 30 days and every other kind after 365. The file header says which reader needs what age.machine_samplekeeps raw samples for 48 h, 5-minute rows for 30 days, then the top-of-hour row for 90 days.ring.recordnow takes its raw window and hourly cutoff from the settings.
- Settings. The days are seven new capacity settings (
retention.*,size.growth_mb_per_day), so an admin can override them on the capacity page. - Rebuild from git.
carriedOrRebuildre-walks git when a deploy's rows are gone. The run page andGET …/runs/{id}use it. A test drops a deploy's rows and checks the rebuilt pulls match. - Space back. Freed pages go back with
PRAGMA incremental_vacuumin 200-page steps (about 800 KiB), never a blockingVACUUMon the live handle, which would hold the write lock for the whole rewrite. Every database created from now on isauto_vacuum=INCREMENTAL. - Size on /system (
src/system/db_size.ts). The new "The database" section on /system, a short block on the terminal System screen anddatabaseon the MCPsystemtool show the file size, free space, growth per day, and the ten heaviest tables and indexes. Vitals raises a need when the file passes 2 GiB or grows faster thansize.growth_mb_per_day(default 200 MB). The figures are estimates, because Bun's SQLite has nodbstat. - Migration. One new migration adds
retention_cursor,db_size_day(one size reading a day) andwebhook_delivery(event_id). Without that index every event deleted would scan all webhook deliveries through the cascade. - Index diet.
scripts/sql-tap.tsrecords the statements a test run prepares, andscripts/index-diet.tslists every index with the statements whose query plan uses it. It drops nothing. - Docs.
docs/features/retention.mdcovers the rules, who reads what age, and the offline conversion.
What I chose not to do, or could not verify
- Production file stays at
auto_vacuum=none. Incremental vacuum does nothing there until one offline conversion byVACUUM INTOat a hand-over. The file stays about as big until that is done; /system says which mode it is in. - No index dropped. The tap/diet scripts are untested beyond two test files, and nothing here was run against a production copy, so I have no list or bytes-returned figure. I did not want to drop indexes the suite never prepares. A run over the full suite plus a production copy produces the list to review.
machine_sampleshould shrink little. Production's 2.0M rows already fit the old 24 h/30 d rule, because there are about 140 targets. My rule adds an hourly tail (90 days), so this table may grow slightly.- Event chatter list. The kinds I treat as chatter are my reading of the code, not measured from production. Check them against the real kind counts before relying on the 2.4M-row reduction.
- Old deploys in the terminal. The terminal deploys list still reads
deploy_pulldirectly, so deploys older than 30 days show no "carries" there. - Not run here. The "under 2 GiB, same answers" and "each batch under 50 ms" checks need a production copy. A test bounds one batch to the 40 ms allowance plus one 500-row chunk on a small database.
Existing tests changed
test/capacity-timing.test.ts: the statement ceiling goes from 69 to 100, because the page has seven more settings.test/vitals.test.ts: the query count goes from 10 to 11 for the growth read.test/system-parts.test.ts: the section list gains "The database".scripts/header-width-allow.json: I wrapped the header comment intest/vitals.test.ts, so it is off the allow list.
Test status. bun scripts/gate.ts, tsc and design-lint are clean, and the tests I ran for these areas pass, except as follows. timers-named (src/runs/log.ts) fails the same way on main. unused-exports still fails on two unused exports, mergedPullClosingScan and bufferRunLogs, neither from my change; I did not re-check them on main. I did not run the full suite.
To try it. Open /system and read "The database". Open a production deploy's run page older than 30 days (carries is unchanged). To see the index list, run FORGE_SQL_TAP=$TMPDIR/sql.jsonl bun test --preload ./scripts/sql-tap.ts <files>, then bun scripts/index-diet.ts $TMPDIR/sql.jsonl [forge.db copy].
🤖 Generated with Claude Code
I fixed three of the seven failing tests and the cause of a fourth that ought to have failed too (/talk in pages-budget). The other four fail on main as well, and I left them alone. I did not run the whole suite. I ran the tests covering these changes plus scripts/gate.ts, tsc and the design lint; all pass except each page stays inside its first-view budget, which still fails on changelog (see below).
What I changed:
- Capacity listing:
listCapacitymade about three SQL statements per setting. The seven new retention and size settings pushed/settings/capacityto 93 statements against a budget of 71. It now readsforge_settingonce, so the count is back near what it was and I reverted theWARM_STATEMENTSbump I had made intest/capacity-timing.test.ts. - Database size walk: a page request used to start the walk in the background. During the page walk it added statements to whichever page was being counted, which is why
/talkread 38–83 against 29 onmain. The nightly retention duty now takes the reading, once a day and once after a start, andpeekDbSize()only returns it. After a restart/systemsays "Being measured" until the duty's first tick, which is within a minute. /systemfirst view: the largest tables and indexes now sit behind a disclosure. I raised the/systembudget from 212 words and 67 blocks to 218 words and 70 blocks, with a note indocs/design/attention-budget.json. The disclosure did not lower the block count./boardbudget: raised from 70 to 71 statements, because vitals now reads the database growth.- Secret-column audit:
retention_cursor.valueis added as audited clear intest/data-browser.test.ts. It holds a cursor, not a credential.
Still failing, not caused by this pull: these four fail on origin/main too.
stall-scans(the assigned sweep)timers-named(src/runs/log.ts:149)flow-clock(src/flow/pipeline.ts)unused-exports(mergedPullClosingScan,bufferRunLogs)
The changelog first-view budget failure (18 words against 16) also fails on main, so each page stays inside its first-view budget stays red until that is fixed.
To try it, open /system, where the database section is the one below "Largest under the forge's data". The retention days are on /settings/capacity.
Three of the four parts are built. I could not verify the "done when" targets, and the index diet is a tool with no drops yet. All of it was tested on fresh databases only; I had no production copy.
What changed
src/core/retention.ts). Each of the three tables has one rule, andretention, a new maintenance duty, runs a batch of it every minute. A batch deletes in 500-row transactions, starts none after 40 ms, and stops at 20,000 rows. Where each walk stopped is kept in a newretention_cursortable.deploy_pullkeeps rows of deploys from the last 30 days and of the deploy each production app serves now. It drops rows of older deploys and of runs that no longer exist.eventnever drops audit kinds (account.,token.,repo.and similar). It drops machine chatter (usage.delta,run.shardand a few more) after 30 days and every other kind after 365. The file header says which reader needs what age.machine_samplekeeps raw samples for 48 h, 5-minute rows for 30 days, then the top-of-hour row for 90 days.ring.recordnow takes its raw window and hourly cutoff from the settings.retention.*,size.growth_mb_per_day), so an admin can override them on the capacity page.carriedOrRebuildre-walks git when a deploy's rows are gone. The run page andGET …/runs/{id}use it. A test drops a deploy's rows and checks the rebuilt pulls match.PRAGMA incremental_vacuumin 200-page steps (about 800 KiB), never a blockingVACUUMon the live handle, which would hold the write lock for the whole rewrite. Every database created from now on isauto_vacuum=INCREMENTAL.src/system/db_size.ts). The new "The database" section on /system, a short block on the terminal System screen anddatabaseon the MCPsystemtool show the file size, free space, growth per day, and the ten heaviest tables and indexes. Vitals raises a need when the file passes 2 GiB or grows faster thansize.growth_mb_per_day(default 200 MB). The figures are estimates, because Bun's SQLite has nodbstat.retention_cursor,db_size_day(one size reading a day) andwebhook_delivery(event_id). Without that index every event deleted would scan all webhook deliveries through the cascade.scripts/sql-tap.tsrecords the statements a test run prepares, andscripts/index-diet.tslists every index with the statements whose query plan uses it. It drops nothing.docs/features/retention.mdcovers the rules, who reads what age, and the offline conversion.What I chose not to do, or could not verify
auto_vacuum=none. Incremental vacuum does nothing there until one offline conversion byVACUUM INTOat a hand-over. The file stays about as big until that is done; /system says which mode it is in.machine_sampleshould shrink little. Production's 2.0M rows already fit the old 24 h/30 d rule, because there are about 140 targets. My rule adds an hourly tail (90 days), so this table may grow slightly.deploy_pulldirectly, so deploys older than 30 days show no "carries" there.Existing tests changed
test/capacity-timing.test.ts: the statement ceiling goes from 69 to 100, because the page has seven more settings.test/vitals.test.ts: the query count goes from 10 to 11 for the growth read.test/system-parts.test.ts: the section list gains "The database".scripts/header-width-allow.json: I wrapped the header comment intest/vitals.test.ts, so it is off the allow list.Test status.
bun scripts/gate.ts,tscanddesign-lintare clean, and the tests I ran for these areas pass, except as follows.timers-named(src/runs/log.ts) fails the same way on main.unused-exportsstill fails on two unused exports,mergedPullClosingScanandbufferRunLogs, neither from my change; I did not re-check them on main. I did not run the full suite.To try it. Open
/systemand read "The database". Open a production deploy's run page older than 30 days (carriesis unchanged). To see the index list, runFORGE_SQL_TAP=$TMPDIR/sql.jsonl bun test --preload ./scripts/sql-tap.ts <files>, thenbun scripts/index-diet.ts $TMPDIR/sql.jsonl [forge.db copy].🤖 Generated with Claude Code
Closes #11973