Skip to content

⚡ Bolt: Offload synchronous SQLite persistence calls to avoid blocking event loop#82

Open
Adityasingh-8858 wants to merge 1 commit into
mainfrom
bolt/offload-sync-sqlite-8555564245407436068
Open

⚡ Bolt: Offload synchronous SQLite persistence calls to avoid blocking event loop#82
Adityasingh-8858 wants to merge 1 commit into
mainfrom
bolt/offload-sync-sqlite-8555564245407436068

Conversation

@Adityasingh-8858
Copy link
Copy Markdown
Collaborator

💡 What
Wrapped all direct SQLite persistence calls (create_transfer_record, set_agent_b, list_transfers, get_transfer) in backend/main.py using await asyncio.to_thread(). Added an entry to Bolt's journal (.jules/bolt.md) explaining the rationale.

🎯 Why
Executing standard Python synchronous SQLite operations inside FastAPI async def endpoints blocks the entire asyncio event loop for the duration of the disk I/O. By offloading these operations to a thread pool with asyncio.to_thread, the main event loop remains free to handle concurrent incoming requests, significantly improving the backend's concurrency and responsiveness.

📊 Impact
Prevents event loop starvation during database reads/writes. In high-concurrency situations, this allows the server to process concurrent API requests rather than blocking all connections while waiting for a single synchronous disk write to complete.

🔬 Measurement
Run the server under load or use a script (e.g. test_persistence_sync.py) to verify that async tasks (like a heartbeat printer) continue firing seamlessly while database writes are occurring, confirming the event loop is no longer blocked. Verified all automated pytest suites passed flawlessly.


PR created automatically by Jules for task 8555564245407436068 started by @Deepaksingh7238

…g event loop

Co-authored-by: Deepaksingh7238 <110552872+Deepaksingh7238@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 17:06
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves FastAPI backend responsiveness by moving synchronous SQLite persistence operations off the asyncio event loop and into a thread pool, preventing event-loop blocking during DB reads/writes.

Changes:

  • Offloaded SQLite writes (create_transfer_record, set_agent_b) to await asyncio.to_thread(...) in async endpoints.
  • Offloaded SQLite reads (list_transfers, get_transfer) to await asyncio.to_thread(...) to avoid blocking under concurrent load.
  • Added a Bolt journal entry documenting the rationale and the recommended pattern going forward.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backend/main.py Wrapes synchronous persistence calls in asyncio.to_thread within async FastAPI endpoints to avoid blocking the event loop.
.jules/bolt.md Documents the learning and standard action (“always offload sync SQLite calls”) for future changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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