Skip to content

fix: reject getEmbeddings on HTTP failures and report A1111 import connectivity distinctly - #14931

Closed
MaanilVerma wants to merge 3 commits into
mainfrom
fix/getembeddings-http-failures
Closed

MaanilVerma wants to merge 3 commits into
mainfrom
fix/getembeddings-http-failures

Conversation

@MaanilVerma

Copy link
Copy Markdown
Collaborator

Summary

api.getEmbeddings() never checked resp.ok, so a backend failure during an A1111 PNG import either resolved silently with garbage (500 with a JSON body, import proceeds with unresolved embeddings and no feedback) or surfaced as "Unable to find workflow in <file>" (500 with an HTML body, via the SyntaxError from parsing it). Connectivity problems now reject identifiably at the source and the import path reports them as what they are.

Changes

  • api.getEmbeddings() throws a new ApiHttpError (endpoint, status, defensive body text) on non-ok responses, and wraps fetch-level rejections as status 0 so a fully unreachable backend is identifiable the same way
  • app.handleFile()'s A1111 parameters fall-through catches ApiHttpError and shows a connectivity toast; any other rejection propagates unchanged
  • Extracted httpFailureDetail() and reused it in cancelJob/cancelJobs, which already built the identical failure string (messages unchanged, their tests stay green)
  • New locale key toastMessages.a1111EmbeddingsUnavailable
  • Tests: api.getEmbeddings.test.ts (success, non-ok JSON body, non-ok HTML body, rejecting body read, fetch-level failure), app-level cases pinning the connectivity toast for ApiHttpError and propagation for everything else, and a pnginfo pin that an embeddings failure rejects before any lifecycle effect runs

Review Focus

  • src/scripts/api.ts: the transport wrap (status 0) is the one behavior judgment call, and getEmbeddings changing from always-resolving to rejecting is a contract change on the window.comfyAPI surface
  • src/scripts/app.ts: the catch narrows on instanceof ApiHttpError; a dedicated test pins that non-connectivity rejections still propagate untoasted

Note for extension authors: api.getEmbeddings() previously resolved whatever a failed response parsed to; it now rejects with ApiHttpError. Direct callers should add a catch.

Testing

  • Red first: the api tests fail on the unfixed code (promise resolved instead of rejecting; SyntaxError instead of an identifiable error) and the app test fails before the class exists
  • Green after: 83 tests across the four touched suites; full unit suite 15,200 passing, with the only 12 failures in scripts/cicd/check-binary-size.test.ts, a CI-script test untouched by this diff that exits 127 (missing tool) in the sandbox that ran it

@MaanilVerma
MaanilVerma requested a review from a team August 8, 2026 03:23
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The API now identifies transport and HTTP failures from getEmbeddings. A1111 imports show a dedicated backend error, preserve unrelated errors, and avoid graph lifecycle effects when embedding loading fails. Tests cover success, HTTP, transport, and import-error paths.

Changes

A1111 embedding failure handling

Layer / File(s) Summary
Embedding API failure contract
src/scripts/api.ts, src/scripts/api.getEmbeddings.test.ts
getEmbeddings now throws ApiHttpError for transport and non-success responses. Tests cover successful responses, JSON and HTML failures, unreadable bodies, and fetch failures. Job cancellation errors use the shared formatter.
A1111 import error handling
src/scripts/app.ts, src/scripts/app.test.ts, src/scripts/pnginfo.test.ts, src/locales/en/main.json
A1111 embedding failures show a dedicated localized toast. Other errors propagate. Tests verify that import lifecycle effects do not run after embedding failures.

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

Possibly related PRs

Suggested labels: core/1.49, cloud/1.49

Suggested reviewers: jaeone94, christian-byrne


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR handles HTTP and transport failures, but the context does not show identifiable handling for malformed successful responses or all other callers. Convert malformed successful responses into an identifiable ApiHttpError, add coverage, and document or update error handling for every getEmbeddings caller.
End-To-End Regression Coverage For Fixes ❓ Inconclusive The changed files and description are available, but the PR title and commit subjects are not provided, so the required bug-fix signal cannot be verified. Provide the PR title and commit subjects to assess whether the end-to-end regression coverage rule applies.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes to getEmbeddings failure handling and A1111 connectivity reporting.
Description check ✅ Passed The description includes the required summary, changes, review focus, issue links, and testing details.
Out of Scope Changes check ✅ Passed The locale update, shared formatter refactor, and tests directly support the linked failure-handling and A1111 import objectives.
Adr Compliance For Entity/Litegraph Changes ✅ Passed The changed files are locale, API, app, and test files; none are under the specified litegraph, ECS, or graph-entity paths.
✨ 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 fix/getembeddings-http-failures

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.

@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright: ✅ 1786 passed, 0 failed · 3 flaky

📊 Browser Reports
  • chromium: View Report (✅ 1765 / ❌ 0 / ⚠️ 3 / ⏭️ 5)
  • chromium-2x: View Report (✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • chromium-0.5x: View Report (✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • mobile-chrome: View Report (✅ 18 / ❌ 0 / ⚠️ 0 / ⏭️ 0)

🎨 Storybook: ✅ Built — View Storybook

Details

⏰ Completed at: 08/08/2026, 03:25:47 AM UTC

Links

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@src/scripts/api.getEmbeddings.test.ts`:
- Around line 42-95: Strengthen the error assertions for api.getEmbeddings in
src/scripts/api.getEmbeddings.test.ts:42-95 to verify ApiHttpError identity plus
endpoint and status metadata, including status 0 for transport failures and body
details for both readable and unreadable failure responses. In
src/scripts/app.test.ts:1625-1636, store the RangeError instance and assert
rejection with rejects.toBe(failure) to verify unchanged propagation.

In `@src/scripts/api.ts`:
- Around line 212-214: Remove the export modifier from the httpFailureDetail
function so it remains module-local while preserving its current signature and
behavior.

In `@src/scripts/app.ts`:
- Line 152: Separate the type-only ComfyApi import from the runtime import in
src/scripts/app.ts: add a dedicated import type statement for ComfyApi and leave
ApiHttpError, PromptExecutionError, and api in the regular import.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a3da4333-6777-4307-8cd3-761c5d708ec4

📥 Commits

Reviewing files that changed from the base of the PR and between 2a0a7ef and abe7cda.

📒 Files selected for processing (6)
  • src/locales/en/main.json
  • src/scripts/api.getEmbeddings.test.ts
  • src/scripts/api.ts
  • src/scripts/app.test.ts
  • src/scripts/app.ts
  • src/scripts/pnginfo.test.ts

Comment on lines +42 to +95
it('rejects identifiably on a non-ok response with a JSON body', async () => {
fetchApiSpy.mockResolvedValueOnce(jsonResponse(500, { error: 'boom' }))

await expect(api.getEmbeddings()).rejects.toSatisfy(
(e) =>
e instanceof Error &&
e.name === 'ApiHttpError' &&
e.message.includes('/embeddings') &&
e.message.includes('500')
)
})

it('keeps the status even when reading the failure body itself rejects', async () => {
fetchApiSpy.mockResolvedValueOnce({
ok: false,
status: 500,
json: () => Promise.reject(new SyntaxError('Unexpected token <')),
text: () => Promise.reject(new Error('body stream lost'))
} as unknown as Response)

await expect(api.getEmbeddings()).rejects.toSatisfy(
(e) =>
e instanceof Error &&
e.name === 'ApiHttpError' &&
e.message.includes('/embeddings') &&
e.message.includes('500')
)
})

it('rejects identifiably when the fetch itself fails (backend down)', async () => {
fetchApiSpy.mockRejectedValueOnce(new TypeError('Failed to fetch'))

await expect(api.getEmbeddings()).rejects.toSatisfy(
(e) =>
e instanceof Error &&
e.name === 'ApiHttpError' &&
e.message.includes('/embeddings') &&
e.message.includes('Failed to fetch')
)
})

it('rejects identifiably on a non-ok response with an HTML body', async () => {
fetchApiSpy.mockResolvedValueOnce(
htmlResponse(502, '<html>bad gateway</html>')
)

await expect(api.getEmbeddings()).rejects.toSatisfy(
(e) =>
e instanceof Error &&
e.name === 'ApiHttpError' &&
e.message.includes('/embeddings') &&
e.message.includes('502')
)
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert error identity and metadata, not only error text.

Text-only assertions can pass when the error type or its public metadata changes.

  • src/scripts/api.getEmbeddings.test.ts#L42-L95: Assert ApiHttpError identity and its endpoint and status fields. Cover status 0 for transport failures and body details for readable and unreadable responses.
  • src/scripts/app.test.ts#L1625-L1636: Store the RangeError instance and use rejects.toBe(failure) to verify unchanged propagation.

As per path instructions, “Tests for getEmbeddings and A1111 import handling should verify … error identity/details.”

📍 Affects 2 files
  • src/scripts/api.getEmbeddings.test.ts#L42-L95 (this comment)
  • src/scripts/app.test.ts#L1625-L1636
🤖 Prompt for 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.

In `@src/scripts/api.getEmbeddings.test.ts` around lines 42 - 95, Strengthen the
error assertions for api.getEmbeddings in
src/scripts/api.getEmbeddings.test.ts:42-95 to verify ApiHttpError identity plus
endpoint and status metadata, including status 0 for transport failures and body
details for both readable and unreadable failure responses. In
src/scripts/app.test.ts:1625-1636, store the RangeError instance and assert
rejection with rejects.toBe(failure) to verify unchanged propagation.

Source: Path instructions

Comment thread src/scripts/api.ts
Comment on lines +212 to +214
export function httpFailureDetail(status: number | string, body = ''): string {
return `${status}${body ? ` — ${body}` : ''}`
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -nP --glob '*.{ts,tsx,vue}' \
  '(?:import\s*\{[^}]*\bhttpFailureDetail\b|httpFailureDetail\s*\()' src

Repository: Comfy-Org/ComfyUI_frontend

Length of output: 569


Remove the redundant httpFailureDetail export.

httpFailureDetail is only called from src/scripts/api.ts; no external file imports it. Drop export to keep the API surface minimal.

🤖 Prompt for 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.

In `@src/scripts/api.ts` around lines 212 - 214, Remove the export modifier from
the httpFailureDetail function so it remains module-local while preserving its
current signature and behavior.

Source: Learnings

Comment thread src/scripts/app.ts
import { deserialiseAndCreate } from '@/utils/vintageClipboard'

import { type ComfyApi, PromptExecutionError, api } from './api'
import { type ComfyApi, ApiHttpError, PromptExecutionError, api } from './api'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Separate the type-only import.

Line 152 mixes type ComfyApi with runtime imports. Move ComfyApi to a separate import type statement.

As per coding guidelines, “Use separate import type statements rather than inline type specifiers in mixed imports.”

Proposed fix
-import { type ComfyApi, ApiHttpError, PromptExecutionError, api } from './api'
+import { ApiHttpError, PromptExecutionError, api } from './api'
+import type { ComfyApi } from './api'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { type ComfyApi, ApiHttpError, PromptExecutionError, api } from './api'
import { ApiHttpError, PromptExecutionError, api } from './api'
import type { ComfyApi } from './api'
🤖 Prompt for 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.

In `@src/scripts/app.ts` at line 152, Separate the type-only ComfyApi import from
the runtime import in src/scripts/app.ts: add a dedicated import type statement
for ComfyApi and leave ApiHttpError, PromptExecutionError, and api in the
regular import.

Sources: Coding guidelines, Learnings

@MaanilVerma MaanilVerma closed this Aug 8, 2026
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@           Coverage Diff            @@
##             main   #14931    +/-   ##
========================================
  Coverage   78.69%   78.70%            
========================================
  Files        1864     1864            
  Lines      115461   115477    +16     
  Branches    34495    33554   -941     
========================================
+ Hits        90864    90883    +19     
+ Misses      24055    24052     -3     
  Partials      542      542            
Flag Coverage Δ
unit 72.22% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scripts/api.ts 59.05% <100.00%> (+1.05%) ⬆️
src/scripts/app.ts 65.99% <100.00%> (+0.11%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle getEmbeddings HTTP failures during A1111 import getEmbeddings ignores resp.ok, so server errors surface as "Unable to find workflow"

1 participant