{"record":{"id":"015e445443910a93","repo":"OpenBMB/ChatDev","slug":"session-not-connected-015e44","errorCode":null,"errorMessage":"Session not connected","messagePattern":"Session not connected","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"server/state.py","lineNumber":29,"sourceCode":"def init_state() -> None:\n    \"\"\"Ensure global singletons are ready for incoming requests.\"\"\"\n\n    get_websocket_manager()\n\n\ndef get_websocket_manager() -> WebSocketManager:\n    global websocket_manager\n    if websocket_manager is None:\n        websocket_manager = WebSocketManager()\n    return websocket_manager\n\n\ndef ensure_known_session(session_id: str, *, require_connection: bool = False) -> WebSocketManager:\n    \"\"\"Return the WebSocket manager if the session is connected or known.\"\"\"\n\n    manager = get_websocket_manager()\n    if not session_id:\n        raise ValidationError(\"Session not connected\", details={\"session_id\": session_id})\n\n    if session_id in manager.active_connections:\n        return manager\n\n    if not require_connection and manager.session_store.has_session(session_id):\n        return manager\n\n    raise ValidationError(\"Session not connected\", details={\"session_id\": session_id})\n","sourceCodeStart":11,"sourceCodeEnd":38,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/server/state.py#L11-L38","documentation":"ensure_known_session raises ValidationError when session_id is empty/None before any session lookup — i.e. the caller never supplied a session identifier. Distinct from a non-empty unknown session, this is a malformed-request guard.","triggerScenarios":"Calling execute_workflow, execute_batch, upload_attachment, or list_attachments with session_id=\"\" or None (missing query/body field, unset client variable).","commonSituations":"Client connects but never stores the session id from the handshake; field name mismatch (sessionId vs session_id); default empty string in a form.","solutions":["Capture and pass the session id returned at connection/register time","Validate session_id is non-empty before calling session-scoped APIs","Check for field-name mismatches in the request payload"],"exampleFix":"# before\nresult = execute_workflow(session_id=sid, ...)  # sid may be ''\n# after\nif not sid:\n    raise ValueError(\"missing session_id; connect first\")\nresult = execute_workflow(session_id=sid, ...)","handlingStrategy":"validation","validationCode":"if not session_id:\n    raise ValueError('session_id required — connect first')","typeGuard":"def has_session_id(sid: str | None) -> bool:\n    return isinstance(sid, str) and bool(sid.strip())","tryCatchPattern":null,"preventionTips":["Store session id immediately from handshake response","Validate non-empty before every session-scoped call","Check field naming (session_id vs sessionId)"],"tags":["session","validation","websocket"],"backgroundTag":"missing-session-id","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}