datawhalechina/hello-agents · info · HTTPException

记忆文件 {filename} 不存在

Error message

记忆文件 {filename} 不存在

What it means

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).

Source

Thrown at Co-creation-projects/tino-chen-HelloClaw/src/api/memory.py:246

        status="ok",
        deleted=deleted,
        message=f"已清理 {len(deleted)} 个过期记忆文件"
    )


# ==================== 动态路由(必须放在最后)====================


@router.get("/{filename}")
async def get_memory(filename: str, ws: WorkspaceManager = Depends(get_workspace)):
    """获取指定日期的记忆内容"""
    if not filename.endswith('.md'):
        filename += '.md'

    filepath = os.path.join(ws.memory_path, filename)

    if not os.path.exists(filepath):
        raise HTTPException(status_code=404, detail=f"记忆文件 {filename} 不存在")

    with open(filepath, 'r', encoding='utf-8') as f:
        content = f.read()

    return {
        "filename": filename,
        "date": filename.replace('.md', ''),
        "content": content
    }

View on GitHub (pinned to 606a07d341)

Solutions

  1. List existing files first (directory listing or an index endpoint) and only fetch names present
  2. Format dates as zero-padded YYYY-MM-DD to match how the writer names files
  3. Treat 404 as 'empty day' in the UI rather than an error
  4. Verify ws.memory_path resolves to the workspace you expect (WORKSPACE_PATH)

Example fix

// before
const res = await fetch(`/api/memory/${today}`); if (!res.ok) throw new Error(res.statusText);
// after
const res = await fetch(`/api/memory/${today}`);
if (res.status === 404) return {content: ''}; // no memory yet today
Defensive patterns

Strategy: fallback

Validate before calling

const wanted = `${yyyy}-${String(mm).padStart(2,'0')}-${String(dd).padStart(2,'0')}.md`;
// only request after confirming the file exists via a listing endpoint

Try / catch

const res = await fetch(`/api/memory/${date}`);
if (res.status === 404) return { filename: `${date}.md`, content: '' };

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/43fb3d8c56ff929d. Report an issue: GitHub.