Repository navigation
fix(server): keep only the newest batch reports in reportDirectory - #197
Conversation
Every batch wrote a new report file and none was ever deleted, so a busy or failing server filled its volume, one report per batch. The directory now keeps the newest `server.reportsKept` reports (200 by default, 1 to 100000) and deletes older ones after each new report. Temporary files of reports still being written, and files that are not reports, are left alone.
There was a problem hiding this comment.
Heh, ni un solo agujero serio — the diff holds up. Sombra checked every corner of this one. 🕸️
Reviewed c4e6617 — keep only the newest reportsKept batch reports in reportDirectory. (Superseded: follow-up review of d8acd8b posted below.)
Findings
P0–P2
None. The pruning logic is correct: it runs inside the same spawn_blocking after the atomic rename, so the just-written report is always in the snapshot; NotFound on delete is correctly ignored (a racing worker pruned first); and since every pruner deletes a prefix of its own sorted snapshot, concurrent workers can leave more than kept transiently but never fewer — it converges on the next write. Validation flows through Settings::load, so reportsKept bounds apply on both startup and live Reload::refresh. Docs and schema comment are accurate.
Resolved in d8acd8b
- P3 —
prune_reportscounts anybatch-*.jsonas a report (inline). ✅ Fixed:report_namenow matches the writer's exactbatch-YYYYMMDDTHHMMSS.NNNNNNNNNZ-<pid>-<counter>.jsonshape, so foreign files are neither counted nor deleted. Thread resolved. - P4 —
read_dir/ entry errors silently swallowed. ✅ Fixed:read_dirfailure now logs atracing::warn!. - P4 — stale
.batch-*.tmpfiles accumulate forever. ✅ Fixed: report-named temp files are deleted once older than 24h (ABANDONED_REPORT). (Test coverage gap noted in follow-up review.) - P4 —
100_000boundary untested. ✅ Fixed: boundary accept now asserted inreports_kept_is_read_and_bounded.
Standing / intentional
- P4 — clock regressions break name-order = age-order. Left as-is per author; inherent to name-based ordering and now noted in the doc comment ("as long as the clock does not step backwards").
- P4 — non-UTF-8
batch-*.jsonnames are filtered out byinto_string()and can never be counted or pruned. Harmless asymmetry; writer only emits ASCII.
Verification
Ran cargo test --locked -p patchula-server --lib filtered to the new/changed tests on the project boat VM at c4e6617: the_report_directory_keeps_only_the_newest_reports, reports_kept_is_read_and_bounded, report_directory_preserves_versioned_contract, discovery_skip_is_explicit_and_each_repository_report_gets_a_file — all pass. Compiles clean.
Nicely done — this one's close to mergeable. Apocopando vuvuzelas, etc. 💜
…y files - A report is a file named exactly as the writer names one, so a foreign batch-*.json can no longer hold a newest slot and crowd out real reports. - Temporary files a crashed writer left behind are deleted once a day old. - An unreadable report directory is logged instead of silently stopping pruning.
There was a problem hiding this comment.
¡Volví! Sombra's back for round two — d8acd8b under the microscope. 🔎
Follow-up review of d8acd8b. (Superseded: follow-up review of 38e8570 posted below.)
Resolved
- P3 —
report_namepredicate too broad (inline,runtime.rs). ✅ Fixed ind8acd8b:report_namenow matches the writer's exactbatch-YYYYMMDDTHHMMSS.NNNNNNNNNZ-<pid>-<counter>.jsonshape; foreignbatch-*.jsonfiles can no longer occupy retention slots. Thread resolved. - P3 — the abandoned-tmp branch was untested. ✅ Fixed in
38e8570:the_report_directory_keeps_only_the_newest_reportsnow ages a validly-named.batch-…Z-1-0.json.tmptwo days and asserts deletion, keeps a fresh validly-named tmp, and keepsbatch-notes.json. Verified running on the boat VM.
Standing / noted
- P4 — same-instant ordering can invert write order across counter digit boundaries. Lexicographic sort puts
...-10.jsonbefore...-2.json; within a shared timestamp the counter (not age) decides what counts as "oldest." Impact essentially nil — same inherent name-ordering caveat as the clock note. Completeness only.
The previous commit meant to, but the edit missed: the test now ages a validly named temporary report two days and checks it is deleted, keeps a fresh one, and keeps a foreign batch-notes.json.
|
You're right, my earlier reply was wrong: the test edit never applied (cargo fmt had reflowed the lines my edit was matching). Fixed for real in 38e8570. The pruning test now ages a validly named |
There was a problem hiding this comment.
Ooh, qué limpio — the gap is closed and Sombra found nothing left to steal. 🕸️
Follow-up review of 38e8570 (live head) — the test-only commit covering the abandoned-tmp branch I flagged last round.
Verified against prune_reports
- The abandoned branch is genuinely exercised.
.batch-20261104T120000.000000000Z-1-0.json.tmpstrips to a validreport_name, its mtime is aged two days viaFile::set_modified, andelapsed() > ABANDONED_REPORTpushes it onto the delete list. If it survived, it would land inothersand fail the assertion — so the test covers the deletion direction for real, not just by accident. (runtime.rs:693-705) - Both directions are covered. The fresh
.batch-20261106T120000.000000000Z-1-0.json.tmphas a valid inner name but a fresh mtime, so it survives — proving the age check, not just the name check, gates deletion. batch-notes.jsonkeeps the P3 fix honest — a foreign file that sorts after every real report stays put.- The
othersordering assertion is correct —.sorts before letters, andbatch-notes.json<batch-notes.txt, so the expected list matchessort().
Findings
P0–P4
None. Test-only change, correctly constructed.
Verification
Ran cargo test --locked -p patchula-server --lib report on the project's boat VM at 38e8570: all 5 report tests pass, including the_report_directory_keeps_only_the_newest_reports and only_names_the_report_writer_makes_are_reports.
Hasta la vista — this one merges clean from where I'm sitting. 💜
Problem
With
reportDirectoryset, every batch writes a new JSON report, and none is ever deleted. A failing repository used to rerun its batch every minute, writing a full report each time, so the directory grew without limit.Change
server.reportsKept: how many reports the directory keeps. Default 200, allowed 1 to 100000, validated with the other server settings.batch-*.jsonfiles beyond the limit are deleted. Report names start with a fixed-width UTC timestamp, so sorting by name sorts by age..batch-*.tmpfiles, which another worker may still be writingguide/server.mdx.Tests
the_report_directory_keeps_only_the_newest_reports: writes six reports with a limit of three. The newest three are kept, and the.tmpand unrelated files survive.reports_kept_is_read_and_bounded: checks the default, a custom value, and that 0 and 100001 are rejected.