HKUDS/Vibe-Trading · error · HTTPException

Session runtime not enabled

Error message

Session runtime not enabled

What it means

Goal-related session routes resolve the session service via _host_get_session_service(); when the host application did not wire a session service into the API, that lookup returns None and the route responds 501 Not Implemented instead of pretending to work. This is a feature-availability signal, not a client error.

Source

Thrown at agent/src/api/sessions_routes.py:355

    # Late-access closures for shared host symbols (monkeypatch-safe)
    def _host_get_session_service():
        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

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Check how the host app registers the session service (the wiring passed to the route-registration factory) and enable/provide it
  2. If embedding, pass the session service when mounting sessions_routes instead of leaving it None
  3. Upgrade/align versions so the session runtime is included in your distribution
  4. If sessions are intentionally disabled, stop calling goal endpoints and treat 501 as expected

Example fix

# before (conceptual embedding)
app.include_router(sessions_routes.router)  # no session service -> 501 on /sessions/{id}/goal

# after
register_session_routes(app, session_service=SessionService(...))
Defensive patterns

Strategy: try-catch

Validate before calling

# cheap capability probe before using goal endpoints
r = requests.get(f"{BASE}/sessions", params={"limit": 1})
if r.status_code == 501:
    raise RuntimeError("Session runtime not enabled on this host; goal routes unavailable")

Type guard

def goal_routes_available(client) -> bool:
    """True when the session runtime (and thus goal routes) is enabled."""
    return client.get("/sessions", params={"limit": 1}).status_code != 501

Try / catch

try:
    return api.create_session_goal(sid, payload)
except HTTPError as e:
    if e.response.status_code == 501:
        raise FeatureUnavailable("Session runtime disabled; enable it server-side") from e
    raise

Prevention

When it happens

Trigger: Calling POST/GET/PATCH /sessions/{id}/goal (create/get/update goal, evidence, status) on a build where the session runtime is disabled or the host (e.g. a lightweight embedding) registered no session service.

Common situations: Embedding the API routes into a custom FastAPI app without passing the session service; a feature-flagged build that compiles out the session runtime; running the API standalone for health/metadata endpoints only; version change where session support became opt-in.

Related errors


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