fix(conversation): serialize parallel writes to prevent pool contention#3023
Draft
amitksingh1490 wants to merge 4 commits intomainfrom
Draft
fix(conversation): serialize parallel writes to prevent pool contention#3023amitksingh1490 wants to merge 4 commits intomainfrom
amitksingh1490 wants to merge 4 commits intomainfrom
Conversation
|
Amit seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
…ites SQLite only allows one writer at a time, so per-conversation locking was ineffective. Changed to a single global write lock that serializes ALL database write operations (upsert, delete) across all conversations. This prevents pool exhaustion when multiple concurrent tasks attempt writes - only one write hits SQLite at a time, preventing the scenario where tasks hold pooled connections while waiting for SQLite's single writer lock. Also removes unused dashmap dependency. Fixes #3021 Co-Authored-By: ForgeCode <noreply@forgecode.dev>
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
Fix SQLite pool contention causing "Failed to get connection from pool: timed out waiting for connection" errors by using a global write lock to serialize all database writes.
Context
Users reported intermittent pool timeout errors when running multiple parallel subagents. The root cause is SQLite's fundamental constraint: only one writer is allowed at a time, even in WAL mode.
The issue occurs when:
Previous incorrect approach: Per-conversation write serialization (doesn't solve the problem since SQLite locks the entire DB, not per-conversation).
Correct approach: Global write lock that serializes ALL writes across all conversations.
Resolves #3021.
Changes
What Changed
spawn_blockingto prevent async runtime thread starvationWhy Global Locking Works
SQLite's single-writer limitation means:
By serializing at the application layer:
Impact
Before the Fix
Under parallel write pressure (16 tasks × 10 writes each):
After the Fix
Same workload now achieves:
Benchmark Results
Benchmark: Parallel writes via SQLite-backed persistence path with pool size=5, connection timeout=5s
Testing
Use Cases
Links