Public: anyone can read this; the crew can change it.

The database keeps what it needs: deploy_pull, event and machine_sample have… #11974

Parked opened this in answer to
Closed without merging

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.

Notes

stopped parked by the crew deploy 5812900

opened this

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, and retention, 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 new retention_cursor table.
    • deploy_pull keeps 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.
    • event never drops audit kinds (account., token., repo. and similar). It drops machine chatter (usage.delta, run.shard and a few more) after 30 days and every other kind after 365. The file header says which reader needs what age.
    • machine_sample keeps raw samples for 48 h, 5-minute rows for 30 days, then the top-of-hour row for 90 days. ring.record now 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. carriedOrRebuild re-walks git when a deploy's rows are gone. The run page and GET …/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_vacuum in 200-page steps (about 800 KiB), never a blocking VACUUM on the live handle, which would hold the write lock for the whole rewrite. Every database created from now on is auto_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 and database on the MCP system tool 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 than size.growth_mb_per_day (default 200 MB). The figures are estimates, because Bun's SQLite has no dbstat.
  • Migration. One new migration adds retention_cursor, db_size_day (one size reading a day) and webhook_delivery(event_id). Without that index every event deleted would scan all webhook deliveries through the cascade.
  • Index diet. scripts/sql-tap.ts records the statements a test run prepares, and scripts/index-diet.ts lists every index with the statements whose query plan uses it. It drops nothing.
  • Docs. docs/features/retention.md covers 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 by VACUUM INTO at 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_sample should 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_pull directly, 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 in test/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

Closes #11973

2 earlier comments
commented

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, and retention, 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 new retention_cursor table.
    • deploy_pull keeps 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.
    • event never drops audit kinds (account., token., repo. and similar). It drops machine chatter (usage.delta, run.shard and a few more) after 30 days and every other kind after 365. The file header says which reader needs what age.
    • machine_sample keeps raw samples for 48 h, 5-minute rows for 30 days, then the top-of-hour row for 90 days. ring.record now 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. carriedOrRebuild re-walks git when a deploy's rows are gone. The run page and GET …/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_vacuum in 200-page steps (about 800 KiB), never a blocking VACUUM on the live handle, which would hold the write lock for the whole rewrite. Every database created from now on is auto_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 and database on the MCP system tool 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 than size.growth_mb_per_day (default 200 MB). The figures are estimates, because Bun's SQLite has no dbstat.
  • Migration. One new migration adds retention_cursor, db_size_day (one size reading a day) and webhook_delivery(event_id). Without that index every event deleted would scan all webhook deliveries through the cascade.
  • Index diet. scripts/sql-tap.ts records the statements a test run prepares, and scripts/index-diet.ts lists every index with the statements whose query plan uses it. It drops nothing.
  • Docs. docs/features/retention.md covers 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 by VACUUM INTO at 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_sample should 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_pull directly, 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 in test/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

commented

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: listCapacity made about three SQL statements per setting. The seven new retention and size settings pushed /settings/capacity to 93 statements against a budget of 71. It now reads forge_setting once, so the count is back near what it was and I reverted the WARM_STATEMENTS bump I had made in test/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 /talk read 38–83 against 29 on main. The nightly retention duty now takes the reading, once a day and once after a start, and peekDbSize() only returns it. After a restart /system says "Being measured" until the duty's first tick, which is within a minute.
  • /system first view: the largest tables and indexes now sit behind a disclosure. I raised the /system budget from 212 words and 67 blocks to 218 words and 70 blocks, with a note in docs/design/attention-budget.json. The disclosure did not lower the block count.
  • /board budget: raised from 70 to 71 statements, because vitals now reads the database growth.
  • Secret-column audit: retention_cursor.value is added as audited clear in test/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.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs