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

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

Closed opened this

Pull #11978 was closed · 3 runs

opened this

The database keeps what it needs: deploy_pull, event and machine_sample have a retention rule, and the forge reports its own size by table

Measured on a copy of production (2026-11-13): forge.db is 4.56 GB, too big for Bun's 2 GiB mmap cap, so scans cost a read per page. Payload is about 1.9 GB and the rest is 396 indexes. The three largest tables are bookkeeping, not anyone's work: deploy_pull 9.9M rows / 906 MB (its own header says it is an index over git and can be rebuilt), event 2.4M rows / 578 MB, machine_sample 2.0M rows / 174 MB. For comparison run is 124k rows / 44 MB and comment 47 MB. The owner's words: "the original vision was bun + sqlite and we've gotten very bloated", and tonight the forge's one thread was blocked most of every minute.

Build:

  1. Retention, each a rule stated in one place and run by the forge's own nightly job in small batches (never a long write lock; a batch per tick with a row cap): deploy_pull keeps rows for deploys of the last N days and whatever a live or sleeping app still needs, the rest is rebuilt on demand from git (prove the rebuild path with a test first); event keeps everything a feed, an audit view or a replay cursor can still reach (say which readers need what age) and drops or rolls up the rest; machine_sample keeps raw samples for 48 h, then one row per 5 minutes for 30 days, then one per hour. Defaults in constants, overridable in admin settings, shown on /system.
  2. After pruning, space is given back without a long lock: incremental vacuum (or VACUUM INTO a new file at a release hand-over), not a blocking VACUUM on the live handle. State which and why.
  3. Index diet: list all 396 indexes with the queries that use them (from EXPLAIN QUERY PLAN over the statements the suite prepares) and drop the ones nothing uses; the pull shows the list and the bytes returned.
  4. The forge knows its own size: /system and the system tool show the top ten tables and indexes by bytes and rows, the file size, and growth per day; a vitals need fires when the file grows faster than a set rate or passes the mmap cap, so this is never found by a profiler again.

Done when: on a copy of production the three rules bring the file under 2 GiB with every test green and every page that reads those tables showing the same answers for the ages it promises; the size table is on /system; the nightly job's batches each hold the write lock under 50 ms.

2 earlier comments · 1 event
commented

Parked by the crew: the check stayed red through 2 automatic tries (pull #11974 closed; its branch mason/11973-the-database-keeps-what-it-needs-deploy at 5812900b14f6 keeps the work so far). Planner: split this smaller, or rewrite what done looks like; a person can also say what to try.

try 1: AGENTS.md, docs/features/retention.md, scripts/index-diet.ts, scripts/sql-tap.ts, src/boards/ring.ts, src/boards/sampler.ts, src/core/capacity.ts, src/c… try 2: scripts/header-width-allow.json, scripts/index-diet.ts, scripts/sql-tap.ts, src/boards/ring.ts, src/core/capacity.ts, src/core/carried.ts, src/core/rete… try 3: docs/design/attention-budget.json, src/actions/capacity.ts, src/maintain/duties/retention.ts, src/system/db_size.ts, src/web/pages/system.ts, test/capac… try 4: src/system/db_size.ts

the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

Parked by the crew: the check stayed red through 2 automatic tries (pull #11978 closed; its branch scout/11973-the-database-keeps-what-it-needs-deploy at d63fc7a21ee8 keeps the work so far).

Parked twice since a person last spoke here, so it is the planner's now. Every reason:

  1. the check stayed red through 2 automatic tries (pull #11974 closed; its branch mason/11973-the-database-keeps-what-it-needs-deploy at 5812900b14f6 keeps the work so far)
  2. the check stayed red through 2 automatic tries (pull #11978 closed; its branch scout/11973-the-database-keeps-what-it-needs-deploy at d63fc7a21ee8 keeps the work so far)

The planner splits it, replaces it with a fresh issue, or defers it; a person can also say what to try. Nothing starts here until then, and the board lists it.

try 1: src/http/mcp/tools/system.ts, src/kernel/vitals.ts, src/system/db_size.ts, src/web/pages/system.ts, test/disk-marks.test.ts, test/system-parts.test.ts try 2: docs/MCP.md, docs/features/estimates.md, docs/features/packs.md, docs/features/ssh-first-ask.md, scripts/pack.ts, src/actions/estimates.ts, src/actions/…

commented

Split: one rule per table, each pruning in capped batches: #12007 (machine_sample), #12008 (event), #12009 (deploy_pull, with the rebuild-from-git test first). Then #12010 (the size table on /system, the system tool's kind "size", and the vitals need) and #12011 (index diet). Giving the space back without a long lock (incremental vacuum or VACUUM INTO at hand-over) comes next, once #12007-#12009 land. It was left out only because a plan holds 12 items.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs