INNER CODE UNIT · TypeScript
handleEnsure
lidge-jun/opencodex · src/cli/index.ts:821
async function handleEnsure(options: { existingIsSuccess?: boolean; forceStart?: boolean; onSpawn?: (child: ReturnType<typeof spawn>) => void } = {}): Promise<boolean> {
const owner = await findProxyOwnerBeforeJournalRecovery({ probeConfiguredPort: true, deferPidCleanup: true });
if (!owner.live) await recoverStartStateUnderOwnershipLease({
supervised: false,
acquireLease: () => acquireOwnershipMutationLease(serviceStatePaths()),
decide: () => ({ kind: "proceed" }),
stayOut: () => { throw new Error("ordinary ensure has no service stay-out decision"); },
recover: () => recoverStartJournalAfterOwnerRecheck(owner),
});
// A later ensure can find this home's sibling alive; the other port still owns shared clients.
if (owner.live) await markLiveHomeSibling(owner.live);
const config = loadConfig();
if (!options.forceStart && !codexAutoStartEnabled(config)) {
console.log("Codex autostart is disabled.");
return false;
}
let live = owner.live;
if (!live) {