HKUDS/Vibe-Trading · error · HTTPException
Session {session_id} not found
Error message
Session {session_id} not found What it means
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'.
Source
Thrown at agent/src/api/sessions_routes.py:358
h = _sys.modules.get("api_server") or _sys.modules.get("agent.api_server")
return h._get_session_service()
def _host_validate_path_param(value: str, kind: str) -> None:
h = _sys.modules.get("api_server") or _sys.modules.get("agent.api_server")
return h._validate_path_param(value, kind)
def _host_shell_tools_enabled_for_request(request: Request) -> bool:
h = _sys.modules.get("api_server") or _sys.modules.get("agent.api_server")
return h._shell_tools_enabled_for_request(request)
def _get_existing_session_or_404(session_id: str):
"""Return (service, session) or raise 404."""
svc = _host_get_session_service()
if not svc:
raise HTTPException(status_code=501, detail="Session runtime not enabled")
session = svc.get_session(session_id)
if not session:
raise HTTPException(status_code=404, detail=f"Session {session_id} not found")
return svc, session
# -----------------------------------------------------------------------
# Session CRUD routes
# -----------------------------------------------------------------------
@app.post("/sessions", response_model=SessionResponse, status_code=status.HTTP_201_CREATED)
async def create_session(
request: CreateSessionRequest,
principal=Depends(require_auth),
):
"""Create a chat session.
The authenticated principal is recorded as the session owner. Under the
shared-key and loopback auth modes that principal is not attributable to
a named human -- it carries ``attributable=False`` and must not be read
as an identity. Recording it anyway is still worth doing: it captures
HOW the session was authorised, which is the part that becomes anView on GitHub (pinned to 80ffdda44c)
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
Example fix
# before goal = api.create_session_goal(session_id="sess-old", ...) # 404 # after sessions = api.list_sessions() sid = next(s for s in sessions if s.title == "research") .session_id goal = api.create_session_goal(session_id=sid, ...)
Defensive patterns
Strategy: validation
Validate before calling
def session_exists(client, sid: str) -> bool:
return any(s["session_id"] == sid for s in client.get("/sessions", params={"limit": 200}).json()) Type guard
import re
SESSION_ID_RE = re.compile(r"^[A-Za-z0-9_-]+$")
def is_valid_session_id(sid: str) -> bool:
return bool(sid) and SESSION_ID_RE.match(sid) is not None Try / catch
try:
return api.get_session_goal(sid)
except NotFoundError as e:
if "Session" in str(e):
sid = recreate_session(api) # or surface 'session expired' to the user
return api.get_session_goal(sid)
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- No current goal
- Session runtime not enabled
- invalid risk_tier: {req.risk_tier}
- live trading or execution goals are not supported
- str(exc)
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/25cb2f2a989a2d6e.
Report an issue: GitHub.