{"record":{"id":"1bdbac6f8bea424e","repo":"datawhalechina/hello-agents","slug":"session-not-found","errorCode":null,"errorMessage":"Session not found","messagePattern":"Session not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"info","filePath":"Co-creation-projects/tino-chen-HelloClaw/src/api/session.py","lineNumber":205,"sourceCode":"async def get_session(session_id: str):\n    \"\"\"获取会话详情\n\n    返回会话的基本信息\n    \"\"\"\n    agent = get_agent()\n    if not agent:\n        raise HTTPException(status_code=500, detail=\"Agent not initialized\")\n\n    sessions = agent.list_sessions()\n    for s in sessions:\n        if s[\"id\"] == session_id:\n            return SessionInfo(\n                id=s[\"id\"],\n                created_at=s[\"created_at\"],\n                updated_at=s[\"updated_at\"]\n            )\n\n    raise HTTPException(status_code=404, detail=\"Session not found\")\n\n\n@router.get(\"/{session_id}/history\", response_model=SessionHistoryResponse)\nasync def get_session_history(session_id: str):\n    \"\"\"获取会话历史消息\n\n    返回会话的所有聊天记录，按照 OpenAI 标准格式\n    \"\"\"\n    agent = get_agent()\n    if not agent:\n        raise HTTPException(status_code=500, detail=\"Agent not initialized\")\n\n    raw_messages = agent.get_session_history(session_id)\n    if raw_messages is None:\n        raw_messages = []\n\n    # 转换为 OpenAI 标准格式\n    chat_messages: List[ChatMessage] = []","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/tino-chen-HelloClaw/src/api/session.py#L187-L223","documentation":"Raised by GET /api/session/{session_id} when the agent is alive but list_sessions() contains no session with the matching id. It is a straightforward lookup miss: sessions live under the workspace, so an id valid in another workspace will not resolve here. HTTP 404.","triggerScenarios":"GET /api/session/<id> with a stale id from a previous workspace or after a reset; mistyped or truncated uuid; id from a different server instance; sessions directory cleared on disk while the client held an old id.","commonSituations":"Frontend persists session ids in localStorage and replays them after the workspace was reset (POST /config/reset with reset_sessions); pointing the client at a fresh environment (dev vs prod) that never saw the session.","solutions":["GET /api/session (list) and use an id that is actually returned","Drop the persisted id on 404 and create a new session","Confirm WORKSPACE_PATH points at the workspace where the session was created"],"exampleFix":"// before\nconst s = await api.getSession(savedId);\n// after\nlet s;\ntry { s = await api.getSession(savedId); }\ncatch (e) { if (e.status === 404) { savedId = await api.createSession(); s = await api.getSession(savedId); } else throw e; }","handlingStrategy":"fallback","validationCode":"const sessions = await listSessions();\nconst exists = sessions.some(s => s.id === wantedId);\nif (!exists) wantedId = await createSession();","typeGuard":null,"tryCatchPattern":"try { return await getSession(id); }\ncatch (e) { if (e.status === 404) return null; throw e; }","preventionTips":["Validate persisted ids against the session list after any reset/restart","Clear cached session ids when WORKSPACE_PATH changes"],"tags":["fastapi","session","http-404"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}