{"record":{"id":"7228998580479f27","repo":"thedotmack/claude-mem","slug":"worker-port-did-not-open-after-lazy-spawn-within-t","errorCode":null,"errorMessage":"Worker port did not open after lazy-spawn within the cold-boot wait (~15s)","messagePattern":"Worker port did not open after lazy-spawn within the cold-boot wait \\(~15s\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/shared/worker-utils.ts","lineNumber":595,"sourceCode":"          });\n        }\n        return false;\n      }\n    } else {\n      logger.info('SYSTEM', 'Another launcher holds the spawn lock — skipping lazy-spawn and waiting for its worker');\n    }\n\n    // Cold boot (#2795): on the first session after a reboot the SessionStart\n    // `start` hook is booting the daemon in parallel, and a cold macOS+Chroma\n    // worker needs ~7s to bind. The old 3-attempt/250ms budget (~0.75s) expired\n    // long before that, so the context (and session-init) hooks raced boot and\n    // soft-failed to empty — dropping memory injection and the user_prompts row\n    // (the upstream trigger for #2794). Wait up to ~15.5s (≈ POST_SPAWN_WAIT) so\n    // whichever worker wins the port is seen before we give up.\n    const alive = await waitForWorkerPort({ attempts: 6, backoffMs: 500 });\n    if (!alive) {\n      logger.warn('SYSTEM', spawnLockHeld\n        ? 'Worker port did not open after lazy-spawn within the cold-boot wait (~15s)'\n        : 'Spawn-lock holder\\'s worker port did not open within the cold-boot wait (~15s)');\n      return false;\n    }\n  } finally {\n    if (spawnLockHeld) releaseSpawnLock();\n  }\n  const ready = await waitForWorkerReadiness();\n  if (!ready) {\n    logger.warn('SYSTEM', 'Worker lazy-spawned but did not become ready before hook readiness timeout');\n    return false;\n  }\n  // Amplifier guard: even if the worker that won the port is still stale,\n  // never recycle a second time in the same hook invocation.\n  if (expectedPluginVersion !== null) {\n    await warnIfVersionStillMismatched(expectedPluginVersion);\n  }\n  return true;\n}","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/shared/worker-utils.ts#L577-L613","documentation":"This invocation spawned the worker (spawnLockHeld true), then waitForWorkerPort — 6 attempts with 500ms backoff (~15.5s, matching POST_SPAWN_WAIT) — never saw the port open, so the hook gives up. The long budget exists because cold macOS+Chroma boots need ~7s (#2795); exceeding ~15s means the worker is stuck or crashing before it can bind.","triggerScenarios":"The spawned worker crashes before listen (bad config, DB lock, missing env), a cold start drags past 15s, or another process squats the configured worker port so bind fails.","commonSituations":"First boot after reboot on slow disks; first-run Chroma initialization; port conflict from an orphaned or foreign process on CLAUDE_MEM_WORKER_PORT.","solutions":["Run the worker manually (bun plugin/scripts/worker-service.cjs) and read the pre-bind crash output.","Check the port is free: lsof -i :$CLAUDE_MEM_WORKER_PORT; kill whatever squats it.","If logs show Chroma contention, clear stale Chroma lock files under ~/.claude-mem/chroma and retry.","Pre-start the daemon at login so the first session does not cold-boot inside a hook."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const alive = await waitForWorkerPort({ attempts: 6, backoffMs: 500 });\nif (!alive) {\n  // diagnose pre-bind crash: run worker manually, check port\n  return false;\n}","typeGuard":"const isPortOpen = async (port: number): Promise<boolean> => {\n  try { await fetch(`http://127.0.0.1:${port}/health`); return true; }\n  catch { return false; }\n};","tryCatchPattern":null,"preventionTips":["Pre-start the worker daemon at login so hooks never cold-boot under a 15s ceiling.","Keep the worker port dedicated — check lsof for squatters when the warning appears.","On very slow disks, warm Chroma (first-run model download) before the first session."],"tags":["worker","spawn","port-open","cold-boot","timeout","claude-mem"],"backgroundTag":"startup-timeout","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}