fix(disk-cleanup): protect cron output root from cleanup (salvage #49271) - #56266
Merged
Merged
Conversation
Only classify files below cron/output/ as disposable cron output. The cron/output directory itself is a durable container for retained job history and should not be tracked or deleted wholesale. Add regression coverage for both category detection and cleanup of a stale tracked entry pointing at the output root.
Review follow-up: the _is_protected_cron_path docstring listed output/ next to jobs.json/.tick.lock as 'the directory itself', which is slightly ambiguous. Spell out that the match is EXACT-path only and must not be 'simplified' into a blanket cron/output/* guard (children stay cleanable) — prevents a future editor from re-introducing the wholesale-delete bug this fix closes.
Contributor
Author
|
Ran hermes-agent-dev + hermes-pr-review Phase 2c (4-part structured). 0 Critical, 0 Warnings. The off-by-one gate is correct (root protected, artifacts still cleaned), the two defenses (category gate + protected-paths set) are legitimate defense-in-depth (gate stops new tracking; set stops deletion of stale tracked.json entries), both .resolve()-consistent, both cron/cronjobs parents covered. Folded one doc-clarity follow-up (9ddd7c8): spell out that the output-root protection is exact-match-only so a future editor can't 'simplify' it into a blanket cron/output/* guard. |
kshitijk4poor
enabled auto-merge (rebase)
July 1, 2026 10:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvage of #49271 by @martinramos002-bot (rebased onto current
main). Stops the disk-cleanup plugin from deleting the cron output root (~/.hermes/cron/output) while still letting individual run artifacts below it be cleaned by retention policy.The bug
The disk-cleanup plugin classifies anything under
cron/output/as disposablecron-output. That includes thecron/outputroot directory itself — deleting it wholesale erases every job's retained run history at once, far broader than expiring one run artifact.The fix
str(base / "output")to_PROTECTED_CRON_PATHSin_is_protected_cron_path(for bothcronandcronjobsparents) — a hard block on deleting the output root.guess_category, tighten the gate fromlen(rel.parts) >= 2to>= 3:relis relative tohermes_home, socron/outputis('cron','output')(len 2) → no longer categorized deletable, while a real artifact atcron/output/<file>(len 3) or deeper stayscron-outputand is still cleaned.Two independent defenses for the same invariant (root not deletable): the category gate, and the protected-paths hard block as defense-in-depth.
Verification
Verified against current
main(applied + behaviorally probed):cron/outputroot → protected;cron/output/run.md(len 3 file),cron/output/job_1/run.md(len 4),cron/output/job_1(len 3 dir) all still deleted; a staletracked.jsonentry pointing at the root is dropped byquick()'s re-validation and hard-blocked by_is_protected_cron_path(both canonicalize via.resolve()). No off-by-one, no over-broad protection, no residual deletion path.Ran hermes-agent-dev + hermes-pr-review Phase 2c (4-part structured) on the final salvage.
Tests
tests/plugins/test_disk_cleanup_plugin.py— output-root-not-tracked, stale-entry-for-output-root-not-deleted, plus existing artifact-still-cleaned coverage. (CI runs the full suite.)Supersedes #49271. Full credit to @martinramos002-bot.