{"record":{"id":"c30598b5a23e4aff","repo":"datawhalechina/hello-agents","slug":"paper-id","errorCode":null,"errorMessage":"论文不存在: {paper_id}","messagePattern":"论文不存在: (.+?)","errorType":"exception","errorClass":"AgentException","httpStatus":500,"severity":"error","filePath":"Co-creation-projects/Apricity-InnocoreAI/agents/miner.py","lineNumber":43,"sourceCode":"        self.add_tool(\"search_memory\", self._search_memory, \"搜索记忆库\")\n        self.add_tool(\"compare_papers\", self._compare_papers, \"对比论文\")\n        self.add_tool(\"generate_report\", self._generate_report, \"生成分析报告\")\n    \n    async def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:\n        \"\"\"执行论文分析和创新点挖掘任务\"\"\"\n        await self.validate_input(input_data)\n        \n        self.set_state(\"running\")\n        \n        try:\n            paper_id = input_data[\"paper_id\"]\n            user_id = input_data.get(\"user_id\")\n            analysis_type = input_data.get(\"analysis_type\", \"full\")  # full, quick, innovation_only\n            \n            # 获取论文信息\n            paper = await db_manager.get_paper(paper_id)\n            if not paper:\n                raise AgentException(f\"论文不存在: {paper_id}\")\n            \n            self._add_to_history(f\"开始分析论文: {paper['title']}\")\n            \n            # 1. 解析PDF内容\n            parsed_content = await self._parse_paper_content(paper)\n            \n            # 2. 检索相关历史论文\n            related_papers = await self._find_related_papers(\n                paper[\"title\"], \n                paper[\"abstract\"], \n                user_id\n            )\n            \n            # 3. 进行对比分析\n            comparison_result = await self._perform_comparison_analysis(\n                parsed_content, \n                related_papers\n            )","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Apricity-InnocoreAI/agents/miner.py#L25-L61","documentation":"Guard in MinerAgent.run: after db_manager.get_paper(paper_id) returns falsy, the agent refuses to analyze. The paper must already exist in the local database — normally inserted by the Hunter stage — so this fires when analysis is requested for an ID that was never hunted/downloaded, belongs to another user, or after the DB was reset.","triggerScenarios":"Calling miner.run({'paper_id':'1234.5678'}) with an arXiv ID string when the DB stores a different key format; running FULL_WORKFLOW where hunting found zero papers and a stale ID is passed downstream; analysis request for a paper_id saved under a different user_id scope; dev DB wiped between hunt and mine steps.","commonSituations":"Frontend sending the arXiv canonical id (entry.id URL tail) while hunter stored article_number; multi-user filtering in get_paper; separate containers pointing at different database files; race where analysis is requested before hunt transaction commits.","solutions":["Confirm the ID exists: query the papers table (or GET /papers) and use the exact stored id value.","Run the hunting step first so the paper is persisted before invoking miner.","Normalize IDs at insert time (strip URL prefixes, store one canonical form) so producers and consumers agree.","If multi-user, pass the same user_id used during hunting so get_paper's scope matches.","Return the list of valid ids in the error to speed up debugging."],"exampleFix":"# before\npaper = await db_manager.get_paper(paper_id)\nif not paper:\n    raise AgentException(f\"论文不存在: {paper_id}\")\n\n# after — helpful error with lookup hints\npaper = await db_manager.get_paper(paper_id)\nif not paper:\n    count = await db_manager.count_papers()\n    raise AgentException(\n        f\"论文不存在: {paper_id} (库中共 {count} 篇; 请先运行 Hunter 抓取, 并使用其返回的 id)\"\n    )","handlingStrategy":"validation","validationCode":"# Verify the paper exists before invoking the miner\npaper = await db_manager.get_paper(paper_id)\nif paper is None:\n    available = await db_manager.list_paper_ids(limit=20)\n    raise ValueError(\n        f\"paper {paper_id!r} not found; run Hunter first. \"\n        f\"Sample ids: {available}\"\n    )","typeGuard":"async def paper_exists(paper_id: str) -> bool:\n    return (await db_manager.get_paper(paper_id)) is not None","tryCatchPattern":"try:\n    result = await miner.run({\"paper_id\": pid})\nexcept AgentException as e:\n    if \"论文不存在\" in str(e):\n        new_id = await hunt_and_store(pid)  # fetch + persist, then retry once\n        result = await miner.run({\"paper_id\": new_id})\n    else:\n        raise","preventionTips":["Always mine with the exact id returned by the hunter stage.","Normalize external ids (strip URLs, one canonical form) at insert time.","In full workflows, skip analysis when the hunt stage found zero papers."],"tags":["python","agent","database","data-integrity","validation"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}