Skip to content

feat(session): cleanup_period_days — opt-in session pruning#239

Merged
emal-avala merged 1 commit intomainfrom
feat/session-cleanup-period-days
Apr 24, 2026
Merged

feat(session): cleanup_period_days — opt-in session pruning#239
emal-avala merged 1 commit intomainfrom
feat/session-cleanup-period-days

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Adds [session] cleanup_period_days = N so 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 / None preserves today's behavior (keep sessions forever).

Config

[session]
# Auto-delete session files whose `updated_at` is older than N days.
# Absent or None = keep forever.
cleanup_period_days = 30

Safety posture

  • Default is no-op — no change for existing users; the feature is strictly opt-in.
  • Conservative age check: files with missing or malformed updated_at are kept. We never delete a file whose age we can't determine.
  • Non-fatal sweep: a failed remove_file is counted as kept and does not abort the rest of the pass (one locked file shouldn't stop the others).
  • Strictly-less-than boundary: a file exactly at the threshold is kept, avoiding off-by-one surprises.
  • Some(0) is a no-op: treated identically to None; reserved as a sentinel we can repurpose later without breaking existing configs.
  • Non-JSON files skipped entirely — .tmp / .bak leftovers are never scanned or counted.

Surface in /doctor

  • Enabled: ✓ Session cleanup: prune files older than 30 days
  • Disabled: ! Session cleanup disabled — set [session] cleanup_period_days to prune old sessions

Tests (8)

Schema (3): default is None, TOML round-trip, a config without [session] keeps defaults.

Runtime (5): stale file removed, fresh kept, days = 0 is a no-op even with an ancient file, unparseable timestamp kept, non-JSON files skipped, exact threshold kept.

Full services::session, config::schema, and services::diagnostics suites pass. Clippy clean under -D warnings.

Test plan

  • cargo test -p agent-code-lib --lib services::session
  • cargo test -p agent-code-lib --lib config::schema
  • cargo test -p agent-code-lib --lib services::diagnostics
  • cargo build -p agent-code
  • cargo clippy --workspace --tests --no-deps -- -D warnings

@chatgpt-codex-connector
Copy link
Copy Markdown

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.
@emal-avala emal-avala force-pushed the feat/session-cleanup-period-days branch from 7b46d5d to dd8cff8 Compare April 24, 2026 04:37
@emal-avala emal-avala merged commit 9b782c0 into main Apr 24, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/session-cleanup-period-days branch April 24, 2026 05:04
@emal-avala emal-avala mentioned this pull request Apr 24, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant