Skip to content

fix(state): add missing thread lock to session_count() and message_count() - #2131

Closed
nidhi-singh02 wants to merge 1 commit into
NousResearch:mainfrom
nidhi-singh02:fix/state-session-message-count-missing-lock
Closed

fix(state): add missing thread lock to session_count() and message_count()#2131
nidhi-singh02 wants to merge 1 commit into
NousResearch:mainfrom
nidhi-singh02:fix/state-session-message-count-missing-lock

Conversation

@nidhi-singh02

@nidhi-singh02 nidhi-singh02 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • SessionDB.session_count() and SessionDB.message_count() accessed self._conn without self._lock, unlike all 22 other database methods in the class
  • Wraps both methods with with self._lock: to match the existing thread-safety pattern

Context

The class docstring promises: "Thread-safe for the common gateway pattern (multiple reader threads, single writer via WAL mode)." These two utility methods were the only ones missing the lock, creating a race condition risk in the gateway's multi-threaded environment.

Test plan

  • Verify session_count() and message_count() still return correct results
  • Confirm no deadlocks by running gateway with multiple platforms

Fixes #2130

🤖 Generated with Claude Code

…unt()

SessionDB promises thread-safety but these two methods accessed self._conn
without self._lock, unlike all 22 other database methods in the class.

Fixes NousResearch#2130

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@teknium1

Copy link
Copy Markdown
Contributor

Closing — duplicate of another open PR addressing the same issue.

@teknium1 teknium1 closed this Mar 22, 2026
@nidhi-singh02

Copy link
Copy Markdown
Contributor Author

Closing — duplicate of another open PR addressing the same issue.

I guess you are referring to #2288, the current PR was raised one day earlier.

Not sure, why all my PRs were sidelined, even though I was the first to raise and fix the issue :(
@teknium1

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.

Bug: session_count() and message_count() missing thread lock

2 participants