{"record":{"id":"16a5a9f94d9b960c","repo":"microsoft/autogen","slug":"failed-to-fetch-sessions","errorCode":null,"errorMessage":"Failed to fetch sessions","messagePattern":"Failed to fetch sessions","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-studio/frontend/src/components/views/playground/api.ts","lineNumber":14,"sourceCode":"import { Session, SessionRuns } from \"../../types/datamodel\";\nimport { BaseAPI } from \"../../utils/baseapi\";\n\nexport class SessionAPI extends BaseAPI {\n  async listSessions(userId: string): Promise<Session[]> {\n    const response = await fetch(\n      `${this.getBaseUrl()}/sessions/?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 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>,","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-studio/frontend/src/components/views/playground/api.ts#L1-L32","documentation":"Thrown by SessionAPI.listSessions when GET /sessions/?user_id=... returns a body with a falsy status field. Note the check is on data.status (the application-level envelope), not response.ok — so this fires even on HTTP 200 whenever the backend marks the operation failed. It also throws on non-JSON error bodies only indirectly (json() would throw first).","triggerScenarios":"GET {base}/sessions/?user_id=X returning {status:false,...}: invalid/empty user_id, user not found in the backend DB, auth token rejected (backend answers 200/401 with status:false envelope), or backend DB unavailable.","commonSituations":"user_id not yet loaded (empty string) when the call fires on mount, user deleted/recreated while token stale, fresh database with no migrations, auth mismatch between token subject and user_id param.","solutions":["Log the full response body — data.message identifies which envelope failure it is","Ensure userId is a real non-empty value before calling (guard against undefined during initial load)","Verify the auth token matches the user_id being queried","Hit GET /sessions/?user_id=... directly with curl to see the raw envelope","If data is undefined because the body was an HTML error page, harden the json parse (see exampleFix)"],"exampleFix":"// before\nconst response = await fetch(`${this.getBaseUrl()}/sessions/?user_id=${userId}`, { headers: this.getHeaders() });\nconst data = await response.json();\nif (!data.status) throw new Error(data.message || \"Failed to fetch sessions\");\n// after\nconst response = await fetch(`${this.getBaseUrl()}/sessions/?user_id=${encodeURIComponent(userId)}`, { headers: this.getHeaders() });\nif (!response.ok) throw new Error(`Failed to fetch sessions (HTTP ${response.status})`);\nconst data = await response.json();\nif (!data.status) throw new Error(data.message || \"Failed to fetch sessions\");","handlingStrategy":"validation","validationCode":"function isValidUserId(u: string | undefined | null): u is string {\n  return typeof u === \"string\" && u.length > 0;\n}\n// gate the call\nif (!isValidUserId(userId)) throw new Error(\"userId not loaded yet\");","typeGuard":"function isSessionListEnvelope(x: unknown): x is { status: true; data: Session[] } {\n  return !!x && typeof x === \"object\" && (x as any).status === true && Array.isArray((x as any).data);\n}","tryCatchPattern":"try {\n  setSessions(await sessionAPI.listSessions(userId));\n} catch (e) {\n  setSessions([]);\n  notify(e instanceof Error ? e.message : \"Failed to fetch sessions\");\n}","preventionTips":["Never fire session calls before the user context is loaded","Check both response.ok and data.status in wrappers so 401 JSON envelopes don't masquerade as generic failures","Use encodeURIComponent on user_id query params"],"tags":["sessions","http","error-envelope","fetch","autogen-studio"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}