{"record":{"id":"9976c8c6ec12c66a","repo":"microsoft/autogen","slug":"run-failed-run-last-error-9976c8","errorCode":null,"errorMessage":"Run failed: {run.last_error}","messagePattern":"Run failed: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py","lineNumber":438,"sourceCode":"                    thread_id=self._thread_id,\n                    assistant_id=self._get_assistant_id,\n                )\n            )\n        )\n\n        # Wait for run completion by polling\n        while True:\n            run = await cancellation_token.link_future(\n                asyncio.ensure_future(\n                    self._client.beta.threads.runs.retrieve(  # type: ignore[reportDeprecated]\n                        thread_id=self._thread_id,\n                        run_id=run.id,\n                    )\n                )\n            )\n\n            if run.status == \"failed\":\n                raise ValueError(f\"Run failed: {run.last_error}\")\n\n            # If the run requires action (function calls), execute tools and continue\n            if run.status == \"requires_action\" and run.required_action is not None:\n                tool_calls: List[FunctionCall] = []\n                for required_tool_call in run.required_action.submit_tool_outputs.tool_calls:\n                    if required_tool_call.type == \"function\":\n                        tool_calls.append(\n                            FunctionCall(\n                                id=required_tool_call.id,\n                                name=required_tool_call.function.name,\n                                arguments=required_tool_call.function.arguments,\n                            )\n                        )\n\n                # Add tool call message to inner messages\n                tool_call_msg = ToolCallRequestEvent(source=self.name, content=tool_calls)\n                inner_messages.append(tool_call_msg)\n                event_logger.debug(tool_call_msg)","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py#L420-L456","documentation":"While polling a run on the Assistants API thread, OpenAIAssistantAgent checks run.status each iteration; a terminal status of 'failed' (server-side failure: expired run, model error, rate/quota issues, bad tool definitions) triggers this ValueError carrying run.last_error from OpenAI. The agent surfaces the API's own error detail rather than retrying.","triggerScenarios":"Any assistant run whose status becomes 'failed': invalid/inaccessible model, insufficient quota, run timeout/expiry (runs have a server-side time limit), malformed tool definitions, or content-policy failures.","commonSituations":"Using a deprecated model name on the assistant; hitting OpenAI rate limits or zero billing quota; long tool executions causing run expiry; stale vector stores or file references used by file_search.","solutions":["Read run.last_error in the message — it contains OpenAI's error code/message (e.g. rate_limit_exceeded, invalid_model) and points at the true cause.","For quota/rate errors: wait and retry the on_messages call (the thread is preserved; new input starts a new run).","For invalid_model: update the assistant to a current model via client.beta.assistants.update.","For expired runs: shorten tool execution time or raise the run's expiration when creating it."],"exampleFix":"# before\nresp = await agent.on_messages([TextMessage(source=\"user\", content=\"hi\")], ct)\n\n# after\ntry:\n    resp = await agent.on_messages([TextMessage(source=\"user\", content=\"hi\")], ct)\nexcept ValueError as e:\n    if \"Run failed\" in str(e):\n        print(\"OpenAI run error:\", e)  # inspect run.last_error detail\n        await asyncio.sleep(30)\n        resp = await agent.on_messages([TextMessage(source=\"user\", content=\"hi\")], ct)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await agent.on_messages(msgs, ct)\nexcept ValueError as e:\n    if \"Run failed\" not in str(e):\n        raise\n    detail = str(e)\n    if \"rate\" in detail.lower() or \"quota\" in detail.lower():\n        await asyncio.sleep(30)\n        resp = await agent.on_messages(msgs, ct)\n    else:\n        raise","preventionTips":["Always surface run.last_error — it carries OpenAI's real failure code.","Keep the assistant's model current and billing/quota healthy.","Bound tool execution time to avoid run expiry."],"tags":["openai","assistants-api","run-failure","api-error"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}