Skip to content

Add workflow_id to all websocket messages#13643

Draft
luke-mino-altherr wants to merge 1 commit intomasterfrom
cursor/add-workflow-id-to-websocket-messages-59fc
Draft

Add workflow_id to all websocket messages#13643
luke-mino-altherr wants to merge 1 commit intomasterfrom
cursor/add-workflow-id-to-websocket-messages-59fc

Conversation

@luke-mino-altherr
Copy link
Copy Markdown
Contributor

Summary

This PR adds workflow_id to all execution-related websocket messages in the ComfyUI core repository, addressing issues with node progress state getting stuck, cross-workflow progress leakage, and node outputs being applied to the wrong workflow when switching tabs.

Changes

1. New Helper Function

  • Added extract_workflow_id() function in comfy_execution/jobs.py to extract workflow_id from extra_data['extra_pnginfo']['workflow']['id']

2. Updated WebSocket Messages in execution.py

Added workflow_id field to the following messages when available:

  • execution_start - Sent when prompt execution begins
  • execution_cached - Sent for cached nodes
  • execution_success - Sent on successful completion
  • execution_error - Sent when execution errors occur
  • execution_interrupted - Sent when execution is interrupted
  • executing - Sent when a node starts/stops executing
  • executed - Sent when a node completes with output

3. Updated Progress Messages in main.py

  • Modified hijack_progress() to include workflow_id in progress messages
  • Updated final "executing" message (with node=None) to include workflow_id

4. Updated Progress State in comfy_execution/progress.py

  • Modified ProgressRegistry to store and pass workflow_id
  • Updated progress_state messages to include workflow_id
  • Added workflow_id to preview image metadata

Backward Compatibility

The workflow_id field is only included when present in the extra_data. Workflows that don't provide a workflow_id will continue to work as before, with messages sent without this field. This ensures backward compatibility with existing workflows and integrations.

Testing

  • ✅ All modified Python files compile without syntax errors
  • ✅ Manual testing of extract_workflow_id() function passes all test cases
  • ✅ Changes follow the existing code patterns in the repository

Related Issues

Fixes: BE-672

Impact

This change enables the frontend to:

  • Properly scope progress state updates to the active workflow
  • Prevent cross-workflow progress leakage
  • Handle dropped WebSocket messages more gracefully
  • Apply node outputs to the correct workflow when switching tabs

The workflow_id field complements the existing prompt_id field, providing an additional layer of scoping for multi-workflow scenarios.

Linear Issue: BE-672

Open in Web Open in Cursor 

This commit addresses BE-672 by ensuring all execution-related websocket
messages include the workflow_id field when available.

Changes:
- Added extract_workflow_id() helper function in comfy_execution/jobs.py
  to extract workflow_id from extra_data
- Updated execution.py to include workflow_id in all websocket messages:
  - execution_start
  - execution_cached
  - execution_success
  - execution_error
  - execution_interrupted
  - executing
  - executed (including cached UI)
- Updated main.py to include workflow_id in:
  - progress messages (via hijack_progress hook)
  - final executing message (node=None)
- Updated comfy_execution/progress.py to include workflow_id in:
  - progress_state messages
  - preview image metadata

The workflow_id is extracted from extra_data['extra_pnginfo']['workflow']['id']
and is conditionally included in messages only when present, maintaining
backward compatibility with workflows that don't have this field.

Fixes: BE-672

Co-authored-by: Luke Mino-Altherr <luke-mino-altherr@users.noreply.github.com>
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