microsoft/semantic-kernel · error · AgentInvokeException
Polling timed out for run id: `{run.id}` and thread id: `{th
Error message
Polling timed out for run id: `{run.id}` and thread id: `{thread_id}` after waiting {timeout_duration}. What it means
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.
Source
Thrown at python/semantic_kernel/agents/azure_ai/agent_thread_actions.py:1106
@classmethod
async def _poll_run_status(
cls: type[_T], agent: "AzureAIAgent", run: ThreadRun, thread_id: str, polling_options: RunPollingOptions
) -> ThreadRun:
"""Poll the run status."""
logger.info(f"Polling run status: {run.id}, threadId: {thread_id}")
try:
run = await asyncio.wait_for(
cls._poll_loop(agent=agent, run=run, thread_id=thread_id, polling_options=polling_options),
timeout=polling_options.run_polling_timeout.total_seconds(),
)
except asyncio.TimeoutError:
timeout_duration = polling_options.run_polling_timeout
error_message = (
f"Polling timed out for run id: `{run.id}` and thread id: `{thread_id}` "
f"after waiting {timeout_duration}."
)
logger.error(error_message)
raise AgentInvokeException(error_message)
logger.info(f"Polled run status: {run.status}, {run.id}, threadId: {thread_id}")
return run
@classmethod
async def _poll_loop(
cls: type[_T], agent: "AzureAIAgent", run: ThreadRun, thread_id: str, polling_options: RunPollingOptions
) -> ThreadRun:
"""Continuously poll the run status until it is no longer pending."""
count = 0
while True:
await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())
count += 1
try:
run = await agent.client.agents.runs.get(run_id=run.id, thread_id=thread_id)
except Exception as e:
logger.warning(f"Failed to retrieve run for run id: `{run.id}` and thread id: `{thread_id}`: {e}")
if run.status not in cls.polling_status:
breakView on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before polling = RunPollingOptions() # default timeout await agent.invoke(thread, ...) // after from datetime import timedelta polling = RunPollingOptions(run_polling_timeout=timedelta(minutes=10)) await agent.invoke(thread, ..., polling_options=polling)
Defensive patterns
Strategy: retry
Validate before calling
from datetime import timedelta
from semantic_kernel.connectors.ai.azure_ai.agent.run_polling_options import RunPollingOptions
def polling_for(workload: str) -> RunPollingOptions:
minutes = 10 if workload == "heavy" else 2
return RunPollingOptions(run_polling_timeout=timedelta(minutes=minutes)) Try / catch
from semantic_kernel.exceptions import AgentInvokeException
import asyncio
for attempt in range(3):
try:
return await agent.invoke(thread, polling_options=polling)
except AgentInvokeException as e:
if "Polling timed out" not in str(e):
raise
polling.run_polling_timeout *= 2
await asyncio.sleep(backoff)
raise last_error Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Agent did not reach status {status} within the specified tim
- Timeout waiting for OAuth callback
- Agent did not reach status {status} within the specified tim
- Polling timed out for run id: `{run.id}` and thread id: `{th
- Polling timed out before completion.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/63858cb299b4ddbc.
Report an issue: GitHub.