datawhalechina/hello-agents · info · HTTPException

Session not found

Error message

Session not found

What it means

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.

Source

Thrown at Co-creation-projects/tino-chen-HelloClaw/src/api/session.py:205

async def get_session(session_id: str):
    """获取会话详情

    返回会话的基本信息
    """
    agent = get_agent()
    if not agent:
        raise HTTPException(status_code=500, detail="Agent not initialized")

    sessions = agent.list_sessions()
    for s in sessions:
        if s["id"] == session_id:
            return SessionInfo(
                id=s["id"],
                created_at=s["created_at"],
                updated_at=s["updated_at"]
            )

    raise HTTPException(status_code=404, detail="Session not found")


@router.get("/{session_id}/history", response_model=SessionHistoryResponse)
async def get_session_history(session_id: str):
    """获取会话历史消息

    返回会话的所有聊天记录,按照 OpenAI 标准格式
    """
    agent = get_agent()
    if not agent:
        raise HTTPException(status_code=500, detail="Agent not initialized")

    raw_messages = agent.get_session_history(session_id)
    if raw_messages is None:
        raw_messages = []

    # 转换为 OpenAI 标准格式
    chat_messages: List[ChatMessage] = []

View on GitHub (pinned to 606a07d341)

Solutions

  1. GET /api/session (list) and use an id that is actually returned
  2. Drop the persisted id on 404 and create a new session
  3. Confirm WORKSPACE_PATH points at the workspace where the session was created

Example fix

// before
const s = await api.getSession(savedId);
// after
let s;
try { s = await api.getSession(savedId); }
catch (e) { if (e.status === 404) { savedId = await api.createSession(); s = await api.getSession(savedId); } else throw e; }
Defensive patterns

Strategy: fallback

Validate before calling

const sessions = await listSessions();
const exists = sessions.some(s => s.id === wantedId);
if (!exists) wantedId = await createSession();

Try / catch

try { return await getSession(id); }
catch (e) { if (e.status === 404) return null; throw e; }

Prevention

When it happens

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

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

Related errors


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