Repository navigation
comfyui-media: a dropped request interrupts its own GPU job - #63
Merged
Merged
Conversation
Starlette does not cancel a plain handler when its client disconnects, so a video request the client gave up on kept the GPU busy until the clip was done and was then thrown away. The Media Studio Director now cancels a speculative next-shot render when the shot before it fails review; without this it would cost a full render of dead GPU time each time. - The video route watches for http.disconnect and cancels the generation. - A cancelled generation that reached Comfy now sends the targeted queue delete and /interrupt for its own prompt id, then holds the slot (busy, not quarantined) until history proves the job ended, as before. - comfyui-media image pin updated for the new bridge source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
Starlette does not cancel a plain FastAPI handler when its client disconnects. When a client gave up on a video request (the gateway aborts its upstream fetch), the bridge kept generating until the clip was done, then threw it away. Meanwhile, every new request got
429 busy.The Media Studio Director now starts the next shot's render while it reviews the previous take, and cancels it when that review fails. Without this change, each of those cancellations wastes a full render of GPU time (~140 s for an 8 s H3 Turbo shot).
What
server.py: the video route runs the generation under_until_disconnect. It pollsrequest.is_disconnected()once a second and cancels the generation when the client hangs up. The response is a 499 that nobody reads.jobs.py: when a cancelled generation has already reached Comfy, it now schedules_interrupt_and_reap. That sends the existing targetedcancel_own_job(pending delete plus/interruptfor our own prompt id), then runs the ordinary reaper. The slot stays busy, not quarantined, until history proves the job ended. The no-second-GPU-job guarantee is unchanged.comfyui-mediaimage pin is updated in all 16 ComfyUI recipes for the new bridge source.Tests
scripts/test-comfyui-media.py(pinned requirements-test venv): 312 passed. New tests:test_cancelled_request_interrupts_its_jobtest_client_disconnect_cancels_the_generation(raw ASGIhttp.disconnect)test_cancelled_request_keeps_slot_until_terminalnow models an interrupt that lands at the next sampler step.node test/comfyui-media.test.mjspasses.Not yet deployed. ennspark03 needs the comfyui-media image rebuilt and the H3 runtime recreated.
🤖 Generated with Claude Code