{"record":{"id":"7dfb826e18d186f3","repo":"microsoft/semantic-kernel","slug":"run-failed-with-status-run-status-for-agent-7dfb82","errorCode":null,"errorMessage":"Run failed with status: `{run.status}` for agent `{agent.name}` and thread `{thread_id}` with error: {error_message}","messagePattern":"Run failed with status: `(.+?)` for agent `(.+?)` and thread `(.+?)` with error: (.+?)","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/assistant_thread_actions.py","lineNumber":567,"sourceCode":"                            for id in active_messages:\n                                step: RunStep = active_messages[id]\n                                message = await cls._retrieve_message(\n                                    agent=agent,\n                                    thread_id=thread_id,\n                                    message_id=id,  # type: ignore\n                                )\n\n                                if message and message.content:\n                                    content = generate_final_streaming_message_content(agent.name, message, step)\n                                    if output_messages is not None:\n                                        output_messages.append(content)\n                        return\n                    elif event.event == \"thread.run.failed\":\n                        run = event.data  # type: ignore\n                        error_message = \"\"\n                        if run.last_error and run.last_error.message:\n                            error_message = run.last_error.message\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}\"\n                        )\n                else:\n                    # If the inner loop completes without encountering a 'break', exit the outer loop\n                    break\n\n    @classmethod\n    async def _handle_streaming_requires_action(\n        cls: type[_T],\n        agent_name: str,\n        kernel: \"Kernel\",\n        run: \"Run\",\n        function_steps: dict[str, \"FunctionCallContent\"],\n        arguments: KernelArguments,\n        function_choice_behavior: FunctionChoiceBehavior | None = None,\n        **kwargs: Any,\n    ) -> FunctionActionResult | None:","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/assistant_thread_actions.py#L549-L585","documentation":"Streaming counterpart of the run-failure guard. While consuming the run event stream, a thread.run.failed event signals the run terminated abnormally; the code raises AgentInvokeException embedding agent name, thread id, and run.last_error.message (empty string if the API supplied none).","triggerScenarios":"The OpenAI run fails during streaming — server-side error, tool-output submission failure, or a model error mid-stream — emitting thread.run.failed. The stream handler maps that event to this exception.","commonSituations":"Malformed tool outputs submitted via submit_tool_outputs_stream; rate limiting/quota hit mid-stream; model errors; concurrent modification/cancellation of the run from another client.","solutions":["Inspect the embedded error_message (run.last_error) to pinpoint the server-side cause.","For tool-output failures, validate FunctionResultContent payloads before streaming submission.","Retry the invoke with backoff for transient (rate-limit / 5xx) failures; restructure inputs for persistent ones.","Ensure no other client or process cancels/overwrites the run during streaming."],"exampleFix":"// before\nasync for msg in assistant.invoke_stream(thread_id=tid):\n    ...  # raises thread.run.failed mid-stream\n\n// after\nfrom tenacity import retry, stop_after_attempt, wait_exponential\n@retry(stop=stop_after_attempt(3), wait=wait_exponential())\nasync def run_once():\n    async for msg in assistant.invoke_stream(thread_id=tid):\n        ...\nawait run_once()","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(3), wait=wait_exponential())\nasync def stream():\n    async for msg in assistant.invoke_stream(thread_id=tid):\n        yield msg\n# wrap consumption; on AgentInvokeException inspect run.last_error via logs","preventionTips":["Validate FunctionResultContent payloads before submitting tool outputs.","Retry transient stream failures (rate-limit/5xx) with backoff.","Avoid concurrent run mutation/cancellation during streaming."],"tags":["openai","assistant","run","streaming","agentinvoke"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}