Skip to content

fix(session): surface silent SessionDB failures that cause session data loss#2939

Open
LucidPaths wants to merge 1 commit intoNousResearch:mainfrom
LucidPaths:fix/session-db-silent-failures
Open

fix(session): surface silent SessionDB failures that cause session data loss#2939
LucidPaths wants to merge 1 commit intoNousResearch:mainfrom
LucidPaths:fix/session-db-silent-failures

Conversation

@LucidPaths
Copy link

Problem

SessionDB initialization and operation failures are logged at debug level or silently swallowed (except Exception: pass), causing sessions to never be indexed in the FTS5 database. session_search returns empty results for affected conversations with zero indication anything went wrong.

In our deployment, ~48% of sessions (65 out of 135) were missing from the FTS5 index. The JSON session files were written normally (separate code path via _save_session_log), but the SQLite store got nothing.

Root Cause

When the gateway restarts while a CLI session is active (or any DB lock contention during init), SessionDB() raises an exception that gets caught and swallowed:

# cli.py:1185-1190
self._session_db = None
try:
    from hermes_state import SessionDB
    self._session_db = SessionDB()
except Exception:
    pass  # <-- session silently becomes unsearchable

The agent runs fine — JSON logs are written to disk — but _session_db stays None, so _flush_messages_to_session_db() short-circuits on every turn and no messages reach FTS5.

Changes

  • cli.py: Log WARNING (not debug/pass) when SessionDB init fails at both __init__ and _start_session entry points
  • run_agent.py: Log WARNING on create_session, append_message, and compression split failures
  • run_agent.py: Set _session_db = None after create_session failure — fail fast instead of silently dropping every message for the rest of the session

Impact

Minimal — only changes log levels and adds one None assignment. No behavioral change for the happy path. Users will now see a clear warning when session indexing fails instead of discovering it hours/days later when session_search returns nothing.

…ta loss

SessionDB initialization and operation failures were logged at debug level
or silently swallowed, causing sessions to never be indexed in the FTS5
database. This made session_search unable to find affected conversations.

In practice, ~48% of sessions can be lost without any visible indication.
The JSON session files are still written (separate code path), but the
SQLite/FTS5 index gets nothing — making session_search return empty results
for affected sessions.

Changes:
- cli.py: Log warnings (not debug) when SessionDB init fails at both
  __init__ and _start_session entry points
- run_agent.py: Log warnings on create_session, append_message, and
  compression split failures
- run_agent.py: Set _session_db = None after create_session failure to
  fail fast instead of silently dropping every message for the session

Root cause: When gateway restarts or DB lock contention occurs during
SessionDB() init, the exception is caught and swallowed. The agent
continues running normally — JSON session logs are written to disk —
but no messages reach the FTS5 index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant