Skip to content

Allow optionally specifying a prompt id in /interrupt endpoint #8308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

josephrocca
Copy link

@josephrocca josephrocca commented May 27, 2025

I'm using ComfyUI via the API for a task, and I found that sometimes I need to cancel/interrupt a running task. So I fetch the data from /queue, but the problem is this data is immediately stale, so a call to /interrupt could cancel the wrong task.

Ideally I'd be able to use the prompt_id of the running item that I got from /queue, to ensure that I don't accidentally cancel the next item in the case where the running task just finished the moment after I got the /queue data.

Please feel free to close this issue if there's a better approach - I don't know much about ComfyUI internals, and so have made this pull request more as a "sketch" of what I'm talking about, than any sort of implicit claim that I think this is a good way to solve this race condition issue.

@comfyanonymous
Copy link
Owner

I'm fine with adding the functionality but this exact way breaks the interrupt button in the frontend.

@josephrocca
Copy link
Author

Oof sorry for not testing that! Latest commit fixes it.

Can confirm now that button works, and also this works when pasted in browser console:

let queue = await fetch("/api/queue").then(r => r.json());
let id = queue.queue_running[0][1];
await fetch("/api/interrupt", {
  method: "POST",
  body: JSON.stringify({id}),
}).then(r => r.ok)

If you give an ID that isn't the currently running item like changing JSON.stringify({id}) to JSON.stringify({id:"foo"}) in the above code, it does not interrupt the running item, as expected.

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