Skip to content

Add a way to attach metadata to the websocket messages of a prompt. - #16763

Merged
alexisrolland merged 8 commits into
masterfrom
cbyrne/ws-workflow-metadata
Oct 6, 2026
Merged

alexisrolland merged 8 commits into
masterfrom
cbyrne/ws-workflow-metadata

Conversation

@christian-byrne

@christian-byrne christian-byrne commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

A workflow_metadata dict can be passed when queueing a prompt and its key/values are included in every json websocket message of that prompt. Limited to 256 bytes; messages without a prompt_id (status, logs, asset events) are left alone.

Lets the frontend tell which workflow a message belongs to without tracking prompt ids itself: Comfy-Org/ComfyUI_frontend#20045 sends the field, Comfy-Org/ComfyUI_frontend#20050 consumes it.

If a client sends no metadata but its prompt carries a workflow in extra_pnginfo, that workflow's id is used instead, which is the same id /api/jobs reports. This is the only part that reads the prompt body, and it is what keeps core and the cloud backend on one contract rather than two. Happy to drop it if you would rather it not.

Earlier attempts, for context: #13684 (reverted in #13901), #13905, #13979, #13643.

Test approach to verify it works:

  • 67 store unit tests: every websocket message type, all three ways workflow ownership resolves and the order they are consulted in, a backend that never sends the field, and one that starts sending it mid-session.
  • 47 cases on the test harness itself, so the thing generating the frames is tested before anything is concluded from it.
  • core's 17 unit cases, green on linux, macos and windows.
  • every regression test was seen red before it was seen green.
  • the full-suite sweep was controlled against the branch point, so flaky suites are distinguishable from regressions.
  • the whole stack runs locally against a real ComfyUI on CPU, not only in CI.
  • the real wire was read during a real run: the field is on progress_state, progress, executing, executed, execution_start, execution_cached and execution_success.
  • the field is absent entirely when not supplied, rejected when oversized or not a dict, and never on status.
  • a client cannot overwrite a frame's own node or prompt_id by naming them in metadata.
  • browser cases, the first seven on two real saved workflows that deliberately share a node numbered 3 since that collision is what causes the leak, the rest driving a scripted websocket for the cases a real backend will not produce on demand:
    • queue a run in A, switch to B while it runs, and B shows no progress, no running node and no output.
    • let A finish while you sit in B, then go back to A, and nothing is still spinning. this is the original report.
    • A still reaches Completed in the tab bar while you are in B, so backgrounding a run does not lose it.
    • B's KSampler never shows A's progress bar or green running outline, even though both workflows own a node numbered 3.
    • switch A to B and back four times during one run, and every arrival in B is clean while every arrival in A shows current progress rather than a frozen or restarted value.
    • queue B behind a still-running A and sit on B, and B stays blank until its own job starts.
    • the tab you are looking at still shows its own progress and output, so the gating did not break the normal single-tab case.
    • a progress frame belonging to another workflow does not put the visible tab into a running state.
    • an image finished by another workflow does not appear in the node you are looking at.
    • two prompts' frames arriving interleaved, and the visible tab tracks only its own.
    • an output arriving after its job already ended is dropped rather than reappearing.
    • a duplicated completion frame does not show the output twice.
    • an older core that never sends the field behaves exactly as it does today.
    • another workflow finishing does not clear your running tab.
    • dropping and restoring the websocket mid-run does not duplicate the output.
    • a live preview from another workflow does not paint onto the canvas you are looking at.
    • two tabs that share one workflow id, because copying a workflow into a new tab keeps the id, do not receive each other's outputs. this is what QA reported with three unsaved copies.
  • a workflow id names a workflow, not an open tab, so ownership resolves on the per-tab instance first, then the session path, then the id. the order is pinned by tests, since getting it wrong is what caused the leak.
  • a run survives its tab being renamed, and the copy that Save As creates does not claim it.
  • three rounds of manual QA on a GPU with a real checkpoint, and the first two failed.
  • QA round 1 found a real cross-tab leak the automated suite had missed, because the two-tab specs asserted the topbar badges, which were always correct, while the bug was on the canvas.
  • QA round 1 also found that the helper opening the saved workflows registered the tab without loading the graph, so those specs had been running against the wrong canvas entirely.
  • QA round 2 found the first fix held only for the first tab switch, which identified it as a race against the canvas code that stamps progress onto the newly opened graph, rather than a stale value.
  • the fix is now applied where progress is projected rather than on a watcher, so no ordering can leak, and one test deliberately leaves a foreign entry in the shared state to prove it.
  • QA round 3 passed all four checks, including seven consecutive tab switches during one 1,200 step run and a second workflow queued behind a running one.

Not covered: binary preview frames are not stamped, since they are not json.

Loading
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.

3 participants