Skip to content

Studio: let image generation be stopped - #8219

Merged
danielhanchen merged 14 commits into
mainfrom
i8187-image-cancel
Aug 9, 2026
Merged

danielhanchen merged 14 commits into
mainfrom
i8187-image-cancel

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Fixes #8187.

Video generation can be stopped; image generation could not. Once a run started the only way out was shutting Studio down, which on a bad memory plan means sitting through a generation that is actively swapping the machine.

What was actually missing

The reporter's map said the image path has no backend cancellation and that "nothing reaches the sampling loop". That part is not right, and it makes the fix much smaller than the issue implies.

DiffusionBackend.generate() already creates a per-generation threading.Event, registers it as _active_generate_cancel under _lock, checks it in the callback_on_step_end closure (setting diffusers' _interrupt), and 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. The route even maps the cancelled sentinel to a 409 already.

The only things missing were the ways to set that event from outside: nothing but unload() and a superseding load could reach it, there was no route, and there was no control. So this adds those three, and nothing in the sampler changes.

Changes

  • DiffusionBackend.cancel_generate() and SdCppDiffusionBackend.cancel_generate(), both mirroring VideoBackend.cancel_generate(): set the registered event under _lock, return False when nothing is running.
  • POST /api/inference/images/generate/cancel, resolved through the engine router so it stops a diffusers denoise and a native sd.cpp run alike. Named images/... to match every other route on this page rather than the diffusion/... the issue guessed at.
  • A Stop control on the Images page that replaces Generate while a run is in flight, same shape as the video page's Cancel.
  • A stop latch in the page's run loop. A generate request is a loop of count backend calls, but the backend cancel only reaches the denoise running right now, so without the latch pressing Stop on run 1 of 4 would immediately start run 2. The latch also suppresses the cancelled sentinel's toast, since the user asked for it.

_is_inference_path already excluded */cancel by construction (it matches on endswith), so the cancel request is not tracked as an inference request and cannot pin the model it just stopped. That is now asserted rather than assumed.

Every surface, not just Create

All seven workflows (Create, Transform, Inpaint, Extend, Upscale, plus Reference and Edit) funnel through the one generate() and the one floating action button, so one control covers all of them. Verified per surface rather than argued:

Driven against a live Studio with unsloth/Z-Image-Turbo-GGUF Q4_K_S on CUDA, 100 steps at 1024x1024, pressing Stop once the sampler was past step 3:

surface steps stopped at step cancel HTTP generate HTTP detail unwind s new gallery records
Create 100 4 200 {"cancelled": true} 409 Diffusion generation was cancelled. 0.69 0
Transform 100 3 200 {"cancelled": true} 409 Diffusion generation was cancelled. 0.22 0
Inpaint 100 5 200 {"cancelled": true} 409 Diffusion generation was cancelled. 0.20 0
Extend 100 4 200 {"cancelled": true} 409 Diffusion generation was cancelled. 0.43 0
Upscale 100 3 200 {"cancelled": true} 409 Diffusion generation was cancelled. 0.23 0

The step column is the point: the sampler stopped, it did not finish. A 200 from the route would not have shown that.

What a cancelled run leaves behind

Settled rather than assumed:

  • No gallery entry and no partial image. The post-chunk check raises before images.extend(out), so nothing reaches the persist step.
  • The published progress state is cleared in generate()'s outer finally on every exit, so the page does not stay stuck at "generating".
  • The event is deregistered on exit, so a second Stop answers False instead of poking a finished run.
  • The pipeline is not half-released. Images unwind through diffusers' cooperative _interrupt, so pipe() returns normally and the pipeline 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 call maybe_free_model_hooks() by hand or leave onloaded modules on the GPU. Worth saying out loud since the issue asked us to mirror video and not copy a flaw silently.
  • Cancelling mid-VAE-decode is not reachable, on images or on video. There is no callback inside the decode, so a Stop pressed during the decode lands when the decode finishes. Best effort at the next step boundary, as documented.

Tests

  • cancel_generate across every workflow, with a stepping fake pipeline that honours _interrupt, asserting the run stopped short of its step count, raised the sentinel, produced no images and cleared progress.
  • The step-boundary contract pinned exactly: a cancel raised during step index 1 lets step 2's callback observe it and nothing after.
  • The same on the native engine, cancelled from another thread mid-run.
  • Route round-trips: idle reports False, an in-flight generation is stopped and reports True, the generate unwinds as 409 with an empty gallery, and the route sits behind auth.
  • The run-loop latch and the cancelled-toast suppression on the frontend.

Ten mutations, all killed: cancel_generate not setting the event; cancel_generate always reporting idle; the _interrupt set removed from the step callback; the post-chunk cancel check removed; the native cancel not setting its event; the cancel path counted as an inference request; the route's auth dependency dropped; the run loop ignoring the latch; the latch no longer suppressing the toast; and every failure suppressed. Suite green after restoring.

Backend suite line sets are identical to the merge-base baseline (86 pre-existing FAILED/ERROR lines either side, 12 more tests passing). hub/tests 304 passed. Frontend typecheck clean, no new lint.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 631ad3e393

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const handleCancelGenerate = useCallback(async () => {
cancelRequested.current = true;
try {
await cancelDiffusionGeneration();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle Stop before the backend registers generation

If the user presses Stop immediately after the button appears, the generate fetch may have started but not yet registered _active_generate_cancel; the cancel endpoint then returns {cancelled: false}, which is ignored here. The latch cannot stop this first request because the loop already passed its pre-request check, so the full generation continues despite Stop. Preserve a cancellation request across this startup race, for example by associating it with the generate request or retrying until that request registers or settles.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not taking this one. The window is real in the code but not reachable in a session, and every remedy for it is a worse bug.

Timing: handleGenerate sets busy to generating and issues the POST in the same tick, so the Stop button is painted no earlier than the next frame, while the backend registers _active_generate_cancel at the very top of generate() (diffusion.py, immediately inside _generate_lock under _lock, before any prompt encoding or setup) and the route does nothing but asyncio.to_thread(backend.generate, ...) first. So the gap is one localhost round trip plus a thread handoff, and it has closed before the button a user must see and react to is even on screen. The reverse case, a Stop pressed while another client holds _generate_lock, needs a second concurrent generator and is out of scope here.

The remedies are the problem. A sticky cancel that the next generate() consumes turns a Stop the backend correctly answered false into a cancellation of a later, unrelated generation, which is a call dropped rather than one preserved. A retry-until-registered loop has the same hazard with a timer attached: on a count > 1 run it would land on run i+1, which the latch already stopped by other means. Neither trade is worth closing a gap narrower than a frame.

What is already covered: cancelRequested latches before the POST, so every remaining run of a count > 1 request stops regardless of what the cancel endpoint answered, and the catch around cancelDiffusionGeneration documents exactly the never-landed case. I did take the other item on this PR, the post-denoise recheck, which is the same class of disagreement but genuinely reachable.

@danielhanchen

Copy link
Copy Markdown
Member Author

Browser evidence, since a route returning 200 is not proof the sampler stopped.

One headless Chromium session against a live Studio built from this branch, unsloth/Z-Image-Turbo-GGUF Q4_K_S on CUDA, real clicks on the real page. Each tab was made generate-ready the way a user would (source image uploaded through the file input, a mask painted on the inpaint canvas with real pointer events, an expand amount set on Extend, a scale factor on Upscale), then Generate, then Stop once the sampler was past step 3.

tab button while running step when Stop was pressed back to Generate generate-progress after gallery delta toast
Create Stop 10 / 50 yes, 0.68s active: false 0 none
Transform Stop 10 / 50 yes, 1.46s active: false 0 none
Inpaint Stop 10 / 50 yes, 0.67s active: false 0 none
Extend Stop 10 / 50 yes, 1.76s active: false 0 none
Upscale Stop 10 / 50 yes, 3.95s active: false 0 none

The gallery was empty before and is still empty, so no cancelled run persisted anything.

Run-loop latch, Create with Runs = 3: the button renders as Stop (0/3) while the card reads "Run 1/3, Step 10/50". Stop pressed during run 1 put the button back to Generate in 0.66s, and generate-progress polled at 4 Hz for a further 15 seconds never flipped back to active, so runs 2 and 3 never started. Gallery delta 0.

The "no toast" result is a verified negative rather than an absent check. A control run clicked Generate on Inpaint with no mask painted, and the same toast scanner immediately reported {"type": "error", "text": "Paint a mask over the region to regenerate"}. So the scanner does see error toasts, and its silence after each Stop means the cancelled sentinel is being swallowed as intended. The browser console does log a 409 on every Stop, which is the in-flight generate POST unwinding, not a user-visible error.

Two honest deviations. The Steps slider is capped at 50 in the UI, so the ceiling proved against is 50, not the backend's 100; stopping at step 10 of 50 is still unambiguously mid-sampler. And Z-Image-Turbo denoises fast enough on this card that each run had to be lengthened (larger batch, larger sources) to leave a usable window to click in. The API-level pass in the description used 100 steps and stopped at steps 3 to 5.

Reference and Edit are not covered because this model does not advertise them; they share the same handler and the same button.

The cancel event stayed registered through the compile-cache save, and
generate_progress still read active, so the page still offered Stop. A Stop
pressed there was answered cancelled = true and then contradicted: generate()
returned the images and the route persisted them. A static compile writes a
fresh artifact per shape, so that save is not instant. Recheck the event once
more before returning, so the two answers agree and a cancelled run leaves no
gallery entry.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…executor

The recheck still left the event registered across the generation-count update
and the two adapter helpers that build the result, so Stop could answer true
for a run that then returned its images. Check and deregister under _lock, the
same lock cancel_generate takes, so the two cannot interleave.

The cancel route also shared the default executor with /images/generate, which
occupies a worker for the whole run while it blocks on the serial generate
lock, so concurrent generations could leave a Stop queued until the run it was
meant to stop had finished. It gets its own small pool, like the status probes
above it; not the event loop, since cancelling a native sd.cpp run kills a
process tree.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d37d558ca1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +20723 to +20725
cancelled = await asyncio.get_running_loop().run_in_executor(
_CANCEL_EXECUTOR, get_active_diffusion_engine().cancel_generate
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind cancellation to the requesting generation

With concurrent generation callers, this always cancels the backend's single currently active event rather than the generation owned by the caller. If request A is running while request B is queued on _generate_lock, pressing Stop in B cancels A; B's already-issued request then acquires the lock and continues generating. Pass a generation/request identifier through the generate and cancel endpoints so a queued caller cannot terminate another client's run.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not taking this one. It needs two concurrent generation clients, which is outside what this control is for, and the remedy would change a contract that predates this PR.

/images/generate/cancel is documented as stopping THE in-flight generation, mirroring /video/generate/cancel, and it reaches the same _active_generate_cancel that unload() and a superseding load already set. That is a global control by design, and binding it to a request id would have to change the generate endpoint, the video endpoint that mirrors it, and the unload path, so the three keep agreeing.

In the scenario as described, B is queued and owns no generation yet, so there is nothing of B's to cancel; Stop stopping the run that is actually running is the documented answer, not a misdirected one. B's own later runs are already stopped by the page's latch, which does not depend on the endpoint at all.

Studio drives one generation at a time from the page, so reaching this needs a second tab or an API client generating concurrently, and that same shape is what I declined earlier in this round for the startup race. I would rather leave a global Stop that is honest about being global than add an id handshake across four endpoints for it.

I did take the two concrete items from this round: the native backend's non-atomic deregistration, and the cancel route sharing the generation executor.

…a real error

The native backend had the same gap the diffusers one just closed: its final
cancel check sat outside the lock that clears the event, so a Stop landing
between the two was answered true for a run that then returned its images.
/images/generate/cancel resolves through the engine router, so both engines owe
the same answer; same locked check-and-deregister there now.

On the page, a cancel POST that never landed was treated as handled. The latch
suppresses every later error for the run, not just the cancellation sentinel,
so an OOM raised after a Stop that the server never heard vanished. Track
whether the cancel landed: report the failure when it did not, and let the run
report its own error.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40ccb0c73f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2714 to +2718
} catch {
// The request never landed, so the denoise in flight keeps running. The latch still stops
// the remaining runs, but the click cannot be treated as handled: say so, and stop it
// explaining away an error the run raises later.
cancelFailed.current = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat a lost cancel response as an ambiguous outcome

When the cancel POST reaches the backend and sets the event but its response is dropped by the proxy or connection, this catch incorrectly concludes that the server never received it, sets cancelFailed, and reports that generation is still running. If the original generate request then returns its expected 409, shouldReportGenerateError also exposes the cancellation sentinel as an error because cancelFailed disabled suppression. Fresh evidence versus the earlier cancel-failure comment is that this revision now explicitly equates every fetch rejection with non-delivery, even though the generate API already recognizes that responses can be lost after work reaches the server.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The consequence you name does not happen, so leaving this as is.

shouldReportGenerateError is not gated on stopRequested alone; it falls through to a message test:

if (input.stopRequested) return false;
return !input.message.toLowerCase().includes("cancelled");

So with cancelFailed set and stopRequested therefore passed as false, a 409 carrying DIFFUSION_CANCELLED_MSG ("Diffusion generation was cancelled.") still returns false and is still suppressed. That holds for the native engine too: sd_cpp_backend maps SdCppCancelled to the same sentinel string, so both engines unwind with a message the test catches. The stopRequested branch is the belt to that pair of braces, for a run that unwinds some other way, which is exactly the case where we genuinely do not know whether the stop landed and would rather show the error than swallow it.

What is left is the toast wording overstating non-delivery on a lost response, which is cosmetic and not worth churning the file for. The unambiguous half of that scenario is the retry it enables, and I took that one: cancelDiffusionGeneration now passes retryNetworkErrors: false in 58c8c46.

authFetch retries network errors by default, but this endpoint always targets
whichever generation is active now, so a retry firing up to 1.5s after a lost
response can land on a run the user started in the meantime and stop that one
instead. Cancellation is not retryable the way the idempotent GETs are.

The status refresh also only ran on the successful path. When a native cancel
is not reflected within its grace window, sd_cpp_server stops the server
outright and the backend reloads on the next generate, so a stopped run left
the page showing a model that was gone until the next Generate failed with no
model loaded. Refresh on every exit instead.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… and post one Stop at a time

A fulfilled cancel was treated as an acknowledged one, so a {cancelled: false}
answered while the route was still persisting still silenced the run. If that
persistence then failed the user got neither an image nor an error. Track the
cancelled field instead: only a confirmed stop explains a later error away.

Each extra Stop click also posted again, and a late duplicate can arrive after
the stopped run settled and target whichever generation is running by then. One
request on the wire at a time; the click still latches, as before.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

Before/after from two isolated Studio installs, merge base 8e558606a vs head 58c8c4642. Same scene on both: load unsloth/Z-Image-Turbo-GGUF Q4_K_M, push Steps and Batch size to their maxima, hit Generate, then try to stop it.

Mid-run, the composer action:

After clicking Stop, once generate-progress reports inactive:

Before, the button is a disabled spinner for the whole run and there is no way to end it: still active: true at step 19 after waiting 60 seconds. After, Stop replaces Generate, and 20 seconds later the run is active: false with the button live again. POST /api/inference/images/generate/cancel answers 405 on the base and 200 on the head.

One measurement worth recording, because it surprised me and it shapes what a reviewer should expect. Cancellation latency depends on batch size:

batch time from clicking Stop to active: false
4 about 20 s
1 under 4 s

The cancel lands at a step boundary, and a batched step is slow, so at batch 4 the button sits on Stop for around twenty seconds before settling. That is not a bug in the cancel, but it is long enough that a user may well press it twice and think nothing happened. Worth considering an immediate "Stopping..." state on the button.

A cancel POST outstanding when the run settles (a 401 refresh-and-replay is the
slow case) left the guard set, so the next run's own Stop was dropped before it
was ever sent. Reset it at the start of each run, beside the other two
per-run refs.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The clear ran unconditionally in the finally, so a slow cancel from an earlier
run released the guard a later run had set, and a duplicate click could get
through behind it. The guard now holds the run token that owns the request, and
each cancel clears it only while it still owns it.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd12e7f14f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2583 to +2586
// Per-run, like the two above. A cancel POST still outstanding from the PREVIOUS run (a 401
// refresh-and-replay is the slow case) would otherwise leave the guard set and swallow this
// run's own Stop entirely.
cancelInFlight.current = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep a pending Stop tied to the previous run

When a Stop request is still awaiting authentication refresh or its response, clearing this guard allows the UI to finish the old generation and start another while the old cancel POST remains live. authFetch retries a 401 after refreshing the session, so that delayed POST can then reach /images/generate/cancel after the new generation becomes active and cancel it instead. This is a single-session scenario, unlike the previously rejected concurrent-client finding; keep Generate unavailable until the pending cancel settles, abort the old request, or bind cancellation to its run.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Taking this one, though not by either of the two remedies I have already declined.

You are right that the 401 refresh-and-replay is a single-session path: the guard I added is correctly scoped now, so no Stop is swallowed, but a request waiting on that refresh genuinely outlives its own run, and the replay targets whatever is active when it lands.

The fix is to make the request abortable rather than to hold Generate hostage or to bind a run id through the protocol. cancelDiffusionGeneration takes an AbortSignal, handleCancelGenerate owns a controller, and the next run aborts any pending cancel as it starts. So a Stop cannot outlive the generation that raised it: if it has not reached the server by the time the next run begins, it never will, and its replay is dropped client-side before it is sent. An abort is silent, since it belongs to a run that is already over.

That closes the last mechanism in this family. The network retry went in 58c8c46, the duplicate clicks in 6b437fb, the guard scoping in fd12e7f and 944e3f9, and with the refresh-and-replay dropped there is nothing left that can put a stale cancel on the wire from this page. I still would not add a request id to the endpoint: that was only ever needed for genuinely concurrent clients, and it would have to change the video endpoint and the unload path to keep the three agreeing.

Frontend suite 1428 passed, typecheck clean, and the backend suite matches origin/main line for line.

Comment on lines 2718 to 2719
if (isMounted.current) void refreshStatus();
setBusy(null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Await native status refresh before enabling Generate

When a resident sd.cpp job does not acknowledge cancellation within its grace period, SdCppServer.img_gen stops the entire server, and the subsequent status call clears the backend's loaded state. This refresh is launched without awaiting it, however, and setBusy(null) immediately re-enables Generate while the page still holds status.loaded === true; a user who starts another generation in that window gets a 409 because the backend no longer has a model. Await the cheap refresh before clearing busy on this exit path, or otherwise keep Generate disabled until the refreshed status is applied.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and fixed in 944e3f9. The refresh I added was fired with void, so setBusy(null) ran first and Generate came back while the page still held the pre-cancel status. On the native path where the grace window expires, sd_cpp_server has already stopped the server by then, so that click 409s against a backend with nothing loaded.

It is awaited before setBusy(null) now. It is a local status GET, so the extra wait is not perceptible, and it only applies on the exit path where the button is being re-enabled anyway.

…nerate returns

A cancel POST waiting on a 401 refresh-and-replay outlives the run that sent
it, and the replay would then target whatever is generating by the time it
lands. The request is abortable now, and the next run aborts any pending one as
it starts, so nothing on the wire can outlive its own generation. An abort is
silent: it belongs to a run that is already over.

The status refresh was also fired without awaiting, so Generate came back
before the refreshed status applied. On the native path where the cancel grace
window expires, sd-server is stopped outright, and clicking Generate in that
window 409s against a backend with nothing loaded. Await it first.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 944e3f9b0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f9656fd into main Aug 9, 2026
52 of 57 checks passed
@danielhanchen
danielhanchen deleted the i8187-image-cancel branch August 9, 2026 15:21
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.

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

1 participant