{"record":{"id":"bb79e029f8e30a21","repo":"HKUDS/Vibe-Trading","slug":"session-runtime-not-enabled","errorCode":null,"errorMessage":"Session runtime not enabled","messagePattern":"Session runtime not enabled","errorType":"http","errorClass":"HTTPException","httpStatus":501,"severity":"error","filePath":"agent/src/api/sessions_routes.py","lineNumber":355,"sourceCode":"\n    # Late-access closures for shared host symbols (monkeypatch-safe)\n    def _host_get_session_service():\n        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","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/api/sessions_routes.py#L337-L373","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check how the host app registers the session service (the wiring passed to the route-registration factory) and enable/provide it","If embedding, pass the session service when mounting sessions_routes instead of leaving it None","Upgrade/align versions so the session runtime is included in your distribution","If sessions are intentionally disabled, stop calling goal endpoints and treat 501 as expected"],"exampleFix":"# before (conceptual embedding)\napp.include_router(sessions_routes.router)  # no session service -> 501 on /sessions/{id}/goal\n\n# after\nregister_session_routes(app, session_service=SessionService(...))","handlingStrategy":"try-catch","validationCode":"# cheap capability probe before using goal endpoints\nr = requests.get(f\"{BASE}/sessions\", params={\"limit\": 1})\nif r.status_code == 501:\n    raise RuntimeError(\"Session runtime not enabled on this host; goal routes unavailable\")","typeGuard":"def goal_routes_available(client) -> bool:\n    \"\"\"True when the session runtime (and thus goal routes) is enabled.\"\"\"\n    return client.get(\"/sessions\", params={\"limit\": 1}).status_code != 501","tryCatchPattern":"try:\n    return api.create_session_goal(sid, payload)\nexcept HTTPError as e:\n    if e.response.status_code == 501:\n        raise FeatureUnavailable(\"Session runtime disabled; enable it server-side\") from e\n    raise","preventionTips":["Feature-probe /sessions at client init and disable session UI accordingly","Keep host wiring consistent when embedding these routes","Version-pin server builds whose session runtime your client depends on"],"tags":["sessions","http-501","not-implemented","feature-flag","goals"],"backgroundTag":"optional-feature-not-enabled","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}