fix(sqlite): add PRAGMA busy_timeout=30000 to all thread-local store connections - #942
Open
bradbrok wants to merge 1 commit into
Open
fix(sqlite): add PRAGMA busy_timeout=30000 to all thread-local store connections#942bradbrok wants to merge 1 commit into
bradbrok wants to merge 1 commit into
Conversation
…connections The 5-second default SQLite busy timeout (sqlite3.connect default) is insufficient when multiple FastAPI worker threads write concurrently to the same database — the serialized write queue can exceed 5 s under moderate load or on slower disk (e.g. Pi, constrained containers). Adds PRAGMA busy_timeout=30000 (30 s) after journal_mode=WAL on every per-thread connection opened by the 13 stores converted to thread-local connections in #929/#933/#934/#937. Fixes test_mixed_crud_hammer_uses_ thread_local_connections which was failing reproducibly in this environment with OperationalError('database is locked'). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019E6DxbrbMeuTFwTTBVEqbC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sqlite3.connect()busy timeout (5 s) isn't enough when multiple FastAPI worker threads write to the same database concurrently: the serialised write queue can exceed 5 s under moderate load or on slower disks (Pi, constrained containers, remote execution environments).PRAGMA busy_timeout=30000(30 s) right afterPRAGMA journal_mode=WALon every per-thread connection opened by the 13 stores converted to thread-local connections in Make task store SQLite connections thread-local #929/Make hot SQLite stores thread-local #933/Make four more SQLite stores thread-local #934/Make five more SQLite stores thread-local #937.test_mixed_crud_hammer_uses_thread_local_connectionsfailing reproducibly withOperationalError('database is locked')across 10/12 worker threads. Test now passes (57 s wall-clock for 12 threads × 25 write rounds).Files changed: activity_store, agent_comms, conversation_store, dream_runner, hooks, presentation_store, research_store, session_store (both store classes), skill_store, task_store, trigger_store, user_profile_store, voice_store — one line added per
_dbproperty.Test plan
test_mixed_crud_hammer_uses_thread_local_connections— was failing, now passestests/pinky_federation/(152 tests) — still passingruff checkclean on all changed filesGenerated by Claude Code