Skip to content

fix(cli/tui): split MRU resume + actual exit session - #16336

Closed
OutThisLife wants to merge 7 commits into
mainfrom
bb/p2-mru-resume-order
Closed

fix(cli/tui): split MRU resume + actual exit session#16336
OutThisLife wants to merge 7 commits into
mainfrom
bb/p2-mru-resume-order

Conversation

@OutThisLife

@OutThisLife OutThisLife commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Make SessionDB.search_sessions() compute and order by last_active (MAX(messages.timestamp) fallback started_at) so session queries are true MRU.
  • Keep _resolve_last_session() as a single-row lookup (limit=1) instead of sampling and client-side sorting.
  • Move TUI exit-summary active-session plumbing here: _read_tui_active_session_file, HERMES_TUI_ACTIVE_SESSION_FILE, and writeActiveSessionFile so the shell epilogue reports the actual active session.
  • Add regression coverage for the >20-session case where the true MRU can be older than the newest started sessions.

Test plan

  • scripts/run_tests.sh tests/hermes_cli/test_resolve_last_session.py tests/hermes_cli/test_tui_resume_flow.py
  • npm test (in ui-tui)

- order session listing by computed last_active in SessionDB so callers get MRU rows directly
- keep _resolve_last_session as a single-row lookup and add regression coverage for >20 session sampling
@OutThisLife
OutThisLife requested review from Copilot and teknium1 and removed request for Copilot April 27, 2026 03:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes hermes -c session resolution to use true MRU semantics by having the state DB compute a last_active value per session (based on latest message timestamp, falling back to started_at) and ordering session queries by that value.

Changes:

  • Update SessionDB.search_sessions() to compute last_active and order results by MRU.
  • Simplify _resolve_last_session() to a single-row lookup (limit=1) that trusts DB ordering.
  • Add regression tests to ensure MRU selection works even when the true MRU falls outside the newest-started 20 sessions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/hermes_cli/test_resolve_last_session.py Adds regression coverage for -c selecting the true MRU session, including the >20 sessions case.
hermes_state.py Computes last_active in search_sessions() and sorts sessions by MRU.
hermes_cli/main.py Changes -c resolution to fetch only the top MRU session from the DB.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hermes_state.py Outdated
Comment thread hermes_cli/main.py
@OutThisLife OutThisLife changed the title fix(cli): resolve -c by true MRU session fix(cli/tui): split MRU resume + actual exit session Apr 27, 2026
@OutThisLife
OutThisLife requested a review from Copilot April 27, 2026 03:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hermes_cli/main.py Outdated
- use a grouped last_active join in search_sessions to avoid per-row correlated max lookups
- always close SessionDB in _resolve_last_session via finally and add regression coverage for search failure cleanup
- create HERMES_TUI_ACTIVE_SESSION_FILE with mkstemp instead of a predictable tmp path and always cleanup in finally
- add assertions that launch wiring uses a randomized session file path and removes it on exit
@OutThisLife
OutThisLife requested a review from Copilot April 27, 2026 03:52
@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 comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Apr 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/hermes_cli/test_tui_resume_flow.py
Validate that the temp active-session file exists while the TUI subprocess runs and is removed after launch cleanup to match mkstemp semantics.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #16626 — your 6 commits were cherry-picked onto current main with your authorship fully preserved in git log. GitHub refused the direct rebase-merge on your branch because it contained a merge commit, so we did a clean cherry-pick onto a fresh branch to keep per-commit attribution. Thanks Brooklyn!

#16626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants