fix(server): wrap sync blocking calls in asyncio.to_thread for search/recall path#1068
Open
mobilebarn wants to merge 1 commit intovolcengine:mainfrom
Open
fix(server): wrap sync blocking calls in asyncio.to_thread for search/recall path#1068mobilebarn wants to merge 1 commit intovolcengine:mainfrom
mobilebarn wants to merge 1 commit intovolcengine:mainfrom
Conversation
…/recall path Under single-worker uvicorn, synchronous blocking calls in async handlers starve the event loop and cause the server to become unresponsive (TCP accepts but HTTP never responds). Changes: - retrieve/hierarchical_retriever.py: Wrap embedder.embed() and rerank_batch() in asyncio.to_thread(); convert _rerank_scores to async - storage/viking_vector_index_backend.py: Wrap _adapter.query() in asyncio.to_thread() - storage/viking_fs.py: Wrap agfs.stat/read calls in abstract(), overview(), and _read_relation_table() with asyncio.to_thread() These calls make synchronous HTTP requests (OpenAI embedding API), file I/O (AGFS), and database queries that block the event loop for 100-500ms+ per call. Under concurrent auto-recall + auto-capture load, this reliably deadlocks the server within 10-40 minutes. Tested: Server remains responsive under sustained auto-recall load with these patches applied (previously hung within 10-40 minutes). Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
Failed to generate code suggestions for PR |
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.
Problem
Under single-worker uvicorn, the OpenViking server becomes unresponsive (TCP accepts, HTTP never responds) within 10-40 minutes of normal operation. This happens when auto-recall search and auto-capture commit operations overlap.
Root Cause
Several synchronous blocking calls are made from inside
async defhandlers:embedder.embed()inhierarchical_retriever.py— synchronous HTTP call to OpenAI embedding API_adapter.query()inviking_vector_index_backend.py— synchronous storage queryrerank_batch()inhierarchical_retriever.py— synchronous HTTP call viarequests.request()agfs.stat/readinviking_fs.py— synchronous file I/O inabstract(),overview(),_read_relation_table()Each call blocks the event loop for 100-500ms+. Under concurrent load, the health endpoint never gets a timeslot and the server appears hung.
Fix
Wrap all sync blocking calls in
asyncio.to_thread()so they run in the default thread pool executor without blocking the event loop.Testing
Files Changed
openviking/retrieve/hierarchical_retriever.py— embed + rerank → to_threadopenviking/storage/viking_vector_index_backend.py— query → to_threadopenviking/storage/viking_fs.py— agfs.stat/read → to_thread