thedotmack/claude-mem · warning

Skipping resume for INIT prompt despite existing memorySessi

Error message

Skipping resume for INIT prompt despite existing memorySessionId=${session.memorySessionId} - SDK context was lost (worker restart or crash recovery)

What it means

The observer resumes SDK sessions via memorySessionId, but only when the current prompt is a continuation (lastPromptNumber > 1). On the first (INIT) prompt it always starts fresh and captures a new session id; if a stale memorySessionId already exists at prompt #1, the prior SDK context is unrecoverable (typically the worker restarted or crashed between session creation and the first prompt), so this warning records the discarded resume.

Source

Thrown at src/services/worker/ClaudeProvider.ts:269

      logger.info('SDK', 'Starting SDK query', {
        sessionDbId: session.sessionDbId,
        contentSessionId: session.contentSessionId,
        memorySessionId: session.memorySessionId ?? undefined,
        hasRealMemorySessionId,
        shouldResume,
        resume_parameter: shouldResume ? session.memorySessionId : '(none - fresh start)',
        lastPromptNumber: session.lastPromptNumber,
        authMethod
      });

      if (session.lastPromptNumber > 1) {
        logger.debug('SDK', `[ALIGNMENT] Resume Decision | contentSessionId=${session.contentSessionId} | memorySessionId=${session.memorySessionId} | prompt#=${session.lastPromptNumber} | hasRealMemorySessionId=${hasRealMemorySessionId} | shouldResume=${shouldResume} | resumeWith=${shouldResume ? session.memorySessionId : 'NONE'}`);
      } else {
        const hasStaleMemoryId = hasRealMemorySessionId;
        logger.debug('SDK', `[ALIGNMENT] First Prompt (INIT) | contentSessionId=${session.contentSessionId} | prompt#=${session.lastPromptNumber} | hasStaleMemoryId=${hasStaleMemoryId} | action=START_FRESH | Will capture new memorySessionId from SDK response`);
        if (hasStaleMemoryId) {
          logger.warn('SDK', `Skipping resume for INIT prompt despite existing memorySessionId=${session.memorySessionId} - SDK context was lost (worker restart or crash recovery)`);
        }
      }

      ensureDir(OBSERVER_SESSIONS_DIR);
      const queryResult = query({
        prompt: messageGenerator,
        options: buildHardenedSdkOptions({
          source: 'Observer',
          sessionDbId: session.sessionDbId,
          contentSessionId: session.contentSessionId,
          project: session.project,
          model: modelId,
          env: isolatedEnv,  // Use isolated credentials from ~/.claude-mem/.env, not process.env
          pathToClaudeCodeExecutable: claudePath,
          abortController: session.abortController,
          ...(shouldResume && session.memorySessionId ? { resume: session.memorySessionId } : {}),
          spawnClaudeCodeProcess: createSdkSpawnFactory(session.sessionDbId, slotReservation, observerExtraArgs),
        }),

View on GitHub (pinned to 8bc631a71a)

Solutions

  1. No data is lost from claude-mem's own DB — the observer starts a new SDK session and continues capturing
  2. To avoid it, keep the worker stable across session starts (check restart/crash logs around the timestamp)
  3. If it happens constantly, look for a crash loop in worker logs and fix the underlying startup failure
Defensive patterns

Strategy: validation

Validate before calling

function shouldResumeSdkSession(session: { lastPromptNumber: number; memorySessionId: string | null }): session is { lastPromptNumber: number; memorySessionId: string } {
  return session.lastPromptNumber > 1 && Boolean(session.memorySessionId);
}

Type guard

function isFirstPrompt(session: { lastPromptNumber: number }): boolean {
  return session.lastPromptNumber <= 1;
}

Prevention

When it happens

Trigger: Worker restart or crash after a session row was created but before its first prompt completed; a session-init hook running twice creating a reused row; database restored from a backup mid-session.

Common situations: Restarting claude-mem or the machine right after starting a coding session; worker crash loops; killing the worker between session-init and the first observation.

Related errors


AI-assisted analysis of thedotmack/claude-mem@8bc631a71a (2026-08-20). Data as JSON: /api/errors/7e5c52b136013bb7. Report an issue: GitHub.