cmmd: growth control + daily-tick + fix-count budgets#1
Open
NagyVikt wants to merge 1 commit into
Open
Conversation
Three classes of unbounded resource use the daemon had no guard against: - `history.jsonl` grew forever (one row per tick per memory root). - `/tmp/cmmd-tick-<id>.log` agent transcripts accumulated indefinitely. - The memory dir's `.git/objects` grew with every pre-tick snapshot. Plus two budget caps that lived only in agent prose, not in code: - "≤3 fixes per tick" was advisory — agent could quietly apply more. - No daily ceiling on agent spawns — a stuck-finding-issues loop could burn tokens forever. What this commit adds: History rotation, per-tick-log TTL sweeper, and per-MEMORY_ROOT `git gc` all run once per main-loop iteration (history.rs). New env knobs: HISTORY_MAX_LINES=10000, TICK_LOG_TTL_DAYS=7, GIT_GC_INTERVAL_DAYS=7. Daily-tick counter is UTC-day rolled and persisted in state.json so the ceiling survives restarts; MAX_TICKS_PER_DAY=100 default. The agent is not spawned for the rest of the day once the cap is hit, and the tick is recorded as `reason_skipped=MAX_TICKS_PER_DAY reached`. Fix-count cap is enforced post-spawn by counting `git status --porcelain` entries vs the pre-tick SHA; if exceeded, `history::restore(pre_sha)` rolls the whole tick back. MAX_FIXES_PER_TICK=3 default. Six new Prometheus counters expose all of the above (cmmd_history_rotations_total, cmmd_tick_logs_swept_total, cmmd_git_gc_runs_total, cmmd_ticks_blocked_daily_cap_total, cmmd_ticks_reverted_fix_cap_total, cmmd_day_ticks_ran). Zero-dep UTC-date helper added to state.rs (Hinnant's civil-from-days) to avoid a chrono dependency for one date string. 44 tests pass (8 new), clippy clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 tasks
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
Three classes of unbounded resource use the daemon had no guard against, plus two budget caps that lived only in agent prose:
history.jsonlgrew forever (one row per tick per memory root)./tmp/cmmd-tick-<id>.logagent transcripts accumulated indefinitely..git/objectsgrew with every pre-tick snapshot.What's in the diff
git gcrun once per main-loop iteration. New env knobs:HISTORY_MAX_LINES=10000,TICK_LOG_TTL_DAYS=7,GIT_GC_INTERVAL_DAYS=7.state.jsonso the ceiling survives restarts.MAX_TICKS_PER_DAY=100default. When hit, the iteration force-skips and recordsreason_skipped=MAX_TICKS_PER_DAY=N reached for <date>.git status --porcelainentries vspre_tick_sha; if exceeded,history::restore(pre_sha)rolls the whole tick back.MAX_FIXES_PER_TICK=3default.state.rs.Test plan
cargo test --lib— 44 tests pass, 8 new (rotation, sweeper, daily-counter rollover, date anchors)cargo clippy --lib --bins --no-deps— cleancargo build --release— succeeds/metricscmmd_ticks_blocked_daily_cap_totalover a week; verify counter increments when the daily cap is hitcmmd_history_rotations_totalover a week; verifyhistory.jsonl.1exists after first rotationgit gcmarker file.git/cmmd-last-gcis created in each MEMORY_ROOT after first run🤖 Generated with Claude Code