{"record":{"id":"3a1fcb8c7522efc7","repo":"datawhalechina/hello-agents","slug":"session-not-found-3a1fcb","errorCode":null,"errorMessage":"Session not found","messagePattern":"Session not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"Co-creation-projects/xujikai-SentenceExpandAgent/backend/src/routers/expand.py","lineNumber":72,"sourceCode":"\n@router.post(\"/session/submit\", response_model=AgentResponse)\nasync def submit_sentence(request: SubmitRequest) -> AgentResponse:\n    \"\"\"\n    提交用户扩写句子，返回点评和下一阶段提问（手动模式）\n    \n    Args:\n        request: 提交请求，包含会话 ID 和用户句子\n        \n    Returns:\n        AgentResponse: 智能体响应\n    \"\"\"\n    # 获取会话存储\n    session_store = get_session_store()\n    \n    # 获取会话\n    session = session_store.get_session(request.session_id)\n    if not session:\n        raise HTTPException(status_code=404, detail=\"Session not found\")\n    \n    # 获取 Orchestrator\n    orchestrator = get_orchestrator()\n    \n    # 处理用户输入\n    response = orchestrator.process_user_input(\n        session_state=session,\n        user_sentence=request.user_sentence\n    )\n    \n    # 更新会话\n    session_store.update_session(session)\n    \n    return response\n\n\n@router.get(\"/session/{session_id}/auto\")\nasync def auto_mode_stream(session_id: str) -> StreamingResponse:","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/xujikai-SentenceExpandAgent/backend/src/routers/expand.py#L54-L90","documentation":"Raised by POST /expand (submit) in SentenceExpandAgent when session_store.get_session(request.session_id) returns nothing — the id was never created, expired from the in-memory/typed store, or belongs to a different process. HTTP 404 before any orchestrator work happens.","triggerScenarios":"POST /expand with a session_id never returned by the create-session endpoint; server restarted so the in-memory session store lost all sessions (TTL expiry); session_id from a different backend instance behind a load balancer without sticky sessions.","commonSituations":"Client keeps a session id longer than the store TTL; backend redeploy mid-conversation; multiple uvicorn workers each with their own get_session_store() global so the create and submit land on different workers.","solutions":["On 404, create a fresh session and resubmit the sentence","Align the store TTL with realistic conversation length or persist sessions (Redis/DB) if restarts are expected","Run a single worker or share the session store across workers so create/submit hit the same state"],"exampleFix":"# before\nresp = client.post('/expand', json={'session_id': sid, 'user_sentence': s})\n# after\nresp = client.post('/expand', json={'session_id': sid, 'user_sentence': s})\nif resp.status_code == 404:\n    sid = client.post('/expand/session').json()['session_id']\n    resp = client.post('/expand', json={'session_id': sid, 'user_sentence': s})","handlingStrategy":"fallback","validationCode":"resp = await fetch(`/expand/session/${sid}`, {method: 'HEAD'});\nif (resp.status === 404) sid = await createSession(); // recreate before submit","typeGuard":null,"tryCatchPattern":"let resp = await submit(sid, sentence);\nif (resp.status === 404) {\n  sid = await createSession();\n  resp = await submit(sid, sentence);\n}","preventionTips":["Set session TTL above expected conversation length","Persist or share the session store if the backend restarts or runs multiple workers","Recreate-and-retry on 404 as standard client behavior"],"tags":["fastapi","session","http-404","state-management"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}