odysseus-dev/odysseus · error · HTTPException

Session not found

Error message

Session not found

What it means

POST /api/inject_context/{session_id} failed to load the session: get_session raised KeyError and the handler maps it to 404. Ownership is verified first, so a session owned by someone else also appears as not-found.

Source

Thrown at routes/chat_routes.py:2448

            if agent_runs.is_active(session_id):
                return {"status": "streaming", "detached": True}
            raise HTTPException(404, "No active stream for this session")
        return rec

    # ------------------------------------------------------------------ #
    # POST /api/inject_context
    # ------------------------------------------------------------------ #
    @router.post("/api/inject_context/{session_id}")
    async def inject_context(request: Request, session_id: str, context: str = Form(...)) -> Dict[str, str]:
        _verify_session_owner(request, session_id)
        try:
            sess = session_manager.get_session(session_id)
            msg = untrusted_context_message("injected research context", f"Research Context: {context}")
            sess.add_message(ChatMessage(msg["role"], msg["content"], metadata=msg.get("metadata")))
            session_manager.save_sessions()
            return {"status": "context_injected"}
        except KeyError:
            raise HTTPException(404, "Session not found")

    # ------------------------------------------------------------------ #
    # GET /api/search — search across chat messages
    # ------------------------------------------------------------------ #
    @router.get("/api/search")
    async def search_messages(
        request: Request,
        q: str = Query("", min_length=0),
        limit: int = Query(20, ge=1, le=100),
    ) -> List[Dict[str, Any]]:
        if not q or not q.strip():
            return []

        _user = effective_user(request)
        return [
            result.to_dict()
            for result in search_session_messages(
                q,

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Resolve a fresh, owned session ID before injecting context
  2. If the research flow spans long periods, re-verify the session exists right before injection
  3. Handle 404 by recreating or re-targeting the session instead of retrying blindly
Defensive patterns

Strategy: fallback

Validate before calling

const sessions = await fetch('/api/sessions').then(r=>r.json());
if (!sessions.some(s => s.id === sessionId)) { sessionId = await createSession(); }

Try / catch

try { await injectContext(sessionId, ctx); } catch (e) { if (e.status === 404) { sessionId = await createSession(); await injectContext(sessionId, ctx); } else throw e; }

Prevention

When it happens

Trigger: Injecting research context into a session ID that was deleted, never existed, or belongs to another user; the 'context' form field is present but the session is gone.

Common situations: Research pipeline holding a stale session ID from before deletion/restart; orchestration code injecting into a session that another process already tore down.

Related errors


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/908096b9c907f34b. Report an issue: GitHub.