Skip to content

feat: auto-prune stale session artifacts#1632

Merged
gavrielc merged 2 commits intomainfrom
feat/session-cleanup-pr
Apr 4, 2026
Merged

feat: auto-prune stale session artifacts#1632
gavrielc merged 2 commits intomainfrom
feat/session-cleanup-pr

Conversation

@gavrielc
Copy link
Copy Markdown
Collaborator

@gavrielc gavrielc commented Apr 4, 2026

Summary

  • Adds scripts/cleanup-sessions.sh — age-based pruning of old session JSONLs, debug logs, todos, telemetry, and group logs
  • Protects active sessions by reading session IDs from store/messages.db before deleting anything
  • Wires cleanup into the main process via src/session-cleanup.ts — runs 30s after startup, then every 24h
  • Script supports --dry-run for manual previewing

Retention policy:

Artifact Retention
Session JSONLs + tool-results 7 days (active session always kept)
Debug logs 3 days
Todo files 3 days
Telemetry 7 days
Group logs 7 days

Context: Session artifacts (especially from daily cron tasks) accumulate unboundedly. A single group with 4 daily scheduled tasks generates ~4 JSONL + debug + todo files per day. Over weeks this adds up to hundreds of MB with no cleanup.

Test plan

  • --dry-run verified: correctly identifies stale files, reports expected savings
  • All 11 active sessions confirmed protected (no active session ID appears in dry-run output)
  • Live run freed ~85 MB on a real install
  • npm run build passes clean

🤖 Generated with Claude Code

Session files (JSONLs, debug logs, todos, telemetry, group logs) accumulate
unboundedly — especially from daily cron tasks. This adds a cleanup script
that prunes old artifacts while protecting active sessions (read from DB),
and wires it into the main process on a 24h interval.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gavrielc gavrielc requested a review from gabi-simons as a code owner April 4, 2026 21:03
- Replace macOS-only `stat -f%z` with portable `wc -c` for Linux compat
- Replace `find | while` pipes with process substitution so TOTAL_FREED
  counter survives the loop (pipe runs in subshell, losing mutations)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gavrielc gavrielc merged commit a74be06 into main Apr 4, 2026
1 check failed
IamAdamJowett pushed a commit to businesslifers/nanoclaw that referenced this pull request Apr 5, 2026
teknium1 added a commit to NousResearch/hermes-agent that referenced this pull request Apr 13, 2026
Port from qwibitai/nanoclaw#1632: Auto-prune stale session artifacts.

hermes-agent accumulates disk artifacts that are never cleaned up:
- Session transcript JSON files (~2 GB on a typical install)
- API request debug dumps
- Filesystem checkpoint shadow repos (~12 GB)
- Gateway JSONL transcript files

The existing 'hermes sessions prune' only deletes DB rows, leaving all
disk files behind.

Changes:
- New tools/session_cleanup.py module with safe, active-session-aware
  disk artifact pruning (session files, request dumps, checkpoints)
- Enhanced 'hermes sessions prune' with --include-files, --files-only,
  and --dry-run flags for disk artifact cleanup
- Enhanced 'hermes sessions stats' to show disk artifact counts and sizes
- Automated daily cleanup in gateway's session expiry watcher
- 28 new tests covering all cleanup paths, safety guards, and edge cases

Safety:
- Never deletes files belonging to active (non-ended) sessions
- Never touches sessions.json state file
- Checkpoints use age-based deletion only (no session ID correlation)
- Dry-run mode available for preview before deletion
- All errors are caught and logged, never crash the gateway
dm-j pushed a commit to dm-j/nanoclaw that referenced this pull request Apr 13, 2026
@gavrielc gavrielc deleted the feat/session-cleanup-pr branch April 17, 2026 09:27
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