thedotmack/claude-mem · error · Error

Failed to fetch SDK sessions: ${sessionsResponse.status} ${s

Error message

Failed to fetch SDK sessions: ${sessionsResponse.status} ${sessionsResponse.statusText} ${body}

What it means

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.

Source

Thrown at scripts/export-memories.ts:99

    if (o.memory_session_id) memorySessionIds.add(o.memory_session_id);
  });
  summaries.forEach((s) => {
    if (s.memory_session_id) memorySessionIds.add(s.memory_session_id);
  });

  console.log('📡 Fetching SDK sessions metadata...');
  let sessions: SdkSessionRecord[] = [];
  if (memorySessionIds.size > 0) {
    const sessionsResponse = await fetchWithTimeout(`${baseUrl}/api/sdk-sessions/batch`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ memorySessionIds: Array.from(memorySessionIds) })
    });
    if (sessionsResponse.ok) {
      sessions = await sessionsResponse.json();
    } else {
      const body = await sessionsResponse.text();
      throw new Error(`Failed to fetch SDK sessions: ${sessionsResponse.status} ${sessionsResponse.statusText} ${body}`.trim());
    }
  }
  console.log(`✅ Found ${sessions.length} SDK sessions`);

  const exportData: ExportData = {
    exportedAt: new Date().toISOString(),
    exportedAtEpoch: Date.now(),
    query,
    project,
    totalObservations: observations.length,
    totalSessions: sessions.length,
    totalSummaries: summaries.length,
    totalPrompts: prompts.length,
    observations,
    sessions,
    summaries,
    prompts
  };

View on GitHub (pinned to d768ba3643)

Solutions

  1. Read the included response body in the error message — it usually states the precise backend reason.
  2. Confirm the worker version exposes /api/sdk-sessions/batch (upgrade if not).
  3. If the payload is too large, narrow the export query/project to reduce the number of distinct session ids.
  4. Check worker logs for the matching 5xx and the underlying DB error.
Defensive patterns

Strategy: try-catch

Validate before calling

if (memorySessionIds.size === 0) { /* skip the batch call entirely */ }

Try / catch

try {
  const r = await fetchWithTimeout(`${baseUrl}/api/sdk-sessions/batch`, {...});
  if (!r.ok) throw new Error(`sdk-sessions ${r.status} ${await r.text()}`);
} catch (e) {
  // degrade gracefully: write the export without SDK session metadata
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12). Data as JSON: /api/errors/be9441930b250d3d. Report an issue: GitHub.