Bug Report: “execution_success” fires before outputs are persisted
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 155
Description
### Custom Node Testing
- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)
### Expected Behavior
The completion notification that clients rely on (execution_success / job_completed) should be emitted after outputs are fully persisted and visible via history/status APIs, so fetching outputs immediately after the completion event returns the final artifacts.
### Actual Behavior
execution_success is emitted in execute_async before history_result is written to history in task_done. Clients that fetch job status/outputs as soon as they receive the completion event can observe output_files empty and persist outputs: [], even though the workflow produced artifacts. This is timing-dependent and intermittent.
### Steps to Reproduce
Steps to Reproduce (race)
Run a workflow that produces outputs (e.g., unified SRT TTS) through ComfyUI.
Listen for the websocket execution_success (or downstream job_completed) event.
Immediately upon receiving the event, call the job status/output endpoint (e.g., /api/jobs/{prompt_id} or mediagen’s /mediagen/api/v1/jobs/{jobid}).
Observe that output_files can be empty right after the completion event; later calls (or manual refresh) show the outputs once history finishes persisting.
Impact
Queue/UX or integrations that fetch once on completion can store outputs: [] and never backfill, so completed jobs appear with missing audio/SRT/media.
### Debug Logs
```powershell
Exact line locations in the ComfyUI repo:
ComfyUI/execution.py
Line 731: self.add_message("execution_success", { "prompt_id": prompt_id }, broadcast=False)
Lines 733–741: Build history_result with ui_outputs/meta_outputs (outputs not yet persisted)
ComfyUI/execution.py
Lines 1135–1155: PromptQueue.task_done(...) persists history_result into self.history and triggers queue_updated
ComfyUI/main.py
Lines 200–236: Main loop runs e.execute(...) then calls q.task_done(...) (persistence happens only after execute_async returns)
```
### Other
Suggested Fix (one of)
Move/emit the completion notification after task_done persists outputs (or add a new “execution_persisted” event and have clients wait for it).
Alternatively, include finalized outputs in the completion payload so clients don’t have to race the history API.
Contributor guide
Research direction
Start with ComfyUI/execution.py around the execution_success emission and history_result construction, then trace PromptQueue.task_done in execution.py and the execute/task_done flow in main.py. Reproduce the race by listening for execution_success and immediately querying the job status/output endpoint. Done means completion consumers can fetch persisted outputs without observing an empty output_files result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100