{"record":{"id":"c1b365a5b47d8e0b","repo":"abi/screenshot-to-code","slug":"request-timed-out","errorCode":null,"errorMessage":"Request timed out","messagePattern":"Request timed out","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"backend/image_generation/replicate.py","lineNumber":97,"sourceCode":"    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)\n            final_response = await _poll_prediction(client, prediction_id, headers)\n            return final_response.get(\"output\")\n        except httpx.HTTPStatusError as exc:\n            raise ValueError(f\"HTTP error occurred: {exc}\") from exc\n        except httpx.RequestError as exc:\n            raise ValueError(f\"An error occurred while requesting: {exc}\") from exc\n        except asyncio.TimeoutError as exc:\n            raise TimeoutError(\"Request timed out\") from exc\n        except (TimeoutError, ValueError):\n            raise\n        except Exception as exc:\n            raise ValueError(f\"An unexpected error occurred: {exc}\") from exc\n\n\ndef _extract_output_url(result: Any, context: str) -> str:\n    if isinstance(result, str):\n        return result\n\n    if isinstance(result, dict):\n        url = cast(Any, result.get(\"url\"))\n        if isinstance(url, str) and url:\n            return url\n\n    if isinstance(result, list) and len(result) > 0:\n        first = cast(Any, result[0])\n        if isinstance(first, str) and first:","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/image_generation/replicate.py#L79-L115","documentation":"Raised when asyncio.TimeoutError escapes the try block in _run_prediction and is converted to the builtin TimeoutError. In practice this is the socket-level timeout path (httpx default timeouts) rather than the poll-budget exhaustion, which raises TimeoutError(\"Inference timed out\") directly and passes through the (TimeoutError, ValueError) re-raise untouched. Note the bare TimeoutError(\"Request timed out\") message distinguishes the two.","triggerScenarios":"An httpx operation exceeding its default timeout during the creation POST or a polling GET and surfacing as asyncio.TimeoutError; on some event-loop/HTTP combinations a CancelledError-adjacent timeout during a long poll.","commonSituations":"Slow mobile/tethered connections where individual HTTP round-trips exceed httpx defaults; overloaded Replicate endpoints making even status GETs slow; event loop stalls from CPU-heavy work in the same process delaying async I/O.","solutions":["Distinguish from \"Inference timed out\": this one is a single-request timeout, not poll-budget exhaustion.","Pass an explicit larger timeout when constructing httpx.AsyncClient (e.g. httpx.Timeout(60.0)).","Retry the operation — single-request timeouts are typically transient.","Avoid blocking the event loop with sync work during generation."],"exampleFix":"# before\nasync with httpx.AsyncClient() as client:\n\n# after\nasync with httpx.AsyncClient(timeout=httpx.Timeout(60.0, connect=10.0)) as client:","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    output = await call_replicate_model(model, input, token)\nexcept TimeoutError as e:\n    if str(e) == \"Request timed out\":\n        # single-request timeout: safe to retry immediately\n        output = await call_replicate_model(model, input, token)\n    raise","preventionTips":["Give the AsyncClient an explicit generous timeout instead of relying on httpx defaults","Distinguish \"Request timed out\" (one round-trip) from \"Inference timed out\" (poll budget)","Keep CPU-heavy sync work off the event loop during generation"],"tags":["replicate","timeout","httpx","asyncio"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}