{"record":{"id":"25cb2f2a989a2d6e","repo":"HKUDS/Vibe-Trading","slug":"session-session-id-not-found","errorCode":null,"errorMessage":"Session {session_id} not found","messagePattern":"Session (.+?) not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"agent/src/api/sessions_routes.py","lineNumber":358,"sourceCode":"        h = _sys.modules.get(\"api_server\") or _sys.modules.get(\"agent.api_server\")\n        return h._get_session_service()\n\n    def _host_validate_path_param(value: str, kind: str) -> None:\n        h = _sys.modules.get(\"api_server\") or _sys.modules.get(\"agent.api_server\")\n        return h._validate_path_param(value, kind)\n\n    def _host_shell_tools_enabled_for_request(request: Request) -> bool:\n        h = _sys.modules.get(\"api_server\") or _sys.modules.get(\"agent.api_server\")\n        return h._shell_tools_enabled_for_request(request)\n\n    def _get_existing_session_or_404(session_id: str):\n        \"\"\"Return (service, session) or raise 404.\"\"\"\n        svc = _host_get_session_service()\n        if not svc:\n            raise HTTPException(status_code=501, detail=\"Session runtime not enabled\")\n        session = svc.get_session(session_id)\n        if not session:\n            raise HTTPException(status_code=404, detail=f\"Session {session_id} not found\")\n        return svc, session\n\n    # -----------------------------------------------------------------------\n    # Session CRUD routes\n    # -----------------------------------------------------------------------\n\n    @app.post(\"/sessions\", response_model=SessionResponse, status_code=status.HTTP_201_CREATED)\n    async def create_session(\n        request: CreateSessionRequest,\n        principal=Depends(require_auth),\n    ):\n        \"\"\"Create a chat session.\n\n        The authenticated principal is recorded as the session owner. Under the\n        shared-key and loopback auth modes that principal is not attributable to\n        a named human -- it carries ``attributable=False`` and must not be read\n        as an identity. Recording it anyway is still worth doing: it captures\n        HOW the session was authorised, which is the part that becomes an","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/api/sessions_routes.py#L340-L376","documentation":"After the session service is located, _get_existing_session_or_404 calls svc.get_session(session_id); a None result (unknown, deleted, or expired/persisted-out session id) becomes 404 with the offending id in the detail. Path params are also validated upstream, so this specifically means 'well-formed but nonexistent'.","triggerScenarios":"Calling create_session_goal, get_session_goal, update_session_goal, add_session_goal_evidence, or update_session_goal_status with a session_id that no session store contains — deleted session, wrong id, or one from another server instance.","commonSituations":"Client holds a stale session id after the store was reset/restarted without persistence; copy-paste typo in the id; pointing a client at a different environment (dev id used against prod); session TTL cleanup removed it.","solutions":["List sessions (GET /sessions) to confirm the id still exists and matches","Re-create the session (POST /sessions) and retry the goal operation with the new id","If sessions should survive restarts, enable session persistence in the service configuration","Verify the client targets the correct environment/host"],"exampleFix":"# before\ngoal = api.create_session_goal(session_id=\"sess-old\", ...)  # 404\n\n# after\nsessions = api.list_sessions()\nsid = next(s for s in sessions if s.title == \"research\") .session_id\ngoal = api.create_session_goal(session_id=sid, ...)","handlingStrategy":"validation","validationCode":"def session_exists(client, sid: str) -> bool:\n    return any(s[\"session_id\"] == sid for s in client.get(\"/sessions\", params={\"limit\": 200}).json())","typeGuard":"import re\nSESSION_ID_RE = re.compile(r\"^[A-Za-z0-9_-]+$\")\ndef is_valid_session_id(sid: str) -> bool:\n    return bool(sid) and SESSION_ID_RE.match(sid) is not None","tryCatchPattern":"try:\n    return api.get_session_goal(sid)\nexcept NotFoundError as e:\n    if \"Session\" in str(e):\n        sid = recreate_session(api)  # or surface 'session expired' to the user\n        return api.get_session_goal(sid)\n    raise","preventionTips":["Check ids against GET /sessions after server restarts","Persist or re-create sessions deterministically in long-running clients","Namespace session ids per environment to avoid cross-env mixups"],"tags":["sessions","http-404","not-found","goals"],"backgroundTag":"resource-not-found","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}