{"record":{"id":"0e638942f6b440eb","repo":"microsoft/semantic-kernel","slug":"run-failed-with-status-run-status-for-agent-0e6389","errorCode":null,"errorMessage":"Run failed with status: `{run.status}` for agent `{agent.name}` and thread `{thread_id}` with error: {error_message} or incomplete details: {incomplete_details}","messagePattern":"Run failed with status: `(.+?)` for agent `(.+?)` and thread `(.+?)` with error: (.+?) or incomplete details: (.+?)","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/assistant_thread_actions.py","lineNumber":255,"sourceCode":"            **run_options,\n        )\n\n        processed_step_ids = set()\n        function_steps: dict[str, \"FunctionCallContent\"] = {}\n\n        while run.status != \"completed\":\n            run = await cls._poll_run_status(\n                agent=agent, run=run, thread_id=thread_id, polling_options=polling_options or agent.polling_options\n            )\n\n            if run.status in cls.error_message_states:\n                error_message = \"\"\n                if run.last_error and run.last_error.message:\n                    error_message = run.last_error.message\n                incomplete_details = \"\"\n                if run.incomplete_details:\n                    incomplete_details = str(run.incomplete_details.reason)\n                raise AgentInvokeException(\n                    f\"Run failed with status: `{run.status}` for agent `{agent.name}` and thread `{thread_id}` \"\n                    f\"with error: {error_message} or incomplete details: {incomplete_details}\"\n                )\n\n            # Check if function calling required\n            if run.status == \"requires_action\":\n                logger.debug(f\"Run [{run.id}] requires action for agent `{agent.name}` and thread `{thread_id}`\")\n                fccs = get_function_call_contents(run, function_steps)\n                if fccs:\n                    logger.debug(\n                        f\"Yielding `generate_function_call_content` for agent `{agent.name}` and \"\n                        f\"thread `{thread_id}`, visibility False\"\n                    )\n                    yield False, generate_function_call_content(agent_name=agent.name, fccs=fccs)\n\n                    from semantic_kernel.contents.chat_history import ChatHistory\n\n                    chat_history = ChatHistory()","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/assistant_thread_actions.py#L237-L273","documentation":"While polling a (non-streaming) assistant run, if run.status lands in error_message_states (e.g. failed, cancelled, expired, incomplete), the run is terminal and AgentInvokeException is raised. The message embeds agent name, thread id, run.last_error.message (if any) and run.incomplete_details.reason (if any) to aid diagnosis.","triggerScenarios":"The OpenAI run ends in a failing/terminal state: server-side failure, cancellation, expiry, or incompleteness (e.g. token/model limits hit). The poll loop detects the status and raises.","commonSituations":"Function/tool outputs that error server-side; rate limiting or quota exhaustion; a run left polling past its expiry; incomplete runs due to max completion tokens or max_prompt_tokens being too low; cancelled runs from dashboard/another client.","solutions":["Read the embedded error_message (run.last_error) and incomplete_details to classify the failure precisely.","For 'incomplete' status, raise max_completion_tokens / max_prompt_tokens or reduce input size, then retry.","For transient failures (rate limit, server error), retry the invoke with exponential backoff.","Verify registered tool/function outputs are well-formed and fast to prevent server-side run failures."],"exampleFix":"// before\nrun = await assistant.invoke(thread_id=tid)  # raises if run incomplete due to token cap\n\n// after\nfrom semantic_kernel.agents.open_ai import RunPollingOptions\nagent.polling_options = RunPollingOptions()\nagent.max_completion_tokens = 4096  # give the run room to finish\nrun = await assistant.invoke(thread_id=tid)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import AgentInvokeException\nfrom tenacity import retry, stop_after_attempt, wait_exponential\n\n@retry(stop=stop_after_attempt(4), wait=wait_exponential(), retry=retry_if_exception_type(AgentInvokeException))\nasync def invoke():\n    try:\n        return await assistant.invoke(thread_id=tid)\n    except AgentInvokeException as e:\n        if \"incomplete\" in str(e):\n            raise  # not transient, fix token caps instead\n        raise","preventionTips":["Set max_completion_tokens/max_prompt_tokens high enough for your workload.","Keep tool outputs small and fast to avoid server-side run failures.","Retry transient (rate-limit/5xx) failures with backoff; fix persistent ones."],"tags":["openai","assistant","run","polling","agentinvoke"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}