{"record":{"id":"a23028258978e699","repo":"stablyai/orca","slug":"recorded-benchmark-helper-pid-now-belongs-to-anoth","errorCode":null,"errorMessage":"Recorded benchmark helper PID now belongs to another process","messagePattern":"Recorded benchmark helper PID now belongs to another process","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/macos-computer-helper-owner-loss-processes.mjs","lineNumber":348,"sourceCode":"\nconst processSignalOperations = {\n  processIdentity,\n  signalProcess: process.kill.bind(process)\n}\n\nexport function signalProcessIdentity(\n  identity,\n  expectedCommandFragment,\n  signal,\n  operations = processSignalOperations\n) {\n  validateDetachedIdentity(identity, expectedCommandFragment)\n  const currentIdentity = operations.processIdentity(identity.pid)\n  if (!currentIdentity) {\n    return false\n  }\n  if (!sameIdentity(currentIdentity, identity)) {\n    throw new Error('Recorded benchmark helper PID now belongs to another process')\n  }\n  let stopped = false\n  try {\n    operations.signalProcess(identity.pid, 'SIGSTOP')\n    stopped = true\n    const stoppedIdentity = operations.processIdentity(identity.pid)\n    if (!sameIdentity(stoppedIdentity, identity)) {\n      throw new Error('Recorded benchmark helper PID changed before signaling')\n    }\n    operations.signalProcess(-identity.pgid, signal)\n    if (signal !== 'SIGKILL') {\n      operations.signalProcess(-identity.pgid, 'SIGCONT')\n    }\n    stopped = false\n    return true\n  } catch (error) {\n    let resumeError\n    if (stopped) {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/macos-computer-helper-owner-loss-processes.mjs#L330-L366","documentation":"signalProcessIdentity reads a recorded identity, validates it, then re-fetches the live identity by pid. If the pid is still alive but sameIdentity is false (pgid or command differs), the recorded helper has exited and the OS recycled its PID for an unrelated process. Signaling would hit the wrong process, so it throws rather than risk killing an innocent process.","triggerScenarios":"operations.processIdentity(identity.pid) returns a non-null identity whose pid matches but pgid or command differs from the recorded identity.","commonSituations":"Long gaps between recording the helper PID (writeProcessRecord) and acting on it; systems with aggressive PID wrapping (containers, macOS under load); or a recorded identity that was never detached (validateDetachedIdentity requires pgid === pid) so the OS reuses the pid freely after the helper exits.","solutions":["Re-spawn the helper and re-record its identity rather than signaling the recycled pid","Reduce latency between writeProcessRecord and signalProcessIdentity so recycling is unlikely","Use killRecordedProcess which combines identity check + exit wait, and pair it with killProcessMatchingCommand as a fallback","Confirm the recorded command fragment is unique enough that a recycled pid is unlikely to match by coincidence"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { processIdentityIsCurrent } from './macos-computer-helper-owner-loss-processes.mjs'\n\nif (!processIdentityIsCurrent(recorded)) {\n  // pid was recycled; do NOT signal\n  return\n}","typeGuard":null,"tryCatchPattern":"try {\n  signalProcessIdentity(recorded, frag, 'SIGKILL')\n} catch (error) {\n  if (/now belongs to another process/.test(error.message)) {\n    killProcessMatchingCommand([frag])\n  } else throw error\n}","preventionTips":["Gate signalProcessIdentity with processIdentityIsCurrent to fail fast","Minimize latency between writeProcessRecord and signalProcessIdentity","Use killRecordedAndMatchingProcesses which combines both kill paths"],"tags":["pid-reuse","process-management","toctou","safety"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}