{"record":{"id":"f0fc8d05ca506d67","repo":"microsoft/semantic-kernel","slug":"polling-timed-out-for-run-id-run-id-and-threa-f0fc8d","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/open_ai/assistant_thread_actions.py","lineNumber":743,"sourceCode":"        ]\n\n    @classmethod\n    async def _poll_run_status(\n        cls: type[_T], agent: \"OpenAIAssistantAgent\", run: \"Run\", thread_id: str, polling_options: RunPollingOptions\n    ) -> \"Run\":\n        \"\"\"Poll the run status.\"\"\"\n        logger.info(f\"Polling run status: {run.id}, threadId: {thread_id}\")\n\n        try:\n            run = await asyncio.wait_for(\n                cls._poll_loop(agent, run, thread_id, 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 = f\"Polling timed out for run id: `{run.id}` and thread id: `{thread_id}` after waiting {timeout_duration}.\"  # noqa: E501\n            logger.error(error_message)\n            raise AgentInvokeException(error_message)\n\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: \"OpenAIAssistantAgent\", run: \"Run\", thread_id: str, polling_options: RunPollingOptions\n    ) -> \"Run\":\n        \"\"\"Internal polling loop.\"\"\"\n        count = 0\n        while True:\n            await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())\n            count += 1\n\n            try:\n                run = await agent.client.beta.threads.runs.retrieve(run.id, thread_id=thread_id)\n            except Exception as e:\n                logging.warning(f\"Failed to retrieve run for run id: `{run.id}` and thread id: `{thread_id}`: {e}\")","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/assistant_thread_actions.py#L725-L761","documentation":"_poll_run_status wraps the internal _poll_loop in asyncio.wait_for with a timeout taken from polling_options.run_polling_timeout. If the run does not reach a terminal status within that duration, asyncio.TimeoutError is caught and re-raised as AgentInvokeException with the run id, thread id, and the configured timeout duration.","triggerScenarios":"The assistant run takes longer to complete than polling_options.run_polling_timeout (e.g. a slow model, a long-running required tool action, or network stalls), so asyncio.wait_for fires TimeoutError.","commonSituations":"Default run_polling_timeout too low for the workload; functions that take minutes to return; congested/slow network to OpenAI; runs stuck in requires_action because tool outputs were never submitted.","solutions":["Increase polling_options.run_polling_timeout (e.g. RunPollingOptions(run_polling_timeout=timedelta(minutes=5))) to match expected run duration.","Speed up or async-ify any tool functions so required_action resolves quickly and the run can complete.","Ensure tool outputs are actually submitted for requires_action runs so polling can progress.","Retry once after a timeout (transient stalls), but raise the timeout if runs consistently exceed it."],"exampleFix":"// before\nawait assistant.invoke(thread_id=tid)  # Polling timed out\n\n// after\nfrom datetime import timedelta\nfrom semantic_kernel.agents.open_ai import RunPollingOptions\nassistant.polling_options = RunPollingOptions(\n    run_polling_timeout=timedelta(minutes=10),\n)\nawait assistant.invoke(thread_id=tid)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import AgentInvokeException\n\ntry:\n    await assistant.invoke(thread_id=tid)\nexcept AgentInvokeException as e:\n    if \"Polling timed out\" in str(e):\n        assistant.polling_options.run_polling_timeout = timedelta(minutes=10)\n        # then retry once","preventionTips":["Size run_polling_timeout to your worst-case run duration.","Make tool functions return quickly so requires_action resolves fast.","Always submit tool outputs for requires_action runs so polling can progress."],"tags":["openai","assistant","polling","timeout","agentinvoke"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}