Skip to content

fix(state): add missing thread locks to 4 SessionDB methods#1704

Merged
teknium1 merged 1 commit intomainfrom
fix/hermes-state-thread-locks
Mar 17, 2026
Merged

fix(state): add missing thread locks to 4 SessionDB methods#1704
teknium1 merged 1 commit intomainfrom
fix/hermes-state-thread-locks

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Four SessionDB methods accessed self._conn without acquiring self._lock, while every other method in the class consistently uses the lock:

  • search_sessions() — reads sessions table
  • clear_messages() — deletes messages + updates session counters + commits
  • delete_session() — checks existence + deletes messages + deletes session + commits
  • prune_sessions() — selects old sessions + deletes messages + deletes sessions + commits

In the gateway's multi-threaded context (concurrent messages from different platforms/users), these unprotected methods can cause sqlite3.ProgrammingError from concurrent cursor operations on the same connection.

What changed

  • hermes_state.py: Wrapped each method body in with self._lock:

Test plan

  • python -m pytest tests/test_hermes_state.py -n0 -q → 109 passed ✔
  • Gateway under concurrent load: no more intermittent SQLite errors on session cleanup/listing
search_sessions(), clear_messages(), delete_session(), and
prune_sessions() all accessed self._conn without acquiring self._lock.
Every other method in the class uses the lock. In multi-threaded
contexts (gateway serving concurrent platform messages), these
unprotected methods can cause sqlite3.ProgrammingError from concurrent
cursor operations on the same connection.
@teknium1 teknium1 merged commit ed3bcae into main Mar 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant