{"record":{"id":"43fb3d8c56ff929d","repo":"datawhalechina/hello-agents","slug":"filename","errorCode":null,"errorMessage":"记忆文件 {filename} 不存在","messagePattern":"记忆文件 (.+?) 不存在","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"info","filePath":"Co-creation-projects/tino-chen-HelloClaw/src/api/memory.py","lineNumber":246,"sourceCode":"        status=\"ok\",\n        deleted=deleted,\n        message=f\"已清理 {len(deleted)} 个过期记忆文件\"\n    )\n\n\n# ==================== 动态路由（必须放在最后）====================\n\n\n@router.get(\"/{filename}\")\nasync def get_memory(filename: str, ws: WorkspaceManager = Depends(get_workspace)):\n    \"\"\"获取指定日期的记忆内容\"\"\"\n    if not filename.endswith('.md'):\n        filename += '.md'\n\n    filepath = os.path.join(ws.memory_path, filename)\n\n    if not os.path.exists(filepath):\n        raise HTTPException(status_code=404, detail=f\"记忆文件 {filename} 不存在\")\n\n    with open(filepath, 'r', encoding='utf-8') as f:\n        content = f.read()\n\n    return {\n        \"filename\": filename,\n        \"date\": filename.replace('.md', ''),\n        \"content\": content\n    }\n","sourceCodeStart":228,"sourceCodeEnd":256,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/tino-chen-HelloClaw/src/api/memory.py#L228-L256","documentation":"Raised by GET /api/memory/{filename} when no file exists at os.path.join(ws.memory_path, filename). The route auto-appends '.md' if missing, so requesting '2024-01-01' and '2024-01-01.md' are equivalent. It is a plain 404 for any memory file that has not been written yet (daily memory is created on demand).","triggerScenarios":"GET /api/memory/2025-08-14 before any memory was captured that day; typo in the date ('2025-8-14' zero-padding mismatch); GET /api/memory/capture or /api/memory/stats accidentally matching this dynamic route because it is registered last but the path fits; workspace memory_path pointing at a fresh directory.","commonSituations":"Frontend loading 'today' on first visit before the agent has written anything; date formatting differences between client locale and the YYYY-MM-DD filenames the writer uses; querying a summary/index filename that lives in a different directory.","solutions":["List existing files first (directory listing or an index endpoint) and only fetch names present","Format dates as zero-padded YYYY-MM-DD to match how the writer names files","Treat 404 as 'empty day' in the UI rather than an error","Verify ws.memory_path resolves to the workspace you expect (WORKSPACE_PATH)"],"exampleFix":"// before\nconst res = await fetch(`/api/memory/${today}`); if (!res.ok) throw new Error(res.statusText);\n// after\nconst res = await fetch(`/api/memory/${today}`);\nif (res.status === 404) return {content: ''}; // no memory yet today\n","handlingStrategy":"fallback","validationCode":"const wanted = `${yyyy}-${String(mm).padStart(2,'0')}-${String(dd).padStart(2,'0')}.md`;\n// only request after confirming the file exists via a listing endpoint","typeGuard":null,"tryCatchPattern":"const res = await fetch(`/api/memory/${date}`);\nif (res.status === 404) return { filename: `${date}.md`, content: '' };","preventionTips":["Zero-pad dates to YYYY-MM-DD","Treat 404 as an empty day, not an error state","Remember this route matches ANY /api/memory/{x} path, so typo'd sub-paths land here"],"tags":["fastapi","memory","http-404","dynamic-route"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}