Skip to content

fix(api): run single-video delete/update off the event loop - #9392

Merged
lstein merged 2 commits into
invoke-ai:mainfrom
lstein:fix/video-single-item-routes-block-event-loop
Aug 9, 2026
Merged

fix(api): run single-video delete/update off the event loop#9392
lstein merged 2 commits into
invoke-ai:mainfrom
lstein:fix/video-single-item-routes-block-event-loop

Conversation

@lstein

@lstein lstein commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-on to #9163 (deferred non-merge-blocker).

delete_video and update_video in invokeai/app/api/routers/videos.py were declared async def but do only blocking work — a SQLite lookup, a SQLite write, and (for delete) file removal. FastAPI runs an async def handler directly on the event loop, so each of these calls stalled every other HTTP request and socket event for its duration. A sync def handler 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 sync def during the #9163 review (11b38696bf). These two single-item routes were the leftovers.

Changes

  • delete_video, update_video: async defdef, with a comment recording why.
  • New test_single_video_mutations_are_offloaded_by_fastapi, mirroring the existing test_video_batch_mutations_are_offloaded_by_fastapi guard so a future edit can't silently reintroduce async 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 def handlers in videos.py (the GET routes, the board association routes) share the same pattern, as does the whole of images.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

`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>
@github-actions github-actions Bot added api python PRs that change python files python-tests PRs that change python tests labels Jul 28, 2026
@lstein lstein added the 6.14.1 label Jul 28, 2026
@lstein lstein moved this to 6.14.1: Bug fixes to 6.14.0 in Invoke - Community Roadmap Jul 28, 2026

@JPPhoto JPPhoto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@lstein
lstein merged commit c7de47b into invoke-ai:main Aug 9, 2026
17 checks passed
@lstein
lstein deleted the fix/video-single-item-routes-block-event-loop branch August 9, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.14.1 api python PRs that change python files python-tests PRs that change python tests

Projects

Status: 6.14.1: Bug fixes to 6.14.0

Development

Successfully merging this pull request may close these issues.

2 participants