Skip to content

fix(codex): first Codex start after a Gateway crash fails on macOS - #176576

Merged
steipete merged 1 commit into
mainfrom
fix/codex-orphan-darwin-inspection
Oct 18, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/codex-orphan-darwin-inspection

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 as uncertain.

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-safe census 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 while readProcessIdentity still 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 ps on PATH, but macOS no longer runs ps. 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 documented PROC_SAFE_NATIVE=off mode (native-only operations throw helper-unavailable, already used by src/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 fake ps to prove procfs never needs it. The test's old generic-ps branch 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 uncertain cleanup on transport close.

Evidence

On macOS 27 (arm64, Node 24.22, @openclaw/proc-safe 0.4.1), host load average 40–63:

  • Root cause probe: an orphaned process that is SIGSTOPped and then SIGKILLed shows { pid, owner: "unknown" } from listProcesses({ pids: [pid] }) while readProcessIdentity(pid) returns exited: false. The window lasted until the process vanished about 2–4 ms later, and it appeared in 4 of 5 runs.
  • Standalone repro with the real orphan fixture: before the fix, every reap attempt killed the tree but reported 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:
    • before, on main: fails with expected 'Cannot inspect Codex processes…' but got 'Cannot reap registered Codex process …'
    • with only the test seam fixed: fails at the fresh start with Cannot reap registered Codex process 57614, which is the regression this PR fixes
    • with this PR: passes (28.7 s test time at load ~40, 35.6 s at load ~61; about 110–200 s wall including Vitest worker preparation). The test cost is unchanged and dominated by the cold native app-server boots it needs.
  • transport.process.test.ts, three runs each at the same load (~50–63):
    • before: 3/3 runs failed, 10 failing cases. The "revalidates identities while quiescing" modes late, reparented, root-resumed, traced, and uninterruptible failed in varying combinations, plus "reaps descendants in independent and root process groups" in 2 runs.
    • after: all 30 quiesce-mode executions passed. One run still had a single "reaps descendants…" failure; see the remaining gap below.
  • Siblings: transport-process-registration{,.procfs,.lifecycle}.test.ts, transport-process-snapshot.test.ts, and transport-stdio.test.ts pass.
  • Static checks: oxfmt --check and oxlint are clean on the touched files. pnpm tsgo:extensions and pnpm tsgo:extensions:test pass.
  • Review: a Codex autoreview at P2 on this exact diff came back scoped-clean, with no accepted findings.

Remaining gap: a full census also fails whenever any unrelated host process is mid-exit (I measured about 0.8% of readDarwinProcessTree calls 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T22:42:20.413586Z e61105d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: A reap attempt can kill process 57614 but fail with “Cannot reap registered Codex process 57614,” requiring another start.
  • After: Cleanup observes through the brief native exit window and starts the replacement after confirming the orphan trees are gone.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct repair with meaningful real-process regression evidence; proof remains fixture-driven rather than a shipped Gateway flow.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate is exempt for this maintainer-authored PR; its body reports real macOS native-process recovery through the production stdio owner, including a failing test-seam-only control and passing patched runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After a Gateway crash on macOS, Codex can reject its first restart despite killing the orphan, and transport closure can report uncertain cleanup.
Reason: The maintainer-authored direction restores automatic recovery using the existing owner and safety contract, with no new product surface.

Regression provenance

Regression provenance — verified: source commit f236b1969015 by Peter Steinberger; canonical PR #175368 (blame-to-merge-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
Reviewed head: e61105da2f8d977772f48de5988ed68e2181cca3

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises production stdio owners and real native processes through fixtures, rather than an isolated Gateway restart.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Orphan and descendant cleanup confirmation changes intended behavior with a stated reason (10ee252: Prevent fresh Codex work from overlapping registered work left by a dead Gateway; later cleanup-evidence changes require confirmed extinction.)
  • Containment deadlines keeps the original intent (ba3ee86: Use a monotonic clock so wall-clock changes cannot distort the containment budget.)
  • Reusable orphan fixture keeps the original intent (2dad3cb: Reuse a surviving owner and warmed stores while preserving real crash, registration, and live-owner controls.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 10ee252 adds extensions/codex/src/app-server/transport-process-containment.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 10ee252b56d7; files: extensions/codex/src/app-server/transport-process-containment.ts)
  • SunnyShu: Raw commit ba3ee86 adds extensions/codex/src/app-server/transport-process-containment.ts:52 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ba3ee866cabf; files: extensions/codex/src/app-server/transport-process-containment.ts)

PR surface

Source +11, Tests +5. Total +16 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 20 9 +11
Tests 1 9 4 +5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 29 13 +16

Labels

Label changes:

  • add P2: A focused macOS crash-recovery regression causes failed first starts and uncertain cleanup; the evidence does not establish a released, broadly blocking outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A focused macOS crash-recovery regression causes failed first starts and uncertain cleanup; the evidence does not establish a released, broadly blocking outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 18, 2026, 6:54 PM ET / 22:54 UTC.

@steipete
steipete merged commit 5f94dfb into main Oct 18, 2026
108 checks passed
@steipete
steipete deleted the fix/codex-orphan-darwin-inspection branch October 18, 2026 23:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…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.
RomneyDa pushed a commit that referenced this pull request Oct 30, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant