feat(sessions): drop empty sessions on CLI exit and rotation (port from gemini-cli#27770) - #43855
Merged
2 commits merged intoJun 11, 2026
Merged
Conversation
Port from google-gemini/gemini-cli#27770: starting the CLI and immediately quitting (or rotating with /new, /clear) left an empty untitled session row behind. These ghost rows pile up in /resume, `hermes sessions list`, and the in-chat recent-sessions browser. - SessionDB.delete_session_if_empty(): transactional check-and-delete that only removes rows with no messages, no title, and no child sessions (delegate subagent parents are preserved). Also removes on-disk transcript files via the existing _remove_session_files. - HermesCLI._discard_session_if_empty(): thin wrapper, wired into the cli_close shutdown path and the new_session() rotation path. Skipped when /exit --delete already handles removal. Unlike the one-shot prune_empty_ghost_sessions migration (TUI-only, 24h-old rows), this prevents new ghost rows from accumulating at the moment they would be created.
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
1 |
First entries
tests/test_empty_session_hygiene.py:10: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
✅ Fixed issues: none
Unchanged: 5560 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
CI caught tests/cli/test_cli_new_session.py asserting that /new keeps the old session row when conversation history exists in memory. The live transcript is authoritative: a session whose messages haven't flushed to the DB yet (or whose flush failed) must not be pruned. Guard _discard_session_if_empty on self.conversation_history and pin the behavior with a test.
1 task
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
Empty sessions no longer pile up in
/resume,hermes sessions list, and the in-chat recent-sessions browser: starting the CLI and immediately quitting (or rotating with/new//clear) now drops the untitled, message-less session row instead of persisting it.Port of google-gemini/gemini-cli#27770 ("Avoid persisting empty resume sessions"), adapted to hermes-agent's SQLite SessionDB.
Changes
hermes_state.py: newSessionDB.delete_session_if_empty()— transactional check-and-delete that only removes rows with no messages, no title, and no child sessions (a parent that spawned delegate subagent runs is never considered empty). Reuses_remove_session_filesfor on-disk transcript cleanup.cli.py:_discard_session_if_empty()wrapper wired into two paths:cli_closeshutdown path (skipped when/exit --deletealready handles removal)new_session()rotation (/new,/clear)tests/test_empty_session_hygiene.py: 13 tests covering delete/keep matrix (messages, title, children), transcript file cleanup, listing visibility, and CLI wiring edge cases (no DB, None id, DB error swallowed).Complementary to the existing one-shot
prune_empty_ghost_sessionsmigration (TUI-only, >24h-old rows): this prevents new ghost rows at the moment they would be created rather than sweeping them later.Validation
tests/test_empty_session_hygiene.pytest_hermes_state.py,test_exit_delete_session.py,test_lazy_session_regressions.pySource PR: google-gemini/gemini-cli#27770