Skip to content

Commit 0bc18c4

Browse files
christian-byrneConnor Byrne
andauthored
fix: clear workflow status when an account precondition ends a run (Comfy-Org#15161)
## Summary A runtime credits refusal leaves the workflow's execution status stuck at `running` forever. ## Changes - **What**: `handleAccountPreconditionError` in `src/stores/executionStore.ts` now clears the workflow's `workflowStatus` entry before resetting execution state. Mechanism on `main`: - `handleExecutionError` calls `handleAccountPreconditionError(e.detail)` and returns early when it returns true. These errors (`INSUFFICIENT_CREDITS` / `WORKSPACE_INSUFFICIENT_CREDITS`, routed via `resolveAccountPrecondition`) open their own modal and are deliberately kept out of the error panel and error count. - `handleAccountPreconditionError` only called `clearInitializationByJobId` then `resetExecutionState`. - `resetExecutionState` deletes `queuedJobs[jobId]` and the `jobIdToWorkflow` entry, but never touches `workflowStatus`. These are runtime errors: the job was accepted, got a machine, and `execution_start` already wrote `running` before the refusal arrives. So the status map keeps `running` indefinitely, and every reader of `getWorkflowStatus` (status badges, the first-run tour result card) promises a result that will never arrive. `handleExecutionInterrupted` already does the right thing and is the precedent this copies. Ordering matters: the `jobIdToWorkflow` lookup and status clear must happen before `resetExecutionState`, which deletes that mapping. ## Review Focus - Clearing rather than writing `failed` is intentional and matches the interrupt path — an account precondition is a gating state with its own modal, not a workflow failure, so it should leave no badge. - Sibling early-return branches (`handleServiceLevelError`, `handleCloudValidationError`) were left alone. Service-level errors have an existing test asserting the status stays `running`, so changing that is a separate decision. - Unit test added in `src/stores/executionStore.test.ts`: paid-style credits payload after `execution_start`, asserting the status goes from `running` to cleared. Verified it fails on `main` (`expected 'running' to be undefined`) and passes with the fix. Found while reviewing Comfy-Org#15091. Distinct from Comfy-Org#14619, which covers the submit-time refusal where no `prompt_id` is ever issued and the status never passes through `running` at all; this is the accepted-then-refused runtime path. Co-authored-by: Connor Byrne <c.byrne@comfy.org>
1 parent 298b78a commit 0bc18c4

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/stores/executionStore.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,28 @@ describe('useExecutionStore - workflowStatus', () => {
936936
}
937937
})
938938

939+
it('clears running when an account precondition error ends the run', () => {
940+
callStoreJob('job-1', workflowA)
941+
fireExecutionStart('job-1')
942+
expect(store.getWorkflowStatus(workflowA)).toBe('running')
943+
944+
apiEventHandlers.get('execution_error')!(
945+
new CustomEvent('execution_error', {
946+
detail: {
947+
prompt_id: 'job-1',
948+
node_id: '1',
949+
node_type: 'TestNode',
950+
exception_message:
951+
'Payment Required: Please add credits to your account to use this node.',
952+
exception_type: 'InsufficientFundsError',
953+
traceback: []
954+
}
955+
})
956+
)
957+
958+
expect(store.getWorkflowStatus(workflowA)).toBeUndefined()
959+
})
960+
939961
it('drops pending failed when service-level error fires before storeJob', () => {
940962
apiEventHandlers.get('execution_error')!(
941963
new CustomEvent('execution_error', {

src/stores/executionStore.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ export const useExecutionStore = defineStore('execution', () => {
686686
})
687687
if (!precondition) return false
688688

689+
const workflow = jobIdToWorkflow.get(detail.prompt_id)
690+
if (workflow) clearWorkflowStatus(workflow)
689691
clearInitializationByJobId(detail.prompt_id)
690692
resetExecutionState(detail.prompt_id)
691693
return true

0 commit comments

Comments
 (0)