{"record":{"id":"c2f88586fb0bc79b","repo":"coleam00/Archon","slug":"owner-returned-an-invalid-pid","errorCode":null,"errorMessage":"owner returned an invalid PID","messagePattern":"owner returned an invalid PID","errorType":"exception","errorClass":"DetachedRunOwnerUnavailableError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/detached-run-control.ts","lineNumber":313,"sourceCode":"  };\n}\n\nfunction parseOwnerResponse(runId: string, raw: string): number {\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(raw);\n  } catch {\n    throw new DetachedRunOwnerUnavailableError(runId, 'owner returned an invalid response');\n  }\n  if (\n    typeof parsed !== 'object' ||\n    parsed === null ||\n    !('pid' in parsed) ||\n    typeof parsed.pid !== 'number' ||\n    !Number.isInteger(parsed.pid) ||\n    parsed.pid <= 0\n  ) {\n    throw new DetachedRunOwnerUnavailableError(runId, 'owner returned an invalid PID');\n  }\n  return parsed.pid;\n}\n\n/** Ask the live exact-run owner for an opaque termination lease. */\nexport function requestDetachedRunStop(runId: string): Promise<DetachedRunStopTarget> {\n  const path = detachedRunControlPath(runId);\n  return new Promise((resolve, reject) => {\n    const socket = createConnection(path);\n    let response = '';\n    let settled = false;\n    const fail = (detail: string): void => {\n      if (settled) return;\n      settled = true;\n      socket.destroy();\n      reject(new DetachedRunOwnerUnavailableError(runId, detail));\n    };\n    const onEnd = (): void => {","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/utils/detached-run-control.ts#L295-L331","documentation":"parseOwnerResponse() successfully parsed JSON but the 'pid' field is missing, not a number, not an integer, or <= 0. Since the whole point of the exchange is to learn the owner's process id for cancellation, an unusable pid makes the run effectively uncontrollable, so DetachedRunOwnerUnavailableError is thrown with reason 'owner returned an invalid PID'.","triggerScenarios":"The owner endpoint returns valid JSON whose pid field fails typeof number / Number.isInteger / > 0 checks.","commonSituations":"A protocol-version mismatch where the owner replies {\"processId\": ...} or omits pid; a stub/mock or third-party process bound to the socket returning a different schema; a corrupted owner build.","solutions":["Check the Archon version owning the run and align it with your CLI version (protocol mismatch is the usual cause).","Stop the misbehaving owner and restart the run to get a fresh, correct owner.","If reproducible, report it with the raw owner response — the schema sent by the owner should always include a positive integer pid."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"function hasValidPid(raw: string): boolean {\n  try {\n    const o: unknown = JSON.parse(raw);\n    return typeof o === 'object' && o !== null && 'pid' in o\n      && Number.isInteger((o as { pid: unknown }).pid) && (o as { pid: number }).pid > 0;\n  } catch { return false; }\n}","typeGuard":"function isOwnerPidPayload(v: unknown): v is { pid: number } {\n  return typeof v === 'object' && v !== null\n    && 'pid' in v\n    && typeof (v as { pid: unknown }).pid === 'number'\n    && Number.isInteger((v as { pid: number }).pid)\n    && (v as { pid: number }).pid > 0;\n}","tryCatchPattern":"try {\n  const pid = await getDetachedRunOwnerPid(runId);\n} catch (err) {\n  if (err instanceof DetachedRunOwnerUnavailableError && err.reason === 'owner returned an invalid PID') {\n    console.error('Owner replied with unusable pid (version/protocol mismatch?); restart the run.');\n  } else throw err;\n}","preventionTips":["Align owner and client Archon versions so the {pid:number} schema matches.","Reject/stub owners that return alternate field names; restart the run cleanly.","Log the raw payload (no secrets) when diagnosing protocol mismatches."],"tags":["ipc","protocol","json","detached-run"],"backgroundTag":"invalid-response-payload","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}