INNER CODE UNIT · TypeScript

findProxyOwnerBeforeJournalRecovery

lidge-jun/opencodex · src/cli/index.ts:370

async function findProxyOwnerBeforeJournalRecovery(
  options: { probeConfiguredPort?: boolean; deferPidCleanup?: boolean } = {},
): Promise<{ live: LiveProxy | null; pidSnapshot: number | null }> {
  const pidSnapshot = readPidFileValue();
  const hasRuntimeOwner = readRuntimePort() !== null;
  const shouldProbe = pidSnapshot !== null || hasRuntimeOwner || options.probeConfiguredPort === true;
  // A negative answer lets the caller walk past a proxy it was supposed to find and
  // deletes this home's stale pid record. Start and ensure defer that write to the
  // lease-held owner recheck; journal recovery follows cross-home discovery.
  // One 750ms probe is not enough evidence for that (#5004) — a transport
  // failure is indistinguishable from an empty port, and the reported Windows duplicate
  // came from exactly that answer on a proxy the previous command had just found healthy.
  const live = shouldProbe ? await findLiveProxy(START_OWNERSHIP_LIVENESS) : null;
  if (live) return { live, pidSnapshot };

  if (!options.deferPidCleanup) removePidIfValueIs(pidSnapshot);
  return { live: null, pidSnapshot };
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…