{"record":{"id":"19d64997be2cc39d","repo":"microsoft/autogen","slug":"invalid-session-configuration","errorCode":null,"errorMessage":"Invalid session configuration","messagePattern":"Invalid session configuration","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx","lineNumber":467,"sourceCode":"\n      // Setup WebSocket with files\n      const socket = setupWebSocket(runId, query, processedFiles);\n      setActiveSocket(socket);\n      activeSocketRef.current = socket;\n    } catch (error) {\n      handleError(error);\n    } finally {\n      setLoading(false);\n    }\n  };\n\n  const setupWebSocket = (\n    runId: number,\n    query: string,\n    files: { name: string; type: string; content: string }[]\n  ): WebSocket => {\n    if (!session || !session.id) {\n      throw new Error(\"Invalid session configuration\");\n    }\n    // Close existing socket if any\n    if (activeSocket?.readyState === WebSocket.OPEN) {\n      activeSocket.close();\n    }\n\n    const baseUrl = getBaseUrl(serverUrl);\n    const wsProtocol = window.location.protocol === \"https:\" ? \"wss:\" : \"ws:\";\n    const auth_token = localStorage.getItem(\"auth_token\");\n    const wsUrl = `${wsProtocol}//${baseUrl}/api/ws/runs/${runId}?token=${auth_token}`;\n\n    const socket = new WebSocket(wsUrl);\n\n    // Initialize current run\n    setCurrentRun({\n      id: runId,\n      created_at: new Date().toISOString(),\n      status: \"active\",","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx#L449-L485","documentation":"Error thrown by setupWebSocket in autogen-studio's playground chat when the component tries to open the run WebSocket but the current session object is null or has no id. The WebSocket URL is built from /api/ws/runs/{runId} plus session-derived state, so without a session id the run cannot be tied to a conversation.","triggerScenarios":"Calling sendMessage/run before a session was created or selected (session is null on first mount); session.id is undefined because the session came from a draft/unsaved builder entity; the session was deleted while the view was open.","commonSituations":"Users typing a message before the session has been persisted; deep-linking into the playground with an invalid session id so the fetch returned no session; race between session creation and the user hitting send; compare-mode with one panel lacking a session.","solutions":["Disable the send button / run action until session && session.id is truthy (e.g. conditionally render or early-return in the send handler).","Ensure a default session is created and awaited before the chat view becomes interactive.","If the session may have been deleted, re-fetch or re-create it before starting a run."],"exampleFix":"// before\nconst socket = setupWebSocket(runId, query, files); // session may be null\n\n// after\nif (!session?.id) {\n  messageApi.error(\"Please select or create a session first.\");\n  return;\n}\nconst socket = setupWebSocket(runId, query, files);","handlingStrategy":"validation","validationCode":"const canSend = Boolean(session?.id);\nif (!canSend) {\n  messageApi.warning(\"Create or select a session before sending.\");\n  return;\n}\nconst socket = setupWebSocket(runId, query, files);","typeGuard":"const hasSession = (s: Session | null | undefined): s is Session =>\n  Boolean(s && typeof s.id === \"number\" && s.id > 0);","tryCatchPattern":"try { const socket = setupWebSocket(runId, query, files); }\ncatch (e) {\n  if (e instanceof Error && e.message === \"Invalid session configuration\") {\n    handleError(new Error(\"Session not ready; please select a session.\"));\n    return;\n  }\n  throw e;\n}","preventionTips":["Disable the send button until session.id is set.","Create/default-select a session before rendering the interactive chat.","Re-validate the session exists (fetch) when deep-linking with a session id."],"tags":["react","typescript","websocket","frontend","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}