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

_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.

Source

Thrown at python/semantic_kernel/agents/open_ai/assistant_thread_actions.py:743

        ]

    @classmethod
    async def _poll_run_status(
        cls: type[_T], agent: "OpenAIAssistantAgent", run: "Run", thread_id: str, polling_options: RunPollingOptions
    ) -> "Run":
        """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, run, thread_id, 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}` after waiting {timeout_duration}."  # noqa: E501
            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: "OpenAIAssistantAgent", run: "Run", thread_id: str, polling_options: RunPollingOptions
    ) -> "Run":
        """Internal polling loop."""
        count = 0
        while True:
            await asyncio.sleep(polling_options.get_polling_interval(count).total_seconds())
            count += 1

            try:
                run = await agent.client.beta.threads.runs.retrieve(run.id, thread_id=thread_id)
            except Exception as e:
                logging.warning(f"Failed to retrieve run for run id: `{run.id}` and thread id: `{thread_id}`: {e}")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Increase polling_options.run_polling_timeout (e.g. RunPollingOptions(run_polling_timeout=timedelta(minutes=5))) to match expected run duration.
  2. Speed up or async-ify any tool functions so required_action resolves quickly and the run can complete.
  3. Ensure tool outputs are actually submitted for requires_action runs so polling can progress.
  4. Retry once after a timeout (transient stalls), but raise the timeout if runs consistently exceed it.

Example fix

// before
await assistant.invoke(thread_id=tid)  # Polling timed out

// after
from datetime import timedelta
from semantic_kernel.agents.open_ai import RunPollingOptions
assistant.polling_options = RunPollingOptions(
    run_polling_timeout=timedelta(minutes=10),
)
await assistant.invoke(thread_id=tid)
Defensive patterns

Strategy: retry

Try / catch

from semantic_kernel.exceptions import AgentInvokeException

try:
    await assistant.invoke(thread_id=tid)
except AgentInvokeException as e:
    if "Polling timed out" in str(e):
        assistant.polling_options.run_polling_timeout = timedelta(minutes=10)
        # then retry once

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/f0fc8d05ca506d67. Report an issue: GitHub.