{"record":{"id":"2380765a99cd976a","repo":"coleam00/Archon","slug":"refusing-to-terminate-invalid-detached-owner-pid","errorCode":null,"errorMessage":"Refusing to terminate invalid detached owner PID ${String(pid)}","messagePattern":"Refusing to terminate invalid detached owner PID (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/detached-run-control.ts","lineNumber":506,"sourceCode":" * carries neither. Nothing here reads message text, so it holds under any locale.\n *\n * Exported for testing: the Windows termination path tolerates a completed-but-failed\n * command and must never tolerate an interrupted one, and that decision cannot be\n * exercised from a platform where the path does not run.\n */\nexport function commandTerminatedBySignal(error: unknown): boolean {\n  if (typeof error !== 'object' || error === null) return false;\n  const { killed, signal } = error as { killed?: unknown; signal?: unknown };\n  return killed === true || typeof signal === 'string';\n}\n\n/** Terminate the process tree while its exact-run owner holds the IPC lease open. */\nasync function terminateDetachedProcessTree(\n  pid: number,\n  ownsLiveLease: () => boolean\n): Promise<void> {\n  if (!Number.isInteger(pid) || pid <= 0 || pid === process.pid) {\n    throw new Error(`Refusing to terminate invalid detached owner PID ${String(pid)}`);\n  }\n  if (!ownsLiveLease()) {\n    throw new Error(`Detached workflow owner ${String(pid)} released its termination lease`);\n  }\n\n  if (process.platform === 'win32') {\n    // `taskkill /T` walks the tree PID by PID and exits non-zero when any of them is\n    // already gone — the outcome this function wants, reached early. Nothing in that\n    // exit code separates it from a kill that genuinely failed, so it is not the\n    // proof: the confirmation below is, the same way the POSIX branch tolerates ESRCH\n    // and then re-checks. A tree that is still running throws there, carrying the\n    // command's own error as the evidence.\n    //\n    // A walk that never finished is a different case and is rethrown here. The root\n    // check can only stand in for the whole tree when every descendant was visited,\n    // and a `timeout` kill leaves taskkill part-way through: the root can be gone\n    // while a descendant the walk never reached is still alive. `/T` is what takes\n    // the descendants with the root, and that they actually die is proved by the","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/utils/detached-run-control.ts#L488-L524","documentation":"Error \"Refusing to terminate invalid detached owner PID ${String(pid)}\" thrown in coleam00/Archon.","triggerScenarios":"Thrown at packages/cli/src/utils/detached-run-control.ts:506 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}