Skip to content

Fix abandoned session cleanup - #38327

Open
sean174 wants to merge 1 commit into
NousResearch:mainfrom
sean174:fix/abandoned-session-cleanup
Open

Fix abandoned session cleanup#38327
sean174 wants to merge 1 commit into
NousResearch:mainfrom
sean174:fix/abandoned-session-cleanup

Conversation

@sean174

@sean174 sean174 commented Jun 3, 2026

Copy link
Copy Markdown

Summary

  • Mark old unended sessions as abandoned_cleanup before pruning so abandoned rows do not bypass retention forever
  • Wire the same finalize-then-prune behavior into hermes sessions prune and startup auto-maintenance
  • Update session maintenance docs for abandoned-session cleanup behavior

Test Plan

  • python -m pytest tests/test_hermes_state.py::TestAutoMaintenance tests/hermes_cli/test_sessions_delete.py -q
  • python -m pytest tests/test_hermes_state.py tests/gateway/test_session_store_prune.py tests/gateway/test_session_state_cleanup.py tests/hermes_cli/test_sessions_delete.py -q
  • python -m py_compile hermes_state.py hermes_cli/main.py hermes_cli/config.py
  • git diff --check HEAD~1..HEAD

Notes

This is a defensive cleanup fix for long-lived/gateway installs where sessions may remain unended after crashes, restarts, or abandoned threads. Recently active sessions are protected by checking latest message timestamp, falling back to session start time for empty sessions.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 3, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for addressing retention leaks in unended session rows. The underlying gap remains on current main: pruning selects only ended_at IS NOT NULL rows (hermes_state.py:5695, used by prune_sessions() at hermes_state.py:5867).

Problems

  • The proposed last-message heuristic would change the current active-session contract. Current config says auto-prune only touches ended sessions (hermes_cli/config.py:3010-3014), and tests/test_hermes_state.py:2198-2209 requires a 200-day unended session to survive pruning. An idle but resumable gateway session is a concrete concern: recovery reopens durable rows in gateway/session.py:1391-1434.
  • The CLI portion of c35eb54 is stale against the current candidate-preview flow. Current main builds filters, previews list_prune_candidates(), then confirms before prune_sessions() (hermes_cli/main.py:14367-14468). The new unended candidates need defined preview and confirmation semantics.

Suggested changes

  • Use an authoritative lifecycle/liveness signal rather than message inactivity alone, and test that long-idle resumable sessions survive.
  • Integrate the behavior into the current preview/confirmation flow and add gateway-recovery coverage.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants