{"record":{"id":"0595c9770f4380be","repo":"microsoft/autogen","slug":"failed-to-fetch-session","errorCode":null,"errorMessage":"Failed to fetch session","messagePattern":"Failed to fetch session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-studio/frontend/src/components/views/playground/api.ts","lineNumber":27,"sourceCode":"        headers: this.getHeaders(),\n      }\n    );\n    const data = await response.json();\n    if (!data.status)\n      throw new Error(data.message || \"Failed to fetch sessions\");\n    return data.data;\n  }\n\n  async getSession(sessionId: number, userId: string): Promise<Session> {\n    const response = await fetch(\n      `${this.getBaseUrl()}/sessions/${sessionId}?user_id=${userId}`,\n      {\n        headers: this.getHeaders(),\n      }\n    );\n    const data = await response.json();\n    if (!data.status)\n      throw new Error(data.message || \"Failed to fetch session\");\n    return data.data;\n  }\n\n  async createSession(\n    sessionData: Partial<Session>,\n    userId: string\n  ): Promise<Session> {\n    const session = {\n      ...sessionData,\n      user_id: userId, // Ensure user_id is included\n    };\n\n    const response = await fetch(`${this.getBaseUrl()}/sessions/`, {\n      method: \"POST\",\n      headers: this.getHeaders(),\n      body: JSON.stringify(session),\n    });\n    const data = await response.json();","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/playground/api.ts#L9-L45","documentation":"Thrown by SessionAPI.getSession when GET /sessions/{id}?user_id=... returns a body with falsy status. Same envelope pattern as listSessions: HTTP status is ignored; only the in-band status flag matters. Typical cause is a session id that does not exist or does not belong to the given user_id.","triggerScenarios":"GET /sessions/{sessionId}?user_id=X with a deleted/nonexistent sessionId, a sessionId belonging to another user (ownership check fails), or user_id mismatch with the authenticated token.","commonSituations":"Deep link to a session deleted from another browser tab, stale session id in component state after switching users, session rows cleared on backend restart with in-memory/refreshed DB.","solutions":["Confirm the session exists: call listSessions(userId) and check the id is present","Verify ownership — the backend rejects sessions whose user_id differs from the request's user_id","Refresh/reset the local sessionId state when the session list no longer contains it","Check data.message in DevTools for the backend's exact wording"],"exampleFix":"// before\nconst session = await sessionAPI.getSession(sessionId, userId);\n// after\nconst sessions = await sessionAPI.listSessions(userId);\nif (!sessions.some(s => s.id === sessionId)) {\n  throw new Error(`Session ${sessionId} not found for this user`);\n}\nconst session = await sessionAPI.getSession(sessionId, userId);","handlingStrategy":"try-catch","validationCode":"// confirm existence cheaply before the detail fetch\nconst sessions = await sessionAPI.listSessions(userId);\nif (!sessions.some(s => s.id === sessionId)) {\n  throw new Error(`Session ${sessionId} not found for this user`);\n}","typeGuard":"function isSessionEnvelope(x: unknown): x is { status: true; data: Session } {\n  return !!x && typeof x === \"object\" && (x as any).status === true && !!(x as any).data?.id;\n}","tryCatchPattern":"try {\n  return await sessionAPI.getSession(sessionId, userId);\n} catch (e) {\n  if (/not found|does not exist/i.test(String(e))) navigateToSessionsList();\n  throw e;\n}","preventionTips":["Treat 'session not found' as a navigation event, not an error toast","Validate deep-linked ids against the list on mount","Clear selected session state on user switch"],"tags":["sessions","http","error-envelope","autogen-studio"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}