Skip to content

feat: add get_workflow() to fetch the graph that produced a job - #47

Closed
wei-hai wants to merge 1 commit into
mainfrom
wei/fetch-job-workflow
Closed

feat: add get_workflow() to fetch the graph that produced a job#47
wei-hai wants to merge 1 commit into
mainfrom
wei/fetch-job-workflow

Conversation

@wei-hai

@wei-hai wei-hai commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

A caller holding a job — including one rehydrated by id — has no way to see the workflow behind it. The SDK holds the graph only when it submitted the job in the same process; otherwise it's gone.

flowchart LR
  subgraph B["Before"]
    J1["job (rehydrated by id)"] -. "?" .-> W1["workflow"]
  end
  subgraph A["After"]
    J2["job"] -- "GET /jobs/{id}/workflow" --> W2["workflow + format"]
  end
Loading

What it returns

Both the graph and the format discriminator, never just the graph:

  • api — the executed graph. Editor-only constructs (Note nodes, Get/Set) are already resolved away.
  • save — the authoring workflow at the version the job ran, un-mangled. Only for jobs that pin a workflow version; jobs submitted through this SDK today always get api.

Callers must branch on format — which shape comes back depends on how the job was submitted, not on anything the caller controls.

Server side is merged

GET /api/v2/jobs/{id}/workflow landed in Comfy-Org/cloud#6642, so this now works against a live server.

One follow-up, deliberately not done here

The transport call is written by hand, because the vendored spec didn't describe the operation when this was written. The spec-sync PR carrying it is open in this repo — once that merges, this call should move onto the generated client and the hand-written request dropped. A comment in the code marks the spot.

Keeping the two separate so this PR stays reviewable on its own; spec/openapi.yaml and spec/VERSION are untouched here and the drift check passes.

Naming

Matches the existing get_download_url / getDownloadUrl precedent for a network-fetching accessor, and the two SDKs stay in lockstep.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added workflow retrieval for synchronous and asynchronous jobs.
    • Workflows are available in API and save formats, including graph data.
    • Added public workflow models and package-level access.
    • Supports retrieving workflows from rehydrated jobs and handling missing workflows.
  • Bug Fixes

    • Missing workflows now consistently raise the SDK’s not-found error.

A caller holding a job — including one rehydrated by id — had no way to see
the workflow behind it. The SDK holds the graph only when it submitted the
job in the same process; otherwise it is gone.

Calls GET /api/v2/jobs/{id}/workflow and returns both the graph and the
format discriminator. "api" is the executed graph, with editor-only
constructs already resolved away; "save" is the authoring workflow at the
version the job ran. Returning the discriminator matters: a caller must be
able to tell which shape it holds.

Written by hand rather than through the generated client, because the
vendored spec does not describe this endpoint yet. It moves onto the
generated client once the spec re-syncs.

Named to match the existing get_download_url(), and mirrored as getWorkflow()
in the TypeScript SDK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a6cf1dff-bf5e-4292-8f56-8aa216e906cc

📥 Commits

Reviewing files that changed from the base of the PR and between 8bfbd3c and ee2155d.

📒 Files selected for processing (5)
  • src/comfy_low/transport.py
  • src/comfy_sdk/__init__.py
  • src/comfy_sdk/jobs.py
  • tests/conftest.py
  • tests/test_job_workflow.py

📝 Walkthrough

Walkthrough

The SDK adds synchronous and asynchronous job workflow retrieval. It introduces the public JobWorkflow dataclass, package-level export, low-level workflow transport methods, stub-server support, and tests for formats, rehydrated jobs, and missing jobs.

Changes

Job workflow retrieval

Layer / File(s) Summary
Workflow transport methods
src/comfy_low/transport.py
Synchronous and asynchronous clients resolve job IDs or URLs, apply request timeouts, validate HTTP 200 responses, and return workflow envelopes.
SDK workflow model and job methods
src/comfy_sdk/jobs.py, src/comfy_sdk/__init__.py
JobWorkflow stores the graph and "save" or "api" format. Sync and async job methods return this model and translate transport errors. The package exports JobWorkflow.
Workflow endpoint fixtures and tests
tests/conftest.py, tests/test_job_workflow.py
The stub server serves configured workflows or job_not_found errors. Tests cover sync, async, rehydrated, API-format, save-format, and missing-workflow cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: 🟡 Moderate · up to ee215

The new accessor fetches a job’s workflow over the network, but the required server endpoint currently returns 404 and the client is awaiting the corresponding specification update. The PR is not merge-ready until that dependency lands.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Job
  participant ComfyLow
  participant WorkflowEndpoint
  Caller->>Job: get_workflow()
  Job->>ComfyLow: get_job_workflow(job_id)
  ComfyLow->>WorkflowEndpoint: GET /jobs/{id}/workflow
  WorkflowEndpoint-->>ComfyLow: workflow envelope or 404
  ComfyLow-->>Job: response or translated error
  Job-->>Caller: JobWorkflow
Loading

Suggested reviewers: sundar-svg, robinjhuang

[fallback: fixed issue severity unavailable]

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding get_workflow() to retrieve the workflow graph for a job.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wei/fetch-job-workflow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wei-hai
wei-hai marked this pull request as ready for review August 13, 2026 16:46
@wei-hai
wei-hai requested review from a team as code owners August 13, 2026 16:46
wei-hai added a commit that referenced this pull request Aug 13, 2026
The required post-sync step: scripts/gen_models.sh against the newly vendored
spec, so the drift gate passes. Picks up JobWorkflowResponse and the new
job_id/expires_at fields on Asset and Output.

Coverage still fails until the two new operations have transport wrappers —
getJobWorkflow (#47) and deleteAsset (#41) — since OPERATION_IDS must match
the spec exactly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
wei-hai added a commit that referenced this pull request Aug 13, 2026
* feat: add asset delete

* address coderabbit PR comments

* address coderabbit PR comments

* feat: add get_workflow() to fetch the graph that produced a job

A caller holding a job — including one rehydrated by id — had no way to see
the workflow behind it. The SDK holds the graph only when it submitted the
job in the same process; otherwise it is gone.

Calls GET /api/v2/jobs/{id}/workflow and returns both the graph and the
format discriminator. "api" is the executed graph, with editor-only
constructs already resolved away; "save" is the authoring workflow at the
version the job ran. Returning the discriminator matters: a caller must be
able to tell which shape it holds.

Written by hand rather than through the generated client, because the
vendored spec does not describe this endpoint yet. It moves onto the
generated client once the spec re-syncs.

Named to match the existing get_download_url(), and mirrored as getWorkflow()
in the TypeScript SDK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* chore: sync vendored Comfy API v2 spec from cloud@7c65b1a

* chore: regenerate comfy_low models for the synced spec

The required post-sync step: scripts/gen_models.sh against the newly vendored
spec, so the drift gate passes. Picks up JobWorkflowResponse and the new
job_id/expires_at fields on Asset and Output.

Coverage still fails until the two new operations have transport wrappers —
getJobWorkflow (#47) and deleteAsset (#41) — since OPERATION_IDS must match
the spec exactly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* chore: wire the synced spec's new operations into comfy_low

Registers getJobWorkflow and deleteAsset in OPERATION_IDS/OPERATION_METHODS,
moves get_job_workflow onto the generated JobWorkflowResponse model, and
fixes six delete-asset test call sites that still passed the base URL
positionally after that constructor argument was replaced by COMFY_BASE_URL.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: jab416171 <jab416171@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: wei-hai <2936715+wei-hai@users.noreply.github.com>
@wei-hai wei-hai closed this Aug 13, 2026
@wei-hai
wei-hai deleted the wei/fetch-job-workflow branch August 13, 2026 17:53
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant