1 Commits

Author SHA1 Message Date
Bingxi Zhao (Frank)
f342281f33 fix(knowledge): keep batch uploads off the event loop (#777)
Batch-uploading files stalled every other request — chat WebSockets included
— for the whole duration of the batch. Two blocking paths, both in an async
context:

* ``_save_uploaded_files`` blocks end to end (a chunked write of every
  uploaded byte, zip extraction, plus a synchronous HTTP upload per file
  when PocketBase is on) and was called inline from the upload and
  create-KB routes;
* the follow-up work runs in a FastAPI ``BackgroundTasks`` entry declared
  ``async def``, which starlette awaits ON the loop — only *sync* callables
  reach its threadpool — so the staging pass (a full-content hash per file
  plus a copy) and the per-file re-hash blocked there too.

Each of those moves to a worker thread. Reading ``UploadFile.file`` off-loop
is safe: it is the plain SpooledTemporaryFile, never the async API. The
provider index itself already ran through an executor, and the remaining
small JSON writes are left inline rather than paying a thread hop each.
2026-08-07 21:09:20 +08:00