Skip to content

fix(workflow): surface unparseable cloud 200 body as an error instead of empty/success (BE-3334)#549

Open
mattmillerai wants to merge 3 commits into
mainfrom
matt/be-3334-cloud-unparseable-response
Open

fix(workflow): surface unparseable cloud 200 body as an error instead of empty/success (BE-3334)#549
mattmillerai wants to merge 3 commits into
mainfrom
matt/be-3334-cloud-unparseable-response

Conversation

@mattmillerai

Copy link
Copy Markdown
Collaborator

ELI-5

When you run comfy workflow list or comfy workflow save against Comfy Cloud, the CLI reads the server's reply and parses it as JSON. If the server answered 200 OK but the body was garbage (a non-JSON HTML error page from a proxy, or non-UTF-8 bytes), the CLI used to quietly pretend it got nothing — so list said count: 0, ok: true (looks like "you have no workflows") and save said ok: true, changed: true, workflow_id: null and printed ✓ saved 'x' → None (looks like it worked). Both lied: the request actually failed, you just couldn't tell.

This PR makes that case loud: a non-empty-but-unparseable 200 body now raises a new _ResponseUnparseable and surfaces as a real error envelope (ok: false, code workflow_unparseable) instead of a misleading empty/success. A genuinely empty body is still treated as legitimate "no data" — that behavior is unchanged.

What changed

  • _http_request (the shared cloud helper): now distinguishes the two conditions. An empty body still returns (status, None); a non-empty body that fails to decode raises _ResponseUnparseable (a sibling to the existing _ResponseTooLarge). It now also catches UnicodeDecodeErrorjson.loads decodes bytes itself and raises that (not JSONDecodeError) on non-UTF-8 input, which previously would have escaped uncaught.
  • _handle_cloud_http_error: maps _ResponseUnparseable → error code workflow_unparseable, mirroring the workflow_too_large branch (message + hint + details.operation).
  • All four cloud call sites (list / get / save / delete) add _ResponseUnparseable to their except tuple so the new raise is caught and mapped rather than crashing.
  • error_codes.py: registered workflow_unparseable (the repo enforces "every raised code is registered" via test_error_code_registry.py).
  • Tests: a parametrized TestUnparseableResponse feeds both a non-JSON (<html>…) and a non-UTF-8 (\xff\xfe…) 200 body through list and save, asserting ok: false + workflow_unparseable (i.e. no silent empty/null-id success).

Scope / judgment calls

  • Follow-up to the deferred review thread on fix(workflow): detect oversize responses in _http_request instead of silently truncating (BE-3297) #540 (BE-3297) — that PR was scoped to oversize detection and only made the pre-existing None-on-unparseable path consistent; distinguishing "empty" from "unparseable" was explicitly left as separate work.
  • get/delete were already non-misleading, but _http_request now raises where it used to return None, so they must include _ResponseUnparseable in their except tuple or they'd crash on a non-empty junk body. Net effect: get now reports workflow_unparseable (was a generic "unexpected response shape") and delete reports it too (was a silent deleted: true on a junk body) — both strictly clearer, and the empty-body/204 delete path is unchanged.
  • Not a capability denial: this only surfaces a transport-level malformed-response error that was previously swallowed; no product feature is being gated or removed. The message points the user to retry, not to a dead end.

Testing

  • pytest tests/comfy_cli/command/test_workflow_saved.py — 41 passed (incl. 4 new cases)
  • pytest tests/comfy_cli/output/test_error_code_registry.py — passed (confirms the new code is registered + raised)
  • pytest tests/comfy_cli/command/ — 1161 passed, 2 skipped
  • ruff check + ruff format --check — clean

@mattmillerai mattmillerai added agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review labels Jul 17, 2026
@mattmillerai
mattmillerai marked this pull request as ready for review July 17, 2026 17:08
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1eab0dc2-9b57-4807-8915-276afa994bc3

📥 Commits

Reviewing files that changed from the base of the PR and between 9d274fa and 83af391.

📒 Files selected for processing (2)
  • comfy_cli/command/workflow.py
  • tests/comfy_cli/command/test_workflow_saved.py
📝 Walkthrough

Walkthrough

Cloud workflow requests now classify non-empty, non-JSON responses as workflow_unparseable. The error is propagated through list, get, save, and delete commands, with tests covering text and non-UTF-8 response bodies.

Changes

Cloud workflow error handling

Layer / File(s) Summary
Response parsing and error envelope
comfy_cli/command/workflow.py, comfy_cli/error_codes.py
Non-empty JSON or Unicode decoding failures raise _ResponseUnparseable and produce the registered workflow_unparseable error envelope.
Command propagation and validation
comfy_cli/command/workflow.py, tests/comfy_cli/command/test_workflow_saved.py
Cloud list, get, save, and delete handle unparseable responses; tests verify failure results for HTML and non-UTF-8 bodies.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matt/be-3334-cloud-unparseable-response
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch matt/be-3334-cloud-unparseable-response

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

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@comfy_cli/command/workflow.py`:
- Around line 628-634: Update the response parsing logic around the JSON load
and _ResponseUnparseable handling to explicitly decode non-empty cloud response
bodies as UTF-8 before calling json.loads. Ensure UTF-16/32 or other non-UTF-8
bytes raise UnicodeDecodeError and are mapped to _ResponseUnparseable,
preserving the existing malformed-response error path.

In `@tests/comfy_cli/command/test_workflow_saved.py`:
- Around line 550-567: Extend TestUnparseableResponse to assert
error.details.operation for list and save using their respective operation
values, then add malformed-response tests covering the changed get and delete
command paths. Each new case should assert ok is false, error.code is
workflow_unparseable, and the envelope’s operation detail matches the invoked
command.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c637a549-84be-4f38-bd2c-cbb7dd7e47b1

📥 Commits

Reviewing files that changed from the base of the PR and between a732f5c and 9d274fa.

📒 Files selected for processing (3)
  • comfy_cli/command/workflow.py
  • comfy_cli/error_codes.py
  • tests/comfy_cli/command/test_workflow_saved.py

Comment thread comfy_cli/command/workflow.py Outdated
Comment thread tests/comfy_cli/command/test_workflow_saved.py
Handed raw bytes, json.loads auto-detects UTF-16/32 (RFC 4627) and would
silently accept a non-UTF-8 body the workflow_unparseable contract treats as
malformed. Decode UTF-8 explicitly first so such bodies raise
UnicodeDecodeError -> _ResponseUnparseable, matching the contract.

Also expand TestUnparseableResponse per review: add a UTF-16-JSON regression
param, assert details.operation on the envelope, and cover the get/delete
catch sites (were untested).

Addresses CodeRabbit review on PR #549.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Cursor Review — Consolidated panel

Triggered by @mattmillerai.

Found 5 finding(s).

Severity Count
🟠 High 1
🟡 Medium 2
🟢 Low 2

Panel: 6/8 reviewers contributed findings.

Reviewers that did not contribute: kimi-k2.5:adversarial (empty), kimi-k2.5:edge-case (empty)

Comment thread comfy_cli/command/workflow.py
Comment thread comfy_cli/command/workflow.py
Comment thread comfy_cli/command/workflow.py Outdated
Comment thread comfy_cli/command/workflow.py Outdated
Comment thread tests/comfy_cli/command/test_workflow_saved.py
Address adversarial review-panel findings on the unparseable-200 handling:

- _http_request: catch the ValueError base (+ RecursionError) instead of only
  (JSONDecodeError, UnicodeDecodeError). Both were already ValueError subclasses;
  the base also maps json.loads' bare ValueError from an integer past CPython's
  4300-digit int/str limit, which previously escaped as a raw traceback.
- list_cmd: guard the response shape like get/save do. A valid-JSON non-dict 200
  (an array or scalar) hit (body).get("data") -> raw AttributeError; coercing it to
  [] would masquerade a malformed shape as a genuinely-empty listing. Now mapped to
  cloud_http_error.
- _handle_cloud_http_error: bound the HTTP error-body read with e.read(1000) rather
  than read-all-then-slice, so a large/malicious error page can't force an unbounded
  allocation on the error path.
- tests: add a bigint bare-ValueError body param and non-dict-shape list cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant