feat: auto-prune stale session artifacts#1632
Merged
Conversation
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>
- 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>
IamAdamJowett
pushed a commit
to businesslifers/nanoclaw
that referenced
this pull request
Apr 5, 2026
feat: auto-prune stale session artifacts
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
feat: auto-prune stale session artifacts
This was referenced Apr 13, 2026
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
scripts/cleanup-sessions.sh— age-based pruning of old session JSONLs, debug logs, todos, telemetry, and group logsstore/messages.dbbefore deleting anythingsrc/session-cleanup.ts— runs 30s after startup, then every 24h--dry-runfor manual previewingRetention policy:
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-runverified: correctly identifies stale files, reports expected savingsnpm run buildpasses clean🤖 Generated with Claude Code