fix(cli): tighten MRU lookup and session DB cleanup

- 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
This commit is contained in:
Brooklyn Nicholson
2026-04-26 22:49:49 -05:00
committed by Teknium
parent 653b5ec128
commit 4b28140912
3 changed files with 36 additions and 9 deletions

View File

@@ -597,15 +597,21 @@ def _session_browse_picker(sessions: list) -> Optional[str]:
def _resolve_last_session(source: str = "cli") -> Optional[str]:
"""Look up the most recently-used session ID for a source."""
db = None
try:
from hermes_state import SessionDB
db = SessionDB()
sessions = db.search_sessions(source=source, limit=1)
db.close()
return sessions[0]["id"] if sessions else None
except Exception:
pass
finally:
if db is not None:
try:
db.close()
except Exception:
pass
return None