fix(sessions): preserve recently active sessions during pruning - #71043
Closed
Frowtek wants to merge 1 commit into
Closed
fix(sessions): preserve recently active sessions during pruning#71043Frowtek wants to merge 1 commit into
Frowtek wants to merge 1 commit into
Conversation
Contributor
|
Merged via #72358 with your commit cherry-picked onto current main — authorship preserved. Thanks for the prune-by-inactivity fix. |
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.
What does this PR do?
Prevents session retention from deleting long-lived conversations that were active recently.
prune_sessions(older_than_days=...)previously compared the retention cutoff againstsessions.started_at. As a result, an ended conversation created more than 90 days ago but used today was silently deleted at CLI/gateway startup whensessions.auto_prunewas enabled. This removed the session row, its messages, and transcript files; the normal follow-up VACUUM could make recovery impractical.Retention age now uses the latest persisted message timestamp, falling back to
started_atfor empty sessions. Explicit--beforeand--afterfilters continue to target session creation time, while relative--older-thanand--newer-thanfilters target activity.The preview, confirmation output, dashboard response, documentation, and deletion path use the same activity contract.
Related Issue
No issue filed.
Related but non-duplicate work:
ended_atremains NULL.Type of Change
Changes Made
hermes_state.pyso age-based preview and pruning use latest message activity.last_active.How to Test
main, create an ended session whosestarted_atis 100 days old, append a message with the current timestamp, and run:maybe_auto_prune_and_vacuum(retention_days=90, vacuum=False, sessions_dir=...)main@7cd48733dreturnspruned: 1and deletes the session, messages, and transcript.pruned: 0; the session, message, and transcript remain..\.venv\Scripts\python.exe -m pytest -o "addopts=-m 'not integration'" -p no:timeout tests/test_hermes_state.py tests/hermes_cli/test_session_filters.py tests/hermes_cli/test_sessions_delete.py tests/hermes_cli/test_sessions_export_md_cli.py tests/hermes_cli/test_dashboard_admin_endpoints.py -qResult:
574 passed.Checklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
docs/, docstrings) —website/docs/user-guide/sessions.mdcli-config.yaml.exampleif I added/changed config keys — N/A, no config keys changedCONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
Current main:
{"started_days_ago":100,"latest_message_age_seconds":0,"maintenance":{"skipped":false,"pruned":1,"vacuumed":false},"session_after":null,"transcript_exists":false}This branch:
{"started_days_ago":100,"latest_message_age_seconds":0,"maintenance":{"skipped":false,"pruned":0,"vacuumed":false},"session_survived":true,"messages":1,"transcript_exists":true}Regression suite:
574 passed in 74.09s