{"record":{"id":"9f3678ae83255d8b","repo":"thedotmack/claude-mem","slug":"worker-spawned-but-readiness-endpoint-not-respondi","errorCode":null,"errorMessage":"Worker spawned but readiness endpoint not responding within window","messagePattern":"Worker spawned but readiness endpoint not responding within window","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/worker-spawner.ts","lineNumber":171,"sourceCode":"        return 'dead';\n      }\n    } else {\n      logger.info('SYSTEM', 'Another launcher holds the spawn lock — skipping duplicate spawn and waiting for its worker');\n    }\n\n    const ready = await waitForReadiness(port, getPlatformTimeout(HOOK_TIMEOUTS.READINESS_WAIT));\n    if (!ready) {\n      const workerStillHealthy = await waitForHealth(port, 1000);\n      const workerPidStillAlive = cleanStalePidFile() === 'alive';\n      const spawnedProcessStillAlive = spawnedPid !== undefined && spawnedPid > 0 && isPidAlive(spawnedPid);\n      if (!workerStillHealthy && !workerPidStillAlive && !spawnedProcessStillAlive) {\n        logger.error('SYSTEM', spawnLockHeld\n          ? 'Worker exited before readiness endpoint became available'\n          : 'Spawn-lock holder never produced a live worker before readiness timed out');\n        return 'dead';\n      }\n      logger.warn('SYSTEM', spawnLockHeld\n        ? 'Worker spawned but readiness endpoint not responding within window'\n        : 'Spawn-lock holder\\'s worker not ready within window');\n      return 'warming';\n    }\n    clearWorkerSpawnAttempted();\n    // touchPidFile is existsSync-guarded and merely refreshes the live worker's\n    // pid-file mtime — correct for lock losers too, since the worker IS up.\n    touchPidFile();\n    logger.info('SYSTEM', spawnLockHeld\n      ? 'Worker started successfully'\n      : 'Worker is up (started by another launcher)');\n    return 'ready';\n  } finally {\n    if (spawnLockHeld) releaseSpawnLock();\n  }\n}\n","sourceCodeStart":153,"sourceCodeEnd":187,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/worker-spawner.ts#L153-L187","documentation":"After this launcher spawned a worker, /readiness did not respond within the window (~30s platform-adjusted), but the health endpoint, PID file, or spawned process is still alive — so the worker did start, it is just not fully initialized. The spawner logs this (the spawn-lock-holder variant) and returns 'warming' instead of failing.","triggerScenarios":"Spawn succeeded but DB/search initialization exceeds READINESS_WAIT: first-run dependency setup, large migrations, or heavy load during startup.","commonSituations":"Cold starts after install or upgrade; machines with slow disks; concurrent claude-mem hooks triggering while init runs.","solutions":["Wait for readiness: poll GET /readiness or run `claude-mem status` again after a minute","Check worker logs for which init step is slow or stuck (dependency preflight warnings appear above this one)","If it happens on every start, trim the search index/backlog or extend the platform timeout"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"async function waitReadyAfterSpawn(port: number, timeoutMs = 60000): Promise<boolean> {\n  const deadline = Date.now() + timeoutMs;\n  while (Date.now() < deadline) {\n    try { if (await fetch(`http://127.0.0.1:${port}/readiness`).then(r => r.ok)) return true; } catch {}\n    await new Promise(r => setTimeout(r, 1000));\n  }\n  return false;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After spawning, wait on /readiness with your own (longer) budget instead of trusting one fixed window","Do not spawn a second worker when the first is merely warming","Warm the worker before hook-heavy sessions (start it at session begin)"],"tags":["worker","spawn","readiness","timeout"],"backgroundTag":"service-not-ready","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}