From 7cf5d1e86b793c797cd91a169dd5edbfc52a9ce6 Mon Sep 17 00:00:00 2001 From: Deep Roy Date: Thu, 10 Jul 2025 20:24:21 -0400 Subject: [PATCH] Add prompt ID to interrupt API call (#4393) --- src/components/sidebar/tabs/QueueSidebarTab.vue | 2 +- src/composables/useCoreCommands.ts | 4 +++- src/scripts/api.ts | 14 ++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/sidebar/tabs/QueueSidebarTab.vue b/src/components/sidebar/tabs/QueueSidebarTab.vue index b598cd8f9..6b0fe036c 100644 --- a/src/components/sidebar/tabs/QueueSidebarTab.vue +++ b/src/components/sidebar/tabs/QueueSidebarTab.vue @@ -159,7 +159,7 @@ const toggleExpanded = () => { const removeTask = async (task: TaskItemImpl) => { if (task.isRunning) { - await api.interrupt() + await api.interrupt(task.promptId) } await queueStore.delete(task) } diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index bef0655cb..5e4cf6125 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -19,6 +19,7 @@ import { useDialogService } from '@/services/dialogService' import { useLitegraphService } from '@/services/litegraphService' import { useWorkflowService } from '@/services/workflowService' import type { ComfyCommand } from '@/stores/commandStore' +import { useExecutionStore } from '@/stores/executionStore' import { useCanvasStore, useTitleEditorStore } from '@/stores/graphStore' import { useQueueSettingsStore, useQueueStore } from '@/stores/queueStore' import { useSettingStore } from '@/stores/settingStore' @@ -39,6 +40,7 @@ export function useCoreCommands(): ComfyCommand[] { const firebaseAuthActions = useFirebaseAuthActions() const toastStore = useToastStore() const canvasStore = useCanvasStore() + const executionStore = useExecutionStore() const getTracker = () => workflowStore.activeWorkflow?.changeTracker const getSelectedNodes = (): LGraphNode[] => { @@ -203,7 +205,7 @@ export function useCoreCommands(): ComfyCommand[] { icon: 'pi pi-stop', label: 'Interrupt', function: async () => { - await api.interrupt() + await api.interrupt(executionStore.activePromptId) toastStore.add({ severity: 'info', summary: t('g.interrupted'), diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 85316a74a..b17df5bac 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -689,7 +689,8 @@ export class ComfyApi extends EventTarget { Running: data.queue_running.map((prompt: Record) => ({ taskType: 'Running', prompt, - remove: { name: 'Cancel', cb: () => api.interrupt() } + // prompt[1] is the prompt id + remove: { name: 'Cancel', cb: () => api.interrupt(prompt[1]) } })), Pending: data.queue_pending.map((prompt: Record) => ({ taskType: 'Pending', @@ -770,10 +771,15 @@ export class ComfyApi extends EventTarget { } /** - * Interrupts the execution of the running prompt + * Interrupts the execution of the running prompt. If runningPromptId is provided, + * it is included in the payload as a helpful hint to the backend. + * @param {string | null} [runningPromptId] Optional Running Prompt ID to interrupt */ - async interrupt() { - await this.#postItem('interrupt', null) + async interrupt(runningPromptId: string | null) { + await this.#postItem( + 'interrupt', + runningPromptId ? { prompt_id: runningPromptId } : undefined + ) } /**