feat: add session artifact disk cleanup (port from NanoClaw #1632)#8685
Closed
teknium1 wants to merge 1 commit into
Closed
feat: add session artifact disk cleanup (port from NanoClaw #1632)#8685teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
Port from nanocoai/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
Contributor
Author
|
Superseded by #16286 (salvaged @SeeYangZhi's #6613, wired into #13861's auto_prune helper). The NanoClaw-style daily watcher loop is out of scope now that we ride on the existing opt-in. The |
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
Ports the session artifact auto-pruning concept from qwibitai/nanoclaw#1632, adapted to hermes-agent's Python architecture.
Problem
hermes-agent accumulates disk artifacts that are never automatically cleaned up:
session_*.json) — ~5,000 files, ~2 GB on a typical installrequest_dump_*.json) — ~180 files, ~32 MB~/.hermes/checkpoints/) — ~1,100 dirs, ~12 GB*.jsonl)The existing
hermes sessions prunecommand only deletes DB rows, leaving all disk files behind forever.What Changed
New
tools/session_cleanup.pymodule — Core cleanup logic with safety guards:sessions.jsonstate fileEnhanced
hermes sessions prune— Three new flags:--include-files: Also clean disk artifacts alongside DB pruning--files-only: Only clean disk files, skip DB pruning--dry-run: Preview what would be deleted without actually deletingEnhanced
hermes sessions stats— Now shows disk artifact counts and sizes, with a tip about cleanupAutomated daily cleanup in gateway — The existing
_session_expiry_watchernow runs disk artifact cleanup once every 24 hours, reclaiming space automatically for long-running gateway deployments28 new tests covering all cleanup paths, safety guards, active session protection, and edge cases
Architectural Differences from NanoClaw
NanoClaw uses a bash script + Node.js timer. Our implementation is pure Python:
prune_session_files()handles session transcripts and request dumps with active-session-ID protectionprune_checkpoints()handles checkpoint shadow repos with age-based deletionprune_all_artifacts()orchestrates both_session_expiry_watcherasync loop viarun_in_executorTest Plan