Skip to content

[FEATURE] Image generation has no stop button, only video does #8187

Closed

Description

@LeoBorcherding

Video generation can be cancelled. Image generation cannot. Once a run starts, the only way out is shutting down Studio, which on a bad plan means sitting through a generation that is actively swapping the machine.

What exists today

path backend cancel route UI control
video generate yes, cancel_event threaded into _run_generate POST /api/inference/video/generate/cancel yes (cancelVideoGeneration, video/api.ts:209)
diffusion training yes POST /api/train/diffusion/stop yes (stopDiffusionTraining, images/api.ts:441)
image generate no none none

studio/backend/core/inference/diffusion.py does have cancel_event plumbing, but every one of its uses is on the load/download path (load_pipeline and prefetch, roughly lines 850 to 1347, plus the eject at 3869). Nothing reaches the sampling loop. So you can cancel a model download and not the generation it was downloaded for.

images-page.tsx has no stop control either. The cancelled identifiers in that file are all React effect-cleanup flags, not user-facing.

Ask

Mirror the video path, which is the reference implementation:

  1. Thread a cancel_event through the image generate call and check it at the step boundary in the denoise loop.
  2. Add POST /api/inference/diffusion/generate/cancel alongside the video one.
  3. Add the Stop control to the Create panel, replacing Generate while a run is in flight, same as video.

Every affected surface: Create, Transform, Inpaint, Extend, Upscale. All of them run the same generate path and none can be stopped.

Best-effort at the next step boundary is fine, matching video's documented behaviour. A stop that lands within one step is the difference between recovering a wedged machine and force-quitting.

Activity

  1. danielhanchen commented on Aug 9, 2026

    @danielhanchen
    Member

    Thanks for the map, it made this quick to check. One part of the diagnosis does not hold, and it is good news.

    The image sampling loop is already cancel-aware. DiffusionBackend.generate() creates a per-generation threading.Event, registers it as _active_generate_cancel under _lock, checks it inside the callback_on_step_end closure and sets diffusers' _interrupt, then re-checks it after each chunk so a partial batch is discarded rather than persisted. The native SdCppDiffusionBackend has the same plumbing, and its runner kills the sd-cli process tree on the event. /images/generate even maps the cancelled sentinel to a 409 already. So "nothing reaches the sampling loop" is not right; what was missing was any way for a user to set that event, since only unload() and a superseding load could.

    Everything else held. No route, no UI control, and the cancelled identifiers in images-page.tsx are indeed just effect-cleanup flags. Mirroring video was the right instinct.

    That makes the fix small: a public cancel_generate() on both engines, POST /api/inference/images/generate/cancel, and the Stop control. I used images/... rather than the diffusion/... you suggested, only because every other route on that page is under images/.

    One thing your report did not mention that mattered: a generate request is a loop of count backend calls, and the backend cancel only reaches the denoise running right now. Without a latch in the page, pressing Stop on run 1 of 4 would have immediately started run 2, which is exactly the "machine keeps swapping" case you were trying to escape. That is handled.

    On the things you asked to settle rather than assume:

    • A cancelled run leaves no gallery entry and no partial image; the post-chunk check raises before anything is persisted. Progress state is cleared on every exit so the page cannot stay stuck at "generating".
    • The pipeline is not left half-released. Images unwind through diffusers' cooperative _interrupt, so pipe() returns normally and runs its own maybe_free_model_hooks(). This is the better of the two paths: video has no cooperative interrupt on its non-callback families, so it unwinds by exception and has to free the hooks by hand or leave onloaded modules on the GPU. You asked me to say so rather than copy it silently, so: that is a real wart on the video side, not something worth reproducing here.
    • Cancelling mid-VAE-decode is not reachable, on images or on video. There is no callback inside the decode, so a Stop pressed during it lands when the decode finishes. Best effort at the next step boundary, as documented.

    Driven in a real browser on all five surfaces (Create, Transform, Inpaint, Extend, Upscale), plus an API pass at 100 steps where Stop landed at steps 3 to 5 with the run unwinding in 0.2 to 0.7 seconds and nothing persisted. Details and screenshots are on the PR.

    PR: #8219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions