{"record":{"id":"c1c677fb5573182c","repo":"datawhalechina/hello-agents","slug":"str-e","errorCode":null,"errorMessage":"任务执行失败: {str(e)}","messagePattern":"任务执行失败: (.+?)","errorType":"exception","errorClass":"AgentException","httpStatus":500,"severity":"error","filePath":"Co-creation-projects/Apricity-InnocoreAI/agents/controller.py","lineNumber":152,"sourceCode":"                task[\"result\"] = result\n                \n                await self._trigger_event(\"task_completed\", task)\n                \n                # 执行回调\n                if task[\"callback\"]:\n                    await task[\"callback\"](task)\n                \n                return result\n                \n            except Exception as e:\n                task[\"status\"] = TaskStatus.FAILED\n                task[\"completed_at\"] = datetime.now()\n                task[\"error\"] = str(e)\n                \n                await self._trigger_event(\"task_failed\", task)\n                \n                logger.error(f\"任务执行失败 {task_id}: {str(e)}\")\n                raise AgentException(f\"任务执行失败: {str(e)}\")\n            \n            finally:\n                # 移动到历史记录\n                self.task_history.append(task.copy())\n                del self.active_tasks[task_id]\n    \n    async def _execute_paper_hunting(self, task: Dict) -> Dict[str, Any]:\n        \"\"\"执行论文抓取任务\"\"\"\n        input_data = task[\"input_data\"]\n        \n        # 调用Hunter Agent\n        hunter_result = await self.agents[\"hunter\"].run(input_data)\n        task[\"agent_results\"][\"hunter\"] = hunter_result\n        \n        return {\n            \"task_type\": \"paper_hunting\",\n            \"papers_found\": hunter_result.get(\"downloaded_papers\", []),\n            \"statistics\": {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Apricity-InnocoreAI/agents/controller.py#L134-L170","documentation":"Outer wrapper in ControllerAgent.execute_task's except: any exception raised by the per-type executor (_execute_paper_hunting and friends) — including nested AgentExceptions from hunter/miner/coach/validator — is re-wrapped as AgentException('任务执行失败: <original>'). Side effects before re-raising: task status set to FAILED, error recorded, task_failed event triggered. The finally block then appends the task to task_history and deletes it from active_tasks, so the ID is gone regardless.","triggerScenarios":"hunter.run failing on ArXiv HTTP error (error 55), miner.run failing on missing paper (error 57), coach rejecting a task type (error 49), missing required fields (error 48) — any of these bubbles through the executor and gains the '任务执行失败:' prefix.","commonSituations":"Reading only the outer prefix and debugging the controller instead of the inner agent; double-wrapping making the message chain long; task_failed event handlers themselves failing and masking the original error.","solutions":["Strip the outer prefix and diagnose the suffixed inner error — the controller is almost never the culprit.","Re-raise AgentException unchanged (except AgentException: raise) so error 48/49/51 style messages keep their original type and text.","Use raise ... from e to preserve the chain in logs/Sentry.","Check task_history (or the task_failed event payload) for task['error'] to see the same inner message with status context."],"exampleFix":"# before\nexcept Exception as e:\n    ...\n    raise AgentException(f\"任务执行失败: {str(e)}\")\n\n# after\nexcept AgentException:\n    task[\"status\"] = TaskStatus.FAILED\n    task[\"completed_at\"] = datetime.now()\n    raise\nexcept Exception as e:\n    task[\"status\"] = TaskStatus.FAILED\n    task[\"completed_at\"] = datetime.now()\n    task[\"error\"] = str(e)\n    raise AgentException(f\"任务执行失败: {e}\") from e","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await controller.execute_task(task_id)\nexcept AgentException as e:\n    root = str(e).split(\"任务执行失败:\", 1)[-1].strip()\n    # root carries the inner agent failure (hunter/miner/coach/validator) — route on it\n    if \"API请求失败\" in root: alert_ops(root)\n    elif \"缺少必需字段\" in root or \"不支持\" in root: return 422\n    raise","preventionTips":["Log task['error'] from task_history for post-mortems — the controller stores it before re-raising.","Re-raise inner AgentExceptions unchanged to keep error types stable across layers.","Subscribe to the task_failed event for monitoring instead of scraping exceptions."],"tags":["python","orchestration","error-wrapping","task-queue"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}