Skip to content

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

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

fix(state): add missing thread locks to 4 SessionDB methods#1704
teknium1 merged 1 commit into
mainfrom
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
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…te-thread-locks

fix(state): add missing thread locks to 4 SessionDB methods
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…te-thread-locks

fix(state): add missing thread locks to 4 SessionDB methods
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…te-thread-locks

fix(state): add missing thread locks to 4 SessionDB methods
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…te-thread-locks

fix(state): add missing thread locks to 4 SessionDB methods
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 2026
…te-thread-locks

fix(state): add missing thread locks to 4 SessionDB methods
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