HKUDS/Vibe-Trading · error · ValueError

Session {session_id} not found

Error message

Session {session_id} not found

What it means

send_message raises ValueError when store.get_session returns nothing for the given session_id — the session was never created or has been deleted/expired from the session store.

Source

Thrown at agent/src/session/service.py:271

        Args:
            session_id: Session ID.
            content: Message content.
            role: Message role.
            include_shell_tools: Whether this attempt may use shell tools.

        Returns:
            Dictionary containing message_id and attempt_id.

        Raises:
            ValueError: If the session does not exist.
            SessionBusyError: If the session already has a run in progress.
                Callers surface this as HTTP 409; the user can wait for the
                running attempt or cancel it first.
        """
        session = self.store.get_session(session_id)
        if not session:
            raise ValueError(f"Session {session_id} not found")

        # Claim the session before persisting anything. Reserving after the
        # user message is appended (or relying on _active_loops, which is only
        # populated once the registry is built) lets two concurrent sends both
        # store a message and create an attempt.
        if role == "user":
            self._reserve_session(session_id)
        handed_off = False

        try:
            message = Message(session_id=session_id, role=role, content=content)
            self.store.append_message(message)
            self._search_index.index_message(session_id, role, content)
            self.event_bus.emit(session_id, "message.received", {"message_id": message.message_id, "role": role, "content": content})

            if role != "user":
                return {"message_id": message.message_id}

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Create the session first and use the returned id for subsequent messages
  2. Refresh/re-create the session if it was deleted or the store was reset
  3. For durable deployments, configure a persistent session store so ids survive restarts

Example fix

# before
svc.send_message("sess-does-not-exist", "hello")
# after
session = svc.create_session(...)
svc.send_message(session.id, "hello")
Defensive patterns

Strategy: validation

Validate before calling

if not session_service.store.get_session(session_id):
    session = session_service.create_session(...)  # then use session.id
assert session_service.store.get_session(session_id), "session missing"

Type guard

def session_exists(svc, sid: str) -> bool:
    return svc.store.get_session(sid) is not None

Try / catch

try:
    service.send_message(session_id, text)
except ValueError as e:
    if "not found" in str(e):
        session = service.create_session(...)
        service.send_message(session.id, text)

Prevention

When it happens

Trigger: POSTing a message to a session id that doesn't exist; using an id from a deleted session; persistence reset (store wiped/restarted with in-memory backend) while clients held old ids; typos/truncation in the id.

Common situations: Dev restarts with ephemeral session storage invalidating client-held ids; expired TTL cleanup; frontend caching stale session ids; load balancer hitting a node with a different store.

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


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/1776f155cc77d7e6. Report an issue: GitHub.