Skip to content

fix(state): release lock between context queries in search_messages#3035

Closed
Kewe63 wants to merge 1 commit into
NousResearch:mainfrom
Kewe63:fix/search-messages-lock-scope
Closed

fix(state): release lock between context queries in search_messages#3035
Kewe63 wants to merge 1 commit into
NousResearch:mainfrom
Kewe63:fix/search-messages-lock-scope

Conversation

@Kewe63

@Kewe63 Kewe63 commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

The per-match context-window queries in search_messages() (one SQLite
round-trip per FTS5 result) were running inside the same outer
with self._lock: block as the primary FTS5 query, holding the lock
for O(N) sequential I/O. This blocked all other threads (message writes,
session updates) for the entire duration of a search with many results.

Moved the per-match context fetches outside the outer lock so each
query acquires the lock independently, keeping critical sections short
and allowing other threads to interleave.

Test plan

  • Run search_messages with multiple results and verify context rows are correct
  • Verify concurrent writes are not blocked during a search

The context-window queries (one per FTS5 match) were running inside
the same lock acquisition as the primary FTS5 query, holding the lock
for O(N) sequential SQLite round-trips. Move per-match context fetches
outside the outer lock block so each acquires the lock independently,
keeping critical sections short and allowing other threads to interleave.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #3249. Your substantive commit (58a17fca) was cherry-picked onto current main with authorship preserved. The search_messages lock scope fix ships alongside two complementary SQLite concurrency fixes. Thanks @Kewe63!

@teknium1 teknium1 closed this Mar 26, 2026
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.

2 participants