{"record":{"id":"be9441930b250d3d","repo":"thedotmack/claude-mem","slug":"failed-to-fetch-sdk-sessions-sessionsresponse-s","errorCode":null,"errorMessage":"Failed to fetch SDK sessions: ${sessionsResponse.status} ${sessionsResponse.statusText} ${body}","messagePattern":"Failed to fetch SDK sessions: (.+?) (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/export-memories.ts","lineNumber":99,"sourceCode":"    if (o.memory_session_id) memorySessionIds.add(o.memory_session_id);\n  });\n  summaries.forEach((s) => {\n    if (s.memory_session_id) memorySessionIds.add(s.memory_session_id);\n  });\n\n  console.log('📡 Fetching SDK sessions metadata...');\n  let sessions: SdkSessionRecord[] = [];\n  if (memorySessionIds.size > 0) {\n    const sessionsResponse = await fetchWithTimeout(`${baseUrl}/api/sdk-sessions/batch`, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json' },\n      body: JSON.stringify({ memorySessionIds: Array.from(memorySessionIds) })\n    });\n    if (sessionsResponse.ok) {\n      sessions = await sessionsResponse.json();\n    } else {\n      const body = await sessionsResponse.text();\n      throw new Error(`Failed to fetch SDK sessions: ${sessionsResponse.status} ${sessionsResponse.statusText} ${body}`.trim());\n    }\n  }\n  console.log(`✅ Found ${sessions.length} SDK sessions`);\n\n  const exportData: ExportData = {\n    exportedAt: new Date().toISOString(),\n    exportedAtEpoch: Date.now(),\n    query,\n    project,\n    totalObservations: observations.length,\n    totalSessions: sessions.length,\n    totalSummaries: summaries.length,\n    totalPrompts: prompts.length,\n    observations,\n    sessions,\n    summaries,\n    prompts\n  };","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/scripts/export-memories.ts#L81-L117","documentation":"Thrown when the POST to /api/sdk-sessions/batch returns non-2xx while enriching the export with SDK session metadata. The branch runs only when at least one memory_session_id was collected; on failure it reads the response body and includes it in the message for diagnosis. This is the second network hop in exportMemories, after the search succeeded.","triggerScenarios":"The batch endpoint returns 404 (route missing in this worker version), 400 (malformed memorySessionIds payload — e.g. an empty array slipped through, or a size limit exceeded), or 500 (DB error joining sdk_sessions). A proxy body-size limit returning 413 is also possible given the payload can be large.","commonSituations":"Exporting a dataset with many distinct memory_session_ids that exceeds a request body cap. Worker version skew where /api/sdk-sessions/batch was added later than the search route. A DB schema where sdk_sessions is empty or the join path errors.","solutions":["Read the included response body in the error message — it usually states the precise backend reason.","Confirm the worker version exposes /api/sdk-sessions/batch (upgrade if not).","If the payload is too large, narrow the export query/project to reduce the number of distinct session ids.","Check worker logs for the matching 5xx and the underlying DB error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (memorySessionIds.size === 0) { /* skip the batch call entirely */ }","typeGuard":null,"tryCatchPattern":"try {\n  const r = await fetchWithTimeout(`${baseUrl}/api/sdk-sessions/batch`, {...});\n  if (!r.ok) throw new Error(`sdk-sessions ${r.status} ${await r.text()}`);\n} catch (e) {\n  // degrade gracefully: write the export without SDK session metadata\n}","preventionTips":["Treat SDK session metadata as enrichment: export should still succeed if this endpoint fails, by degrading gracefully.","Cap the batch payload size or chunk memorySessionIds to avoid 413/timeout.","Version-pin the worker so /api/sdk-sessions/batch is guaranteed present."],"tags":["network","http","api","worker","export"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}