{"record":{"id":"5114b469c909f532","repo":"thedotmack/claude-mem","slug":"failed-to-spawn-sdk-subprocess-for-session-sessi","errorCode":null,"errorMessage":"Failed to spawn SDK subprocess for session ${sessionDbId}","messagePattern":"Failed to spawn SDK subprocess for session (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/supervisor/process-registry.ts","lineNumber":890,"sourceCode":"      }\n    }\n\n    let result: ReturnType<typeof spawnSdkProcess>;\n    try {\n      result = spawnSdkProcess(sessionDbId, {\n        ...spawnOptions,\n        extraArgs: [...(spawnOptions.extraArgs ?? []), ...extraArgs],\n      });\n    } finally {\n      // The waitForSlot() reservation is consumed here: on success the\n      // process is now a registry record (registered inside spawnSdkProcess)\n      // and takes over the slot accounting; on failure the slot goes back to\n      // the pool. Both statements above are synchronous, so no other caller\n      // can observe the reservation and the record at the same time.\n      slotReservation?.release();\n    }\n    if (!result) {\n      throw new Error(`Failed to spawn SDK subprocess for session ${sessionDbId}`);\n    }\n\n    return result.process;\n  };\n}\n","sourceCodeStart":872,"sourceCodeEnd":896,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/supervisor/process-registry.ts#L872-L896","documentation":"After a slot reservation is acquired, the factory attempts to spawn the SDK subprocess for the session; if the spawn returns no result (null/undefined), the slot is released back to the pool and this error is thrown. It wraps the failure of the underlying SDK process launch for a specific session database ID.","triggerScenarios":"The internal spawn routine for the session's SDK subprocess fails and returns a falsy result — e.g. binary missing, immediate process exit, or spawn API returning no process.","commonSituations":"SDK executable not installed or not on PATH; invalid SDK configuration for the session; resource exhaustion (ulimit, memory) killing the child at birth; corrupted session state causing bad spawn arguments.","solutions":["Check that the SDK binary exists and is executable on PATH","Inspect logs just before this error for the underlying spawn failure cause","Retry the session spawn after freeing resources","Verify the session's configuration/arguments passed into the spawn call"],"exampleFix":"// before\nconst proc = await spawnForSession(sessionDbId); // throws with no detail\n// after\ntry {\n  const proc = await spawnForSession(sessionDbId);\n} catch (e) {\n  logger.error('spawn failed', { sessionDbId, cause: e });\n  await releaseSlot();\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const sdkPath = resolveSdkBinary();\nif (!existsSync(sdkPath)) throw new Error(`SDK binary missing at ${sdkPath}`);","typeGuard":null,"tryCatchPattern":"try { const proc = await spawnSdkForSession(sessionDbId); }\ncatch (e) { if (e.message.includes('Failed to spawn SDK subprocess')) { await cleanupSession(sessionDbId); throw new Error(`spawn failed for ${sessionDbId}`, { cause: e }); } throw e; }","preventionTips":["Pre-flight check the SDK binary and its version at startup","Log the underlying spawn error cause before wrapping","Monitor resource limits (ulimit, memory) on hosts running many sessions"],"tags":["process","spawn","subprocess"],"backgroundTag":"command-not-found","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}