fix(api): run single-video delete/update off the event loop - #9392
Merged
lstein merged 2 commits intoAug 9, 2026
Merged
Conversation
`delete_video` and `update_video` were declared `async def` while doing blocking SQLite and filesystem work. FastAPI runs an `async def` handler directly on the event loop, so each call stalled every other request and socket event for its duration. Their batch siblings (`delete_videos_from_list`, `star_videos_in_list`, `unstar_videos_in_list`, `delete_uncategorized_videos`) were already converted to sync `def` — which FastAPI offloads to the threadpool — during the invoke-ai#9163 review; these two single-item routes were deferred to this follow-on. Deferred non-blocker from PR invoke-ai#9163. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lstein
requested review from
JPPhoto,
Pfannkuchensack,
blessedcoolant and
dunkeroni
as code owners
July 28, 2026 00:51
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
Follow-on to #9163 (deferred non-merge-blocker).
delete_videoandupdate_videoininvokeai/app/api/routers/videos.pywere declaredasync defbut do only blocking work — a SQLite lookup, a SQLite write, and (for delete) file removal. FastAPI runs anasync defhandler directly on the event loop, so each of these calls stalled every other HTTP request and socket event for its duration. A syncdefhandler is offloaded to the threadpool instead.Their batch siblings —
delete_videos_from_list,delete_uncategorized_videos,star_videos_in_list,unstar_videos_in_list— were already converted to syncdefduring the #9163 review (11b38696bf). These two single-item routes were the leftovers.Changes
delete_video,update_video:async def→def, with a comment recording why.test_single_video_mutations_are_offloaded_by_fastapi, mirroring the existingtest_video_batch_mutations_are_offloaded_by_fastapiguard so a future edit can't silently reintroduceasync def.No behavior change beyond scheduling: neither handler contained an
await, and the request/response contract is untouched (no OpenAPI change, no frontend change).Out of scope
The remaining
async defhandlers invideos.py(the GET routes, the board association routes) share the same pattern, as does the whole ofimages.py/board_images.py— that's the pre-existing codebase-wide convention and converting it is a much larger, separate change. This PR closes the specific gap where video routes were left internally inconsistent.Testing
pytest tests/app/routers/test_videos_multiuser.py— 51 passed.🤖 Generated with Claude Code