moeru-ai/airi · error · Error

Cannot connect to ComfyUI at ${this.serverUrl}: ${e.message}

Error message

Cannot connect to ComfyUI at ${this.serverUrl}: ${e.message}

What it means

Thrown by the ComfyUI provider when fetchWithTimeout to <serverUrl>/prompt throws (network-level failure) rather than returning a response. The catch wraps any thrown error and re-throws with the server URL and the underlying error message for diagnosability.

Source

Thrown at apps/stage-tamagotchi/src/main/services/airi/widgets/providers/comfyui.ts:143

        resolvedPrompt = this.replacePlaceholders(resolvedPrompt, replacements)
      }

      log.log(`[ComfyUI] Resolved prompt for ${jobId}:`, JSON.stringify(resolvedPrompt, null, 2))

      // 2. POST /prompt to queue the workflow
      this.updateStatus(jobId, { status: 'running', actionLabel: 'Queuing in ComfyUI...' })

      let queueResp: Response
      try {
        queueResp = await this.fetchWithTimeout(`${this.serverUrl}/prompt`, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ prompt: resolvedPrompt }),
        }, 15000)
      }
      catch (e: any) {
        throw new Error(`Cannot connect to ComfyUI at ${this.serverUrl}: ${e.message}`)
      }

      if (!queueResp.ok) {
        const errorBody = await queueResp.text()
        throw new Error(`Workflow error: ${errorBody.slice(0, 200)}`)
      }

      const queueData = await queueResp.json()
      const promptId = queueData.prompt_id
      if (!promptId) {
        throw new Error('ComfyUI returned no prompt_id')
      }

      log.log(`[ComfyUI] Queued prompt ${promptId} for job ${jobId}`)
      this.updateStatus(jobId, { status: 'running', actionLabel: 'Generating...' })

      // 3. Poll /history/{prompt_id} until completion
      let historyDone = false

View on GitHub (pinned to 27111382b4)

Solutions

  1. Confirm ComfyUI is running and reachable at this.serverUrl (curl the /system_stats endpoint).
  2. Correct the serverUrl in the artistry/ComfyUI config to the actual host:port.
  3. Check for firewall/network/VPN blocking the port.
  4. If the server is just slow, raise the fetchWithTimeout (currently 15000ms) for the /prompt call.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate reachability before queuing a prompt
async function comfyUIAlive(serverUrl: string): Promise<boolean> {
  try {
    const r = await fetch(`${serverUrl}/system_stats`, { signal: AbortSignal.timeout(5000) })
    return r.ok
  } catch {
    return false
  }
}

Try / catch

try {
  return await provider.generate(request)
} catch (e) {
  if (/Cannot connect to ComfyUI/.test(errorMessageFrom(e) ?? '')) {
    // surface a reconnect prompt to the user; do not auto-loop
    throw new Error('ComfyUI unreachable. Check it is running and the URL is correct.')
  }
  throw e
}

Prevention

When it happens

Trigger: POST to /prompt cannot establish a connection — ComfyUI server is down, wrong host/port, DNS failure, TLS error, connection refused, or the 15-second fetchWithTimeout expired before a response (server too slow to even accept the connection).

Common situations: ComfyUI process crashed or was stopped; serverUrl is wrong or stale (e.g. localhost vs LAN IP); firewall blocks the port; the 15s timeout is too short for a heavily loaded ComfyUI; VPN/network changed after config.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/4d67ec77119ab1f4. Report an issue: GitHub.