Repository navigation
Description
cleanup_old() deletes rows past the retention window on every insert, but nothing ever reclaims the pages. Retention therefore bounds the row count, not the file size, and the database stays permanently at its high-water mark.
Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). The numbers below were measured on this machine.
Measured
Populated a history db to 500k rows, aged every row past the 90-day window, then ran rtk so cleanup_old() fired:
rows in commands table : 1
file size : 87.8 MB
freelist_count : 22480
page_count : 22486 (99.9% of pages are free)
auto_vacuum : 0
The space is never handed back to the filesystem. It is reused by future inserts, so this is not unbounded growth — but a user who had one heavy month keeps that footprint indefinitely.
There is a measurable cost too: rtk gain on that empty-but-88 MB file takes 92 ms, versus 50 ms on a freshly created one.
Source
src/core/tracking.rs:454-465—cleanup_old()issuesDELETE, and that is the whole reclamation story.- Grepping
src/forVACUUM,auto_vacuum, andANALYZEreturns nothing. NoPRAGMA auto_vacuumis set at connection time (tracking.rs:271-274setsjournal_mode=WALandbusy_timeout), andauto_vacuumcannot be enabled on an existing database without a fullVACUUManyway.
Related, smaller
rtk gain --history and --failures scan more than they need on a large table:
tracking.rs:595-618 get_summary_filteredselects four columns for every row and sums them in a Rustforloop instead of usingSELECT SUM(), COUNT(). Measured on the same database: 887.5 ms vs 92.1 ms at 500k rows (9.6×); 177.9 ms vs 18.7 ms at 100k.tracking.rs:598,656,684useWHERE (?1 IS NULL OR project_path = ?1 OR project_path GLOB ?2).EXPLAIN QUERY PLANreportsSCAN commandsplus temp b-trees for GROUP BY and ORDER BY; the same predicate written without the parameter-dependent OR reportsSEARCH commands USING INDEX idx_project_path_timestamp.
End to end, rtk gain goes 50 ms (empty) → 101 ms (10k) → 228 ms (100k) → 920 ms (500k rows). At roughly 1.1k commands/day, 100k rows is about what a 90-day window holds for a heavy user.
Possible directions (untested — no programmer has reviewed these)
- Run
VACUUMoccasionally — e.g. whenfreelist_countexceeds some fraction ofpage_count, checked at cleanup time rather than on every insert. - Or set
PRAGMA auto_vacuum = INCREMENTALfor newly created databases and callincremental_vacuumafter cleanup. Existing databases would need a one-timeVACUUMto switch. - Independently: fold the summary aggregation into SQL, and split the project-scope filter into two prepared statements so the index can be used.
For what it is worth, the streaming path in rtk discover is a good counter-example in the same codebase — 837 MB across 1109 files at a flat ~20 MiB.
Activity
pszymkowiak commentedon Aug 4, 2026
🔍 Automated Triage
bugmediumSummary
history.db never reclaims disk space after row deletion (no VACUUM/auto_vacuum), keeping it at its high-water-mark size and slowing queries; recommend periodic VACUUM or incremental auto_vacuum, plus SQL-side SUM/COUNT aggregation and an index-friendly project-scope filter.
📁 Relevant files
src/core/tracking.rsTriaged automatically by wshm · This is an automated analysis, not a human review.