Skip to content

sd: cancel image generation on client disconnect#2318

Merged
LostRuins merged 1 commit into
LostRuins:concedo_experimentalfrom
wbruna:sd_disconnect_cancel
Jul 11, 2026
Merged

sd: cancel image generation on client disconnect#2318
LostRuins merged 1 commit into
LostRuins:concedo_experimentalfrom
wbruna:sd_disconnect_cancel

Conversation

@wbruna

@wbruna wbruna commented Jul 9, 2026

Copy link
Copy Markdown

Detects client disconnection on the image generation endpoints, and calls sd_cancel_generation to avoid running the next steps.

LostRuins/stable-ui#25 is still needed for the Cancel button.

Spectrum enabled - w: 0.40, m: 3, lam: 1.00, window: 2, flex: 0.50, warmup: 4, stop: 90%
  |======>                                           | 1/8 - 4.40s/it
Client disconnected unexpectedly, aborting...
  |============>                                     | 2/8 - 4.32s/it
cancelling generation
Diffusion model sampling failed
sampling for image 1/1 failed after 8.73s
KCPP SD generate failed!
127.0.0.1 - - [09/Jul/2026 18:16:11] "POST /sdapi/v1/txt2img HTTP/1.1" 200 -
[Errno 32] Broken pipe
Generate Image: The response could not be sent, maybe connection was terminated?

@wbruna wbruna force-pushed the sd_disconnect_cancel branch from 063a729 to 922cb41 Compare July 10, 2026 21:36

@LostRuins LostRuins left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

quick tests seem to work

@LostRuins LostRuins merged commit c43c27c into LostRuins:concedo_experimental Jul 11, 2026
@LostRuins

Copy link
Copy Markdown
Owner

One potential regression: previously the user would be able to recover from a browser crash using the "recover last image" feature, that will not be possible anymore as the connection loss would prevent the generation from completing.

image

So now if firefox.exe crashes or closes, they will lose the in-progress image.
Ideally, the abort should be explicit rather than implicit.

@wbruna

wbruna commented Jul 11, 2026

Copy link
Copy Markdown
Author

I would argue that the new behavior makes more sense, at least by default, because the image recovering functionality only works with the stable-ui. It won't work with any other API user, or with Lite.

Also, a long-running image gen blocks the server from accepting any other gen until it finishes: if we generate a 100-step image by mistake (and again, it could happen with another UI), the only way to stop it is interrupting the server. Cancelling with a client disconnect is what any synchronous, session-less API would expect.

The recovery functionality also feels like a stopgap: it doesn't integrate with the rest of the UI (the image isn't included to the gallery, and its metadata isn't recovered). The reconnected client also have to blindly wait for the gen to finish (or save the url, run another gen, and refresh the url as soon as it begin - assuming it would work with the current id handling).

Anyway, since the functionality is tied to client support, it seems to me its behavior should be triggered by an API field. We configure the stable-ui to send a boolean 'keep generating on disconnect', signalling to the server that the behavior is desired and the client supports it. And stable-ui would persist that flag as a config.

@wbruna

wbruna commented Jul 11, 2026

Copy link
Copy Markdown
Author

I went ahead and added an API field: #2322 .

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants