{"record":{"id":"a58e741cd41e4e69","repo":"rohitg00/agentmemory","slug":"engine-not-responding-on-port-but-survivors","errorCode":null,"errorMessage":"Engine not responding on :${port}, but ${survivors.size} process(es) still hold the port or pidfile: ${[...survivors].join(\", \")}","messagePattern":"Engine not responding on :(.+?), but (.+?) process\\(es\\) still hold the port or pidfile: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":3554,"sourceCode":"      // instead of preserving for manual cleanup.\n      const s = p.spinner();\n      s.start(`Stopping orphaned agentmemory worker (pid ${workerPid})...`);\n      const ok = await signalAndWait(workerPid, \"SIGTERM\", 3000);\n      s.stop(ok ? `Stopped worker pid ${workerPid}` : `Failed to stop worker pid ${workerPid}`);\n      clearEnginePidfile();\n      clearEngineState();\n      clearWorkerPidfile();\n      if (!ok) {\n        p.log.error(`Worker pid ${workerPid} survived SIGKILL. Investigate with \\`ps\\`.`);\n        process.exit(1);\n      }\n      p.outro(\"Stopped orphaned worker. Memories persisted to disk.\");\n      return;\n    }\n    const survivors = new Set<number>(portPids);\n    if (pidfilePid) survivors.add(pidfilePid);\n    if (workerPid) survivors.add(workerPid);\n    p.log.warn(\n      `Engine not responding on :${port}, but ${survivors.size} process(es) still hold the port or pidfile: ${[...survivors].join(\", \")}`,\n    );\n    p.log.info(\n      `Preserving ~/.agentmemory/iii.pid + worker.pid. Investigate before manual cleanup:\\n  ps -p ${[...survivors].join(\",\")} -o pid,ppid,comm,etime\\n  ${IS_WINDOWS ? \"netstat -ano | findstr :\" + port : \"lsof -i :\" + port}`,\n    );\n    process.exit(1);\n  }\n\n  if (!state) {\n    const compose = discoverComposeFile();\n    if (compose && pidfilePid === null) {\n      if (force) {\n        p.log.warn(\n          `--force: bypassing Docker-heuristic guard. Falling back to native pidfile + lsof on :${port}.`,\n        );\n      } else {\n        p.log.error(\n          `Engine is running on :${port} but no pidfile or state file is present. It may have been started via Docker compose by a different shell. Refusing to signal host PIDs.\\n\\nStop it with:\\n  docker compose -f ${compose} down\\n\\nOr re-run with --force to signal whatever lsof finds on :${port}, or AGENTMEMORY_USE_DOCKER=1 to record state next time.`,","sourceCodeStart":3536,"sourceCodeEnd":3572,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/cli.ts#L3536-L3572","documentation":"Fatal stop-flow warning: the engine does not respond on the port (not actually serving), but one or more processes still hold the port or are referenced by the pidfile/worker pidfile. The CLI preserves state files and exits 1 so the user can investigate instead of blindly killing.","triggerScenarios":"Port PIDs or pidfile/worker pids exist, but health check on the port fails — hung processes, stale pidfile pointing at a live unrelated process, or half-dead engine.","commonSituations":"Engine crashed without cleanup leaving orphaned listeners; another app bound the port; process in uninterruptible (D) state; container port mapping.","solutions":["Inspect the listed pids: ps -p <pids> -o pid,ppid,comm,etime and lsof -i :<port>","Kill the confirmed survivors manually: kill <pid> (or kill -9 if needed)","If the pids are stale/unrelated, remove ~/.agentmemory/iii.pid and worker.pid, then restart the engine","Re-run with --force to bypass the guard once you understand the situation"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"lsof -i :49134 && ps -p $(cat ~/.agentmemory/iii.pid) -o pid,ppid,comm,etime 2>/dev/null || echo \"stale pidfile\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the engine exits cleanly (use the provided stop command)","Monitor for orphaned listeners after crashes","Clean stale pidfiles only after confirming the pid is dead"],"tags":["process","port-conflict","stale-pidfile"],"backgroundTag":"port-already-in-use","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}