Repository navigation
fix(codex): first Codex start after a Gateway crash fails on macOS - #176576
Conversation
On macOS the native proc-safe census reports a process in its SIGKILL exit window as a bare row without topology, so Darwin inspection fails closed. The Codex reaper's post-SIGKILL confirmation loops treated that first failed observation as lost custody: every first orphan reap after a Gateway crash failed with "Cannot reap registered Codex process", and live transport closes could report cleanup "uncertain". After our own SIGKILL, retry failed observations until the existing containment deadline; runs without SIGKILL are unchanged and the deadline still fails closed. The orphan test's macOS "inspection unavailable" step used a fake ps, which macOS no longer runs since #175368, so it silently became the first real reap attempt. It now disables the native binding with proc-safe's documented PROC_SAFE_NATIVE=off mode.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR retries failed process observations after containment kills and restores the macOS orphan test’s inspection-failure scenario. Example: Restart Codex on macOS after a Gateway crash leaves registered app-server processes alive.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a source-confirmed macOS recovery failure still present on main. The focused change preserves identity checks, fail-closed cleanup, and existing deadlines; no actionable introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Codex plugin’s stdio transport checks durable process registrations before spawning app-servers and uses OS identity snapshots to contain descendants and report confirmed or uncertain cleanup. flowchart TD
A[Codex stdio start] --> B[Registered orphan sweep]
B --> C[Process containment]
D[Transport close] --> C
C --> E[Native process observations]
E --> C
C --> F[Confirmed exit or uncertain cleanup]
Technical reviewBest possible solution: Keep bounded post-kill observation retries in the existing containment owner while retaining positive exit evidence and identity validation. Do we have a high-confidence way to reproduce the issue? Current source connects incomplete native topology to immediate confirmation failure, and the author supplies a specific macOS before/after reproduction; no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete caller repair: tolerate uncertain observations after the caller’s own destructive action, require confirmed cleanup before success, and repair the existing regression fixture without adding machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3c3c7c2415c9. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +5. Total +16 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 18, 2026, 6:54 PM ET / 22:54 UTC. |
|
Merged via squash.
|
…aw#176576) On macOS the native proc-safe census reports a process in its SIGKILL exit window as a bare row without topology, so Darwin inspection fails closed. The Codex reaper's post-SIGKILL confirmation loops treated that first failed observation as lost custody: every first orphan reap after a Gateway crash failed with "Cannot reap registered Codex process", and live transport closes could report cleanup "uncertain". After our own SIGKILL, retry failed observations until the existing containment deadline; runs without SIGKILL are unchanged and the deadline still fails closed. The orphan test's macOS "inspection unavailable" step used a fake ps, which macOS no longer runs since openclaw#175368, so it silently became the first real reap attempt. It now disables the native binding with proc-safe's documented PROC_SAFE_NATIVE=off mode.
* fix(process): backport native Darwin group inspection Backport the process census and supervisor tests from #174147. The independent Doctor diagnostics and runtime-pin migration changes are excluded. (cherry picked from commit 6d50f72) * refactor(process): backport the shared Darwin inspection owner Backport the process owner, SDK exports, Codex consumer and their tests from #174284. The independent credential detection and onboarding changes are excluded. Preserve the release branch's unrelated diagnostic documentation. (cherry picked from commit 4959773) * refactor(process): share native macOS census across runtimes Backport #175368. Retain fs-safe 0.26.5 and adapt native census fixtures to the release branch. Carries the approved DarwinProcess uid-to-owner SDK migration; the following package pin completes the exit-window repair. (cherry picked from commit f236b19) * fix(codex): retry post-kill observations through the native exit window Backport #176576. Keep custody while retrying observations after our own SIGKILL within the existing containment deadline. (cherry picked from commit 5f94dfb) * fix(process): preserve macOS cleanup while unrelated processes exit Backport #176612. Pin proc-safe 0.4.2 and its exact native package exclusions, retain the real exiting-process regression, and align the SDK summary with native inspection on both runtimes. Retain the release branch's other dependency pins and exemptions. (cherry picked from commit 727c607) * test(process): reuse the process group inspection helper
What Problem This Solves
Fixes: on macOS, the first Codex start after a Gateway crash fails with
Cannot reap registered Codex process <pid>. Stop it before retrying.(one failed start per orphan), and closing a live Codex app-server can intermittently report process cleanup asuncertain.User Impact
User impact: after a crash on macOS, OpenClaw reaps orphaned Codex app-servers and starts a fresh one on the first attempt again. Closing a Codex transport on a loaded Mac no longer reports spurious uncertain cleanup. Linux behavior is unchanged, and inspection failures still fail closed at the existing 2 s containment deadline.
Why This Change Was Made
Since #175368, macOS process inspection uses the native
@openclaw/proc-safecensus for both Node and Bun. During the few milliseconds between SIGKILL and exit, that census reports the dying process as a bare{ pid, owner: "unknown" }row whilereadProcessIdentitystill sees it. The shared Darwin inspection owner correctly fails closed on that (the SDK contract says inspection errors never prove absence). But the Codex reaper's two post-SIGKILL confirmation loops gave up on that first failed observation. The reaper's own kill puts the process into exactly that window, so confirmation failed almost every time even though the kill had worked.The fix is local to the caller that caused the window. After our own SIGKILL, a failed observation is retried every 20 ms until the existing containment deadline, instead of being treated as lost custody. The stopped root keeps custody while we retry, and runs that never sent a SIGKILL behave exactly as before.
The orphan test is also fixed. Its macOS "inspection unavailable" step put a failing fake
psonPATH, but macOS no longer runsps. The step therefore stopped testing inspection failure; it became the first real reap attempt, which hit the bug above. It now uses proc-safe's documentedPROC_SAFE_NATIVE=offmode (native-only operations throwhelper-unavailable, already used bysrc/daemon/systemd-loaded-unit-inventory.test.ts). The fixture owner applies that mode per start. That makes the step a genuine inspection failure, which fails closed and leaves the orphans alive, and it exposed the reap regression in the following step. Linux still runs every start with the fakepsto prove procfs never needs it. The test's old generic-psbranch is gone because the test needs a pinned native Codex binary, which exists only for macOS, Linux, and Windows.Release-note context: Codex plugin, macOS only. Fixes orphaned app-server reaping after a Gateway crash (regression from #175368) and spurious
uncertaincleanup on transport close.Evidence
On macOS 27 (arm64, Node 24.22,
@openclaw/proc-safe0.4.1), host load average 40–63:{ pid, owner: "unknown" }fromlistProcesses({ pids: [pid] })whilereadProcessIdentity(pid)returnsexited: false. The window lasted until the process vanished about 2–4 ms later, and it appeared in 4 of 5 runs.Cannot reap registered Codex process(the native root, then the Node root on the retry). After the fix, one start reaps both orphan trees and spawns a fresh child.pnpm test extensions/codex/src/app-server/transport-orphan.test.ts --maxWorkers=1:expected 'Cannot inspect Codex processes…' but got 'Cannot reap registered Codex process …'Cannot reap registered Codex process 57614, which is the regression this PR fixestransport.process.test.ts, three runs each at the same load (~50–63):late,reparented,root-resumed,traced, anduninterruptiblefailed in varying combinations, plus "reaps descendants in independent and root process groups" in 2 runs.transport-process-registration{,.procfs,.lifecycle}.test.ts,transport-process-snapshot.test.ts, andtransport-stdio.test.tspass.oxfmt --checkandoxlintare clean on the touched files.pnpm tsgo:extensionsandpnpm tsgo:extensions:testpass.Remaining gap: a full census also fails whenever any unrelated host process is mid-exit (I measured about 0.8% of
readDarwinProcessTreecalls at load ~56). That is the likely source of the remaining rare "reaps descendants…" flake. The right fix is in proc-safe (fill topology for exiting processes from the kernel record, as it already does for zombies), followed by a dependency bump; I've filed that as a separate follow-up.