thedotmack/claude-mem · error · Error

Failed to spawn SDK subprocess for session

Error message

Failed to spawn SDK subprocess for session ${sessionDbId}

What it means

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.

Solutions

  1. Check that the SDK binary exists and is executable on PATH
  2. Inspect logs just before this error for the underlying spawn failure cause
  3. Retry the session spawn after freeing resources
  4. Verify the session's configuration/arguments passed into the spawn call

Example fix

// before
const proc = await spawnForSession(sessionDbId); // throws with no detail
// after
try {
  const proc = await spawnForSession(sessionDbId);
} catch (e) {
  logger.error('spawn failed', { sessionDbId, cause: e });
  await releaseSlot();
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

const sdkPath = resolveSdkBinary();
if (!existsSync(sdkPath)) throw new Error(`SDK binary missing at ${sdkPath}`);

Try / catch

try { const proc = await spawnSdkForSession(sessionDbId); }
catch (e) { if (e.message.includes('Failed to spawn SDK subprocess')) { await cleanupSession(sessionDbId); throw new Error(`spawn failed for ${sessionDbId}`, { cause: e }); } throw e; }

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/5114b469c909f532. Report an issue: GitHub.

Appendix: source

Thrown at src/supervisor/process-registry.ts:890

      }
    }

    let result: ReturnType<typeof spawnSdkProcess>;
    try {
      result = spawnSdkProcess(sessionDbId, {
        ...spawnOptions,
        extraArgs: [...(spawnOptions.extraArgs ?? []), ...extraArgs],
      });
    } finally {
      // The waitForSlot() reservation is consumed here: on success the
      // process is now a registry record (registered inside spawnSdkProcess)
      // and takes over the slot accounting; on failure the slot goes back to
      // the pool. Both statements above are synchronous, so no other caller
      // can observe the reservation and the record at the same time.
      slotReservation?.release();
    }
    if (!result) {
      throw new Error(`Failed to spawn SDK subprocess for session ${sessionDbId}`);
    }

    return result.process;
  };
}

View on GitHub (pinned to d8bc9755e7)