{"record":{"id":"63858cb299b4ddbc","repo":"microsoft/semantic-kernel","slug":"polling-timed-out-for-run-id-run-id-and-threa","errorCode":null,"errorMessage":"Polling timed out for run id: `{run.id}` and thread id: `{thread_id}` after waiting {timeout_duration}.","messagePattern":"Polling timed out for run id: `(.+?)` and thread id: `(.+?)` after waiting (.+?)\\.","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/azure_ai/agent_thread_actions.py","lineNumber":1106,"sourceCode":"    @classmethod\n    async def _poll_run_status(\n        cls: type[_T], agent: \"AzureAIAgent\", run: ThreadRun, thread_id: str, polling_options: RunPollingOptions\n    ) -> ThreadRun:\n        \"\"\"Poll the run status.\"\"\"\n        logger.info(f\"Polling run status: {run.id}, threadId: {thread_id}\")\n        try:\n            run = await asyncio.wait_for(\n                cls._poll_loop(agent=agent, run=run, thread_id=thread_id, polling_options=polling_options),\n                timeout=polling_options.run_polling_timeout.total_seconds(),\n            )\n        except asyncio.TimeoutError:\n            timeout_duration = polling_options.run_polling_timeout\n            error_message = (\n                f\"Polling timed out for run id: `{run.id}` and thread id: `{thread_id}` \"\n                f\"after waiting {timeout_duration}.\"\n            )\n            logger.error(error_message)\n            raise AgentInvokeException(error_message)\n        logger.info(f\"Polled run status: {run.status}, {run.id}, threadId: {thread_id}\")\n        return run\n\n    @classmethod\n    async def _poll_loop(\n        cls: type[_T], agent: \"AzureAIAgent\", run: ThreadRun, thread_id: str, polling_options: RunPollingOptions\n    ) -> ThreadRun:\n        \"\"\"Continuously poll the run status until it is no longer pending.\"\"\"\n        count = 0\n        while True:\n            await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())\n            count += 1\n            try:\n                run = await agent.client.agents.runs.get(run_id=run.id, thread_id=thread_id)\n            except Exception as e:\n                logger.warning(f\"Failed to retrieve run for run id: `{run.id}` and thread id: `{thread_id}`: {e}\")\n            if run.status not in cls.polling_status:\n                break","sourceCodeStart":1088,"sourceCodeEnd":1124,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/agent_thread_actions.py#L1088-L1124","documentation":"Raised when the polling loop for a thread run exceeds RunPollingOptions.run_polling_timeout without the run leaving a pending/queued state. This wraps asyncio.TimeoutError from asyncio.wait_for around _poll_loop.","triggerScenarios":"A long-running Azure AI agent run (large indexing, heavy code interpreter work, service-side slowness) that does not reach a terminal status before run_polling_timeout elapses.","commonSituations":"Default timeout too short for complex runs; Azure service degradation or throttling; back-end queued behind a large batch; network latency inflating each poll interval.","solutions":["Increase RunPollingOptions.run_polling_timeout (a timedelta) to a value appropriate for the workload.","Retry the invoke; transient service-side delays often resolve. Use the run.id from the exception to inspect run status in the Azure portal.","Inspect polling_options.get_polling_interval backoff curve and reduce the interval if network round-trips dominate.","Verify Azure AI service health and quota are not throttling the run."],"exampleFix":"// before\npolling = RunPollingOptions()  # default timeout\nawait agent.invoke(thread, ...)\n\n// after\nfrom datetime import timedelta\npolling = RunPollingOptions(run_polling_timeout=timedelta(minutes=10))\nawait agent.invoke(thread, ..., polling_options=polling)","handlingStrategy":"retry","validationCode":"from datetime import timedelta\nfrom semantic_kernel.connectors.ai.azure_ai.agent.run_polling_options import RunPollingOptions\n\ndef polling_for(workload: str) -> RunPollingOptions:\n    minutes = 10 if workload == \"heavy\" else 2\n    return RunPollingOptions(run_polling_timeout=timedelta(minutes=minutes))","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import AgentInvokeException\nimport asyncio\n\nfor attempt in range(3):\n    try:\n        return await agent.invoke(thread, polling_options=polling)\n    except AgentInvokeException as e:\n        if \"Polling timed out\" not in str(e):\n            raise\n        polling.run_polling_timeout *= 2\nawait asyncio.sleep(backoff)\nraise last_error","preventionTips":["Size run_polling_timeout to the worst expected run duration for the workload.","Log run.id on timeout so you can inspect the run in the Azure portal.","Monitor Azure AI service health for throttling that stalls runs."],"tags":["azure-ai-agent","polling","timeout","network"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}