feat(session): cleanup_period_days — opt-in session pruning#239
Merged
emal-avala merged 1 commit intomainfrom Apr 24, 2026
Merged
feat(session): cleanup_period_days — opt-in session pruning#239emal-avala merged 1 commit intomainfrom
emal-avala merged 1 commit intomainfrom
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Adds `[session] cleanup_period_days = N` so long-running installs don't accumulate unbounded session files under `~/.config/agent-code/sessions/`. When set, `prune_older_than(days)` runs at REPL startup and deletes any session whose `updated_at` is older than the threshold. Safety posture: - Default is None/absent — no change in behavior for existing users. - `Some(0)` is an explicit no-op (treated same as None; reserved for a future "prune everything" sentinel without silent churn). - A file with a missing or malformed `updated_at` is conservatively **kept** — we never delete a file whose age we can't determine. - A failed `remove_file` is counted as kept and doesn't abort the sweep — one locked file shouldn't stop the others from pruning. - Boundary rule is strictly-less-than, so a file exactly at the threshold is kept (no off-by-one that would surprise the operator). Also surfaces the current policy via `/doctor`: - Pass row when pruning is enabled: "Session cleanup: prune files older than N days" - Warn row when disabled: "Session cleanup disabled — set [session] cleanup_period_days to prune old sessions" Tests (8): - Schema default is None - TOML round-trip produces Some(30) - A config without a [session] section still produces defaults - Stale file is removed, fresh file kept - `days = 0` is a no-op even with an ancient file present - Unparseable timestamp is kept - `.tmp` / `.bak` files are skipped entirely - Exact-threshold boundary is kept (strictly-less-than rule) Full session + schema + diagnostics suites pass.
7b46d5d to
dd8cff8
Compare
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
Adds
[session] cleanup_period_days = Nso long-running installs don't accumulate unbounded session files under~/.config/agent-code/sessions/. When set, old session files are pruned at REPL startup. Absent /Nonepreserves today's behavior (keep sessions forever).Config
Safety posture
updated_atare kept. We never delete a file whose age we can't determine.remove_fileis counted as kept and does not abort the rest of the pass (one locked file shouldn't stop the others).Some(0)is a no-op: treated identically to None; reserved as a sentinel we can repurpose later without breaking existing configs..tmp/.bakleftovers are never scanned or counted.Surface in
/doctor✓ Session cleanup: prune files older than 30 days! Session cleanup disabled — set [session] cleanup_period_days to prune old sessionsTests (8)
Schema (3): default is None, TOML round-trip, a config without
[session]keeps defaults.Runtime (5): stale file removed, fresh kept,
days = 0is a no-op even with an ancient file, unparseable timestamp kept, non-JSON files skipped, exact threshold kept.Full
services::session,config::schema, andservices::diagnosticssuites pass. Clippy clean under-D warnings.Test plan
cargo test -p agent-code-lib --lib services::sessioncargo test -p agent-code-lib --lib config::schemacargo test -p agent-code-lib --lib services::diagnosticscargo build -p agent-codecargo clippy --workspace --tests --no-deps -- -D warnings