{"record":{"id":"e181f5dec9225517","repo":"moeru-ai/airi","slug":"comfyui-disconnected-during-polling-e-message","errorCode":null,"errorMessage":"ComfyUI disconnected during polling: ${e.message}","messagePattern":"ComfyUI disconnected during polling: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/stage-tamagotchi/src/main/services/airi/widgets/providers/comfyui.ts","lineNumber":182,"sourceCode":"\n      while (!historyDone) {\n        await new Promise(r => setTimeout(r, POLL_INTERVAL_MS))\n        attempt++\n\n        if (Date.now() - startTime > POLL_TIMEOUT_MS) {\n          throw new Error('Generation timed out after 5 minutes')\n        }\n\n        if (attempt % 3 === 0) {\n          log.log(`[ComfyUI] Polling history for ${promptId}... attempt ${attempt}`)\n        }\n\n        let histResp: Response\n        try {\n          histResp = await this.fetchWithTimeout(`${this.serverUrl}/history/${promptId}`, {}, 10000)\n        }\n        catch (e: any) {\n          throw new Error(`ComfyUI disconnected during polling: ${e.message}`)\n        }\n\n        if (histResp.ok) {\n          const histData = await histResp.json()\n          if (histData[promptId]) {\n            let outputs = histData[promptId].outputs\n            const stats = histData[promptId].status\n\n            // 3.1. Race condition protection: If outputs are missing, wait a beat and retry once\n            if ((!outputs || Object.keys(outputs).length === 0) && !historyDone) {\n              log.warn(`[ComfyUI] Job ${jobId} finished but outputs are empty. Retrying history in 1s...`)\n              await new Promise(r => setTimeout(r, 1000))\n              const retryResp = await this.fetchWithTimeout(`${this.serverUrl}/history/${promptId}`, {}, 10000)\n              if (retryResp.ok) {\n                const retryData = await retryResp.json()\n                if (retryData[promptId] && retryData[promptId].outputs) {\n                  log.log(`[ComfyUI] Retry successful for ${jobId}. Managed to find outputs!`)\n                  outputs = retryData[promptId].outputs","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/apps/stage-tamagotchi/src/main/services/airi/widgets/providers/comfyui.ts#L164-L200","documentation":"Thrown by the ComfyUI provider when fetchWithTimeout to <serverUrl>/history/{promptId} throws a network-level error during the polling loop. Unlike a non-ok response, this means the fetch itself failed (connection dropped, DNS, timeout) and the provider treats mid-poll disconnection as fatal.","triggerScenarios":"During the polling loop the connection to ComfyUI is lost — the server crashed, network dropped, the 10-second fetchWithTimeout elapsed (server hung), or a transient network blip interrupted the history fetch.","commonSituations":"ComfyUI process restarted/crashed mid-generation; Wi-Fi/VPN flapped; the ComfyUI host is overloaded and stops responding within the 10s history timeout; a proxy/load balancer cut an idle connection.","solutions":["Verify ComfyUI is still running and reachable at serverUrl when the error occurs.","If the disconnection is transient, add retry logic around the history fetch instead of failing immediately.","Raise the history fetchWithTimeout (10000ms) if ComfyUI is slow to respond under load.","Stabilize the network path to the ComfyUI host (wired connection, fixed host)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await provider.generate(request)\n} catch (e) {\n  if (/disconnected during polling/.test(errorMessageFrom(e) ?? '')) {\n    // optionally wait and retry once if the drop looks transient\n    await new Promise(r => setTimeout(r, 2000))\n    return await provider.generate(request)\n  }\n  throw e\n}","preventionTips":["Add bounded retry around the history fetch for transient network drops.","Keep the ComfyUI host on a stable, low-latency connection.","Raise the 10s history fetchWithTimeout if the host is occasionally slow."],"tags":["comfyui","network","polling","connection","artistry"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}