{"record":{"id":"7551961d6829a287","repo":"BerriAI/litellm","slug":"task-task-id-did-not-complete-within-max-attemp","errorCode":null,"errorMessage":"Task {task_id} did not complete within {max_attempts * poll_interval} seconds","messagePattern":"Task (.+?) did not complete within (.+?) seconds","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"litellm/a2a_protocol/providers/pydantic_ai_agents/transformation.py","lineNumber":151,"sourceCode":"                },\n            )\n            response.raise_for_status()\n            poll_data = _STR_KEY_DICT_ADAPTER.validate_python(response.json())\n\n            result = _STR_KEY_DICT_ADAPTER.validate_python(poll_data.get(\"result\", {}))\n            status = _STR_KEY_DICT_ADAPTER.validate_python(result.get(\"status\", {}))\n            state = status.get(\"state\", \"\")\n\n            verbose_logger.debug(\"Pydantic AI: Poll attempt %s/%s, state=%s\", attempt + 1, max_attempts, state)\n\n            if state == \"completed\":\n                return poll_data\n            elif state in (\"failed\", \"canceled\"):\n                raise Exception(f\"Task {task_id} ended with state: {state}\")\n\n            await asyncio.sleep(poll_interval)\n\n        raise TimeoutError(f\"Task {task_id} did not complete within {max_attempts * poll_interval} seconds\")\n\n    @staticmethod\n    async def _send_and_poll_raw(\n        api_base: str,\n        request_id: str,\n        params: \"_SupportsModelDump | _SupportsPydanticDict | Mapping[str, object]\",\n        timeout: float = 60.0,\n        agent_extra_headers: dict[str, str] | None = None,\n    ) -> dict[str, object]:\n        \"\"\"\n        Send a request to Pydantic AI agent and return the raw task response.\n\n        This is an internal method used by both non-streaming and streaming handlers.\n        Returns the raw Pydantic AI task format with history/artifacts.\n\n        Args:\n            api_base: Base URL of the Pydantic AI agent\n            request_id: A2A JSON-RPC request ID","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/a2a_protocol/providers/pydantic_ai_agents/transformation.py#L133-L169","documentation":"TimeoutError raised when the polling loop for a Pydantic AI task exhausts max_attempts * poll_interval seconds without the task reaching 'completed' (and without hitting failed/canceled). The task may still be running server-side.","triggerScenarios":"Long-running agent task that never transitions to completed within the poll budget, e.g. max_attempts=60, poll_interval=1 and the task takes 90s.","commonSituations":"Slow LLM/tool calls inside the agent; poll budget not scaled with expected workload; network stalls between LiteLLM and the agent.","solutions":["Increase max_attempts and/or poll_interval so the budget covers the expected task duration","Optimize/scale the Pydantic AI agent so tasks finish faster","On TimeoutError, optionally re-query the task by id to check if it completed late"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"expected_max_seconds = 120\nmax_attempts, poll_interval = 60, 2  # budget 120s > expected\n# ensure max_attempts * poll_interval >= worst-case task duration","typeGuard":null,"tryCatchPattern":"import asyncio\ntry:\n    result = await poll_task(task_id)\nexcept TimeoutError:\n    logger.warning(\"task %s poll timed out; retrying once\", task_id)\n    await asyncio.sleep(5)\n    result = await poll_task(task_id)  # task may have completed late","preventionTips":["Size max_attempts * poll_interval above the agent's worst-case task duration","Track p95 task duration and alert when polls approach the budget","Treat late completion as a possible eventual success: re-check by task id on timeout"],"tags":["a2a","litellm","pydantic-ai","timeout","polling"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}