{"record":{"id":"1ac5e722f0731c8c","repo":"datawhalechina/hello-agents","slug":"task-type-1ac5e7","errorCode":null,"errorMessage":"不支持的任务类型: {task['type']}","messagePattern":"不支持的任务类型: (.+?)","errorType":"exception","errorClass":"AgentException","httpStatus":500,"severity":"error","filePath":"Co-creation-projects/Apricity-InnocoreAI/agents/controller.py","lineNumber":130,"sourceCode":"            try:\n                task[\"status\"] = TaskStatus.RUNNING\n                task[\"started_at\"] = datetime.now()\n                \n                await self._trigger_event(\"task_started\", task)\n                \n                # 根据任务类型执行相应的逻辑\n                if task[\"type\"] == TaskType.PAPER_HUNTING:\n                    result = await self._execute_paper_hunting(task)\n                elif task[\"type\"] == TaskType.PAPER_ANALYSIS:\n                    result = await self._execute_paper_analysis(task)\n                elif task[\"type\"] == TaskType.WRITING_ASSISTANCE:\n                    result = await self._execute_writing_assistance(task)\n                elif task[\"type\"] == TaskType.CITATION_VALIDATION:\n                    result = await self._execute_citation_validation(task)\n                elif task[\"type\"] == TaskType.FULL_WORKFLOW:\n                    result = await self._execute_full_workflow(task)\n                else:\n                    raise AgentException(f\"不支持的任务类型: {task['type']}\")\n                \n                task[\"status\"] = TaskStatus.COMPLETED\n                task[\"completed_at\"] = datetime.now()\n                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                ","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Apricity-InnocoreAI/agents/controller.py#L112-L148","documentation":"Dispatch guard in ControllerAgent.execute_task: task['type'] is compared against five TaskType members (PAPER_HUNTING, PAPER_ANALYSIS, WRITING_ASSISTANCE, CITATION_VALIDATION, FULL_WORKFLOW); any other value raises. Because tasks are dicts built by submit_task from TaskType(task_type), the usual cause is a raw string stored instead of the enum, since TaskType.PAPER_HUNTING != 'paper_hunting' in equality.","triggerScenarios":"submit_task called with the enum's string value while the dict stores it unconverted (or JSON round-trip converts enum to string), so the later == comparisons all fail; or a genuinely new TaskType member added to the enum without a dispatch branch; or client sends 'paper-hunting' with a hyphen.","commonSituations":"Serializing tasks through JSON (queue persistence, API echo) turning TaskType into 'TaskType.PAPER_HUNTING' or 'paper_hunting'; adding FULL_WORKFLOW-style new types in one place only; mixing str and Enum comparisons after a Python version migration.","solutions":["Normalize on read: task['type'] = TaskType(task['type']) after any deserialization, since TaskType('paper_hunting') succeeds for str-values enums.","Use dict-based dispatch keyed by TaskType so enum + handler are registered together, making missing branches loud at startup.","Accept the string form in comparisons by comparing task['type'].value if tasks may carry raw strings.","Grep for new TaskType members and confirm each has an _execute_* branch or mapping entry."],"exampleFix":"# before\nif task[\"type\"] == TaskType.PAPER_HUNTING: ...\nelse:\n    raise AgentException(f\"不支持的任务类型: {task['type']}\")\n\n# after — mapping dispatch, immune to enum/str drift\nself._executors = {\n    TaskType.PAPER_HUNTING: self._execute_paper_hunting,\n    TaskType.PAPER_ANALYSIS: self._execute_paper_analysis,\n    TaskType.WRITING_ASSISTANCE: self._execute_writing_assistance,\n    TaskType.CITATION_VALIDATION: self._execute_citation_validation,\n    TaskType.FULL_WORKFLOW: self._execute_full_workflow,\n}\nexecutor = self._executors.get(TaskType(task[\"type\"]))  # accepts str values too\nif executor is None:\n    raise AgentException(f\"不支持的任务类型: {task['type']}\")\nresult = await executor(task)","handlingStrategy":"validation","validationCode":"# Normalize the type through the enum before submission/execution\ntry:\n    normalized = TaskType(task[\"type\"])\nexcept ValueError:\n    raise ValueError(\n        f\"unsupported task type {task['type']!r}; \"\n        f\"valid: {[t.value for t in TaskType]}\"\n    )","typeGuard":"def is_supported_task_type(v) -> bool:\n    try:\n        TaskType(v)\n        return True\n    except (ValueError, TypeError):\n        return False","tryCatchPattern":"try:\n    await controller.execute_task(task_id)\nexcept AgentException as e:\n    if \"不支持的任务类型\" in str(e):\n        log.error(\"enum/str drift for task type %r — normalize before submit\", task[\"type\"])\n    raise","preventionTips":["Always convert to the enum (TaskType(value)) right after any JSON deserialization.","Use a dict-based dispatch table so a new enum member without a handler fails at startup, not at runtime.","Add a serialization round-trip test: submit -> dump/load -> execute."],"tags":["python","orchestration","enum","dispatch","serialization"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}