{"record":{"id":"4708a6a90274c196","repo":"abi/screenshot-to-code","slug":"inference-failed","errorCode":null,"errorMessage":"Inference failed","messagePattern":"Inference failed","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/image_generation/replicate.py","lineNumber":71,"sourceCode":"    status_check_url = f\"{REPLICATE_API_BASE_URL}/predictions/{prediction_id}\"\n\n    for _ in range(MAX_POLLS):\n        await asyncio.sleep(POLL_INTERVAL_SECONDS)\n        status_response = await client.get(status_check_url, headers=headers)\n        status_response.raise_for_status()\n        status_response_raw: Any = status_response.json()\n        if not isinstance(status_response_raw, dict):\n            raise ValueError(\"Invalid prediction status response.\")\n        status_response_json = cast(dict[str, Any], status_response_raw)\n\n        status = status_response_json.get(\"status\")\n        if status == \"succeeded\":\n            return cast(dict[str, Any], status_response_json)\n        if status == \"error\":\n            error_message = str(status_response_json.get(\"error\", \"Unknown error\"))\n            raise ValueError(f\"Inference errored out: {error_message}\")\n        if status == \"failed\":\n            raise ValueError(\"Inference failed\")\n\n    raise TimeoutError(\"Inference timed out\")\n\n\nasync def _run_prediction(\n    endpoint_url: str, payload: dict[str, Any], api_token: str\n) -> Any:\n    headers = _build_headers(api_token)\n\n    async with httpx.AsyncClient() as client:\n        try:\n            response = await client.post(endpoint_url, headers=headers, json=payload)\n            response.raise_for_status()\n            response_json = response.json()\n            if not isinstance(response_json, dict):\n                raise ValueError(\"Invalid prediction creation response.\")\n\n            prediction_id = _extract_prediction_id(response_json)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/image_generation/replicate.py#L53-L89","documentation":"Raised in _poll_prediction when the prediction's status becomes \"failed\": Replicate terminated the prediction without the detailed \"error\" payload. Unlike the \"error\" status (which carries an error message), \"failed\" gives no diagnostics here, so this ValueError is the generic terminal-failure signal after MAX_POLLS rounds of polling.","triggerScenarios":"A prediction that transitions to status \"failed\" on Replicate's side — commonly GPU/infra failures, canceled predictions, cold-start crashes, or model runtime exceptions that don't populate the error field.","commonSituations":"Transient Replicate infra hiccups; model version removed or deprecated mid-flight; overloaded models during peak times.","solutions":["Retry the call once — \"failed\" is frequently transient infrastructure, unlike parameter errors.","Check the Replicate status page and the prediction in the Replicate dashboard (its logs often explain the failure).","Pin a stable model version if the failure repeats with the latest tag.","If persistent, test the same input via curl against the Replicate API to isolate client vs model."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    try:\n        output = await call_replicate_model(model, input, token)\n        break\n    except ValueError as e:\n        if str(e) == \"Inference failed\" and attempt == 0:\n            continue  # status \"failed\" is often transient infra\n        raise","preventionTips":["Retry \"Inference failed\" once before reporting — it's frequently infra-side","Check the prediction's logs in the Replicate dashboard for the real cause","Pin stable model versions to avoid mid-flight deprecations"],"tags":["replicate","image-generation","inference-failure","retryable"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}