thedotmack/claude-mem · info
Skipping resume for INIT prompt despite existing…
Error message
Skipping resume for INIT prompt despite existing memorySessionId=${session.memorySessionId} - SDK context was lost (worker restart or crash recovery) What it means
startSession normally resumes an existing SDK session via memorySessionId. For the first (INIT) prompt, however, a stored memorySessionId is necessarily stale — the SDK context was lost (worker restart or crash recovery) — so the provider deliberately starts fresh and logs this warning instead of attempting a resume that would fail.
Solutions
- No action needed — starting fresh is the correct recovery; a new memorySessionId will be captured from the SDK response
- If this recurs unexpectedly, investigate why the worker restarts between prompts (crash logs)
- Clear stale session rows if old memorySessionIds accumulate and cause confusion
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Only resume when there is a real session and it is not the first prompt
const canResume = session.lastPromptNumber > 1 && !!session.memorySessionId && memorySessionIdLooksReal(session.memorySessionId);
if (!canResume) console.log('starting fresh session'); Try / catch
try {
await startSession(session, /* resume */ shouldResume);
} catch (err) {
// stale session id: restart fresh
await startSession(session, false);
} Prevention
- Treat memorySessionId from before a worker restart as stale
- Always capture the fresh memorySessionId from the first SDK response
- Log resume decisions (prompt#, hasRealMemorySessionId) for easier diagnosis
When it happens
Trigger: promptNumber === 1 (INIT), hasRealMemorySessionId is true (a memorySessionId persisted from before), shouldResume is false, so the code chooses START_FRESH and warns about the skipped resume.
Common situations: Worker restarted between the project's previous session and a new INIT prompt; crash recovery restored the session record with an old memorySessionId; database retains a session row whose SDK process no longer exists.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Anthropic API rejected request with HTTP 400: this model…
- Cannot process observations: memorySessionId not yet…
- Cannot process summary: memorySessionId not yet captured…
- Failed to capture session_id while priming corpus
- is forbidden from tool use (claude-mem hard lockdown).
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/7e5c52b136013bb7.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/worker/ClaudeProvider.ts:293
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 d8bc9755e7)