Skip to content

fix(codex): reap orphaned app-servers before reconnect - #132610

Merged
steipete merged 6 commits into
mainfrom
codex/reap-app-server-orphans
Aug 29, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/reap-app-server-orphans

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Related: #132413 (bounded terminal settlement), follow-up 3.

What Problem This Solves

Fixes an issue where a hard-killed Gateway left its detached Codex app-server alive, allowing pre-restart native work to overlap a fresh connection against the same state. Graceful transport shutdown already contained descendants, but the next process had no durable spawn fact identifying the old child.

Why This Change Was Made

The stdio spawn owner now reaps registrations belonging to dead parents before creating a fresh child, and commits the new parent/child process identities to the existing state-directory-scoped SQLite plugin store before Codex initialization. It reuses the existing bounded process containment algorithm instead of adding command-name discovery or another supervisor; asynchronous startup retains acquisition deadlines, late-client disposal, and node exec authorization revalidation.

Registrations have unique keys, no expiry/eviction, and no schema change. Live parents are skipped. Start-time/PID/group checks reject reused or ambiguous identities; uncertain cleanup keeps the row and fails visibly. Normal exit removes the registration. WebSocket/Unix endpoints are externally owned and unaffected. The async client-start API is plugin-private.

User Impact

On POSIX, reconnecting after a hard Gateway stop cannot start another registered stdio child until the previous dead owner's app-server is confirmed gone. Healthy concurrent instances remain running. Recovery is automatic on connection, with no new configuration.

Limits: pre-upgrade unregistered children are not guessed from command names; Windows has no equivalent reaper in this change. The PID/start-time checks are not atomic OS handles and cannot recover independently reparented descendants outside the verified tree/group. A kill between spawn and registration can still leave an uninitialized child, but Codex rejects native requests before initialize. Linux reads kernel procfs identities (boot ID plus start ticks); macOS uses native ps. Supported Alpine/BusyBox installs need no extra package.

Evidence

  • Failing-first real-process regression on baseline 32bd1602e54009287f24157f8a1776691f56f77e: after parent SIGKILL and a fresh same-state spawn, the old child was still alive. The repaired test removes the child and its independently detached descendant while preserving live same-state and separate-state controls.
  • Real Codex binary proof on Linux and macOS: start a native command/exec, SIGSTOP its app-server to prevent EOF cleanup, SIGKILL the OpenClaw parent, and reconnect. The old app-server and command are gone before the replacement reports ready. This is real native execution with isolated homes and no provider inference or saved credentials.
  • On macOS, unavailable ps blocks startup without consuming the registration; retry with working inspection reaps it. Linux crash-recovery tests run with an intentionally failing ps to prove no dependency on procps. Stale start identity and process-group mismatch are covered separately from existing descendant PID-reuse/cleanup tests. An isolated acquisition deadline disposes a client returned late, and node authorization is rechecked after awaited setup.
  • Linux Blacksmith Testbox tbx_01m16sv1xtrxp72r7bkt0p6m10: 124 tests passed across crash recovery, shared client, stdio, WebSocket/Unix, and node exec policy. A later expanded rerun was blocked by missing tsx after full sync and a frozen-lockfile dependency-bootstrap error; that lease was stopped. Final hosted checks will be recorded below.
  • Codex autoreview: no accepted/actionable findings at its P0 threshold. Independent lifecycle challenge additionally identified and drove the startup-deadline and orphan-unwind repairs.
  • Direct upstream contract inspection at openai/codex@6478a751fde8884b2fdc76486fe23175a8e795d4: codex-rs/app-server/src/message_processor.rs:837-889 (initialization gate), codex-rs/app-server-transport/src/transport/stdio.rs:24-78 (EOF), codex-rs/app-server/src/lib.rs:1015-1035,1176-1186 (connection shutdown/drain), and codex-rs/app-server-protocol/src/protocol/v2/command_exec.rs:24-109 (native command proof).

The inspected shallow baseline already contains detached spawning; the exact original introduction was not established. This repairs the explicitly named follow-up, without changing terminal settlement or native rollout recovery policy.

Production LOC: +436/-113 (net +323); tests and test support: +857/-442; docs: +33. These totals include the platform inspector extraction; pure moves do not contribute to the net. Growth supplies the previously missing durable spawn ownership, first-connect reaping, and bounded asynchronous startup. Existing descendant containment is reused and the former synchronous spawn path is replaced; there is no second supervisor, compatibility fallback, or new database schema.

Final local sibling proof: node scripts/run-vitest.mjs over transport.process.test.ts, shared-client.test.ts, attempt-startup.test.ts, models.test.ts, run-attempt-thread-cleanup.test.ts, and thread-lifecycle.binding.test.ts: 293 passed, including the new stale-root-identity and group-drift cases. The final macOS native hard-kill probe also passed after the fixture reused isolated native setup and disabled unrelated native proxy/snapshot discovery.

Linux proof ran on Blacksmith Testbox workflow 33254010522; the wrapper's successful command exit/timing JSON is the proof result (the lease was subsequently stopped).

Local gates: full pnpm build passed. node scripts/check-changed.mjs passed all formatting, typechecking, boundary, dead-code and policy gates; its final lint batch caught an implicit Promise-executor return, corrected without a behavior change. The full affected lint batch then passed, as did the four process-containment tests and a fresh Codex autoreview of that correction.

Review corrections and final proof

ClawSweeper correctly identified a supported-platform compatibility problem: stable v2026.7.1 already recommends node:24-alpine, whose BusyBox ps lacks lstart. The fix now uses one canonical Linux procfs inspector; macOS retains native ps. This removes the new Linux system-package prerequisite without silently skipping registration or allowing overlapping old work. The kernel documents process stat fields and boot identity.

Alpine before/after proof used a minimal node:26-alpine Docker container (Node 26.8.1, no added procps, no network during the probe). The previous PR head fails at registration with “Cannot register the Codex child process.” The corrected registration/containment and real SQLite store, bundled from source for this environment probe, survive the exact sequence: spawn/register; SIGKILL parent; prove old tree alive; reconnect; prove old root and detached descendant gone while live same-state and separate-state controls remain. This is a real subprocess/store probe, not a packaged-install or provider-inference claim.

The first hosted CI run 33255824607 passed all 17 changed-plugin shards but exposed a stale catalog test mock lacking PID/spawn lifecycle. That test now uses the supported user-home Unix socket transport and retains catalog, account-change, route-isolation and disconnect assertions. The generated fake-ps fault driver was replaced by tests at the shared inspection boundary, retaining real signals and all nine fault scenarios; dedicated native-ps tests preserve inspector timeout/leak coverage.

Final combined macOS proof: node scripts/run-vitest.mjs extensions/codex/src/app-server/transport.process.test.ts extensions/codex/src/app-server/transport-process-snapshot.test.ts extensions/codex/src/app-server/transport-orphan.test.ts test/plugins/codex-model-catalog.gateway.test.ts — 17 tests passed across 4 files, including real native crash/reconnect. Fresh Codex autoreview of the complete correction found no actionable issue at its P0 threshold.

Rank-up disposition: the POSIX prerequisite finding is repaired and demonstrated on the affected Alpine environment. The upstream initialization-gate source was personally inspected and is directly available at message_processor.rs:880-889. The review worker's unavailable checkout was an access gap; no initialization assumption substitutes for this source proof. The flagged serialized-state file is a test subprocess fixture; runtime records use the existing plugin KV schema.

The procfs adapter also distinguishes ESRCH/ENOENT (a process exited during inspection) from EACCES (inspection failed). An Alpine injected-read reproduction failed before the ESRCH correction; all three outcomes pass afterward, and Linux-only regression cases cover the documented kernel contract plus command names containing spaces and closing parentheses. The correction received a fresh clean Codex autoreview.

Final builds passed: full pnpm build and the canonical node --import ./scripts/tsx.mjs scripts/build-all.mts gatewayWatch runtime refresh. Root-test typechecking then caught an ArrayBuffer overload in the socket fixture; the test now converts that variant through Uint8Array, matching the WebSocket binary contract. The corrected root-test typecheck, focused catalog/inspector rerun, and fresh Codex autoreview passed.

Final startup-order correction: hosted CI exposed a child that exited with a retryable SQLite failure while registration was still inspecting processes. Attaching the JSON-RPC client only afterward lost its stderr/exit event and masked the failure as registration error. The client now observes lifecycle events immediately after spawn, while initialization still waits for durable registration. A forced-order real-child regression failed before the fix; the final startup/shared-client/stdio run passed 111 tests without changing timeouts. Extension-test types, focused lint and Codex autoreview passed. Two intermediate local stress reruns timed out on this heavily loaded host; the clean full rerun passed, and no timeout was increased.

The unrelated shared-worker benchmark failure came from a preceding async-task fixture retaining a running task. The branch was rebased once to absorb its existing owner cleanup in #132643; no duplicate workaround was added. After rebase, 17 async-task/benchmark tests and both real native/fixture crash-recovery tests passed. Full local changed-file checks passed; the small startup correction additionally passed focused types/lint. Current head: d7aa5dc488657caed44d8da2e8de0a67c290be3a; exact-head CI33260972583 passed with no failed jobs.

Latest ClawSweeper disposition: the refreshed review has no concrete source finding. Its missing sibling checkout is covered by the personally inspected upstream initialization/EOF/drain source cited above. The deliberate fail-closed behavior is retained: when an old registered owner cannot be inspected or confirmed gone, spawning overlapping native work would violate this repair. Linux procfs removes the supported-Alpine prerequisite issue. The flagged serialization in the snapshot adapter is kernel process identity, and the helper is a test fixture; neither changes the SQLite schema.

Final focused command: node scripts/run-vitest.mjs extensions/codex/src/app-server/attempt-startup-retry.test.ts extensions/codex/src/app-server/shared-client.test.ts extensions/codex/src/app-server/transport-stdio.test.ts — 111 passed. Rebase sanity command: node scripts/run-vitest.mjs extensions/codex/src/app-server/transport-orphan.test.ts src/agents/embedded-agent-runner/run/attempt.async-tasks.test.ts test/scripts/bench-agent-concurrency.test.ts — 19 passed, including both real fixture/native crash-recovery cases. Exact-head CI completed successfully.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: L labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 13:45
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 29, 2026
@steipete steipete self-assigned this Aug 29, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 11:03 AM ET / 15:03 UTC.

ClawSweeper review

What this changes

The PR records POSIX Codex stdio app-server processes durably, reaps verified children left by a dead Gateway before reconnecting, and makes startup awaitable for deadline and authorization checks.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for maintainer review: current main still lacks the orphan-registration/reaping path, and the PR is maintainer-labeled. No source-level defect was confirmed, but this reviewer could not perform the repository-required direct sibling Codex source check.

Priority: P1
Reviewed head: b8ec3a6f63d046b68df56c6f7c70473947cb0e84
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is coherent and behavior-tested at its owner boundary, but the required direct upstream Codex contract check prevents a merge-ready Codex verdict in this environment.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate. Its body describes native crash/reconnect probes and the checked source contains a behavior-level process test, but this reviewer did not independently execute them and could not complete the required sibling Codex contract check.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate. Its body describes native crash/reconnect probes and the checked source contains a behavior-level process test, but this reviewer did not independently execute them and could not complete the required sibling Codex contract check.
Evidence reviewed 8 items Current main lacks this recovery path: Current main still returns the spawned stdio child directly; it has neither pre-spawn registration cleanup nor durable process registration, so the central behavior remains necessary.
Introduced owner boundary: The PR places recovery before spawn and persists the parent/child identity after spawn but before the caller can initialize the app-server.
Caller and lifecycle deadline: Shared-client startup awaits the new async start under its existing acquisition deadline and disposes a client that resolves after ownership has been released.
Findings None None.
Security None None.

How this fits together

The Codex plugin launches an app-server subprocess for native work. The new startup path reads prior process registrations, removes a verified orphan when its Gateway parent is gone, then persists the replacement process identity before Codex initialization.

flowchart LR
  A[Gateway requests Codex work] --> B[Codex stdio startup]
  B --> C[Process registration store]
  C --> D[Inspect prior Gateway owner]
  D -->|dead and identity verified| E[Reap orphan process tree]
  D -->|live or uncertain| F[Skip or fail visibly]
  E --> G[Spawn and register app-server]
  G --> H[Codex initialize and native work]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned POSIX recovery design proceed after a reviewer with the required sibling Codex checkout verifies the initialization and shutdown assumptions that bound orphan cleanup? Complete upstream contract check: Have a Codex-area reviewer inspect the pinned app-server initialization and EOF/shutdown behavior, then resume normal merge review.

Why: The PR directly launches and drives the Codex app-server, and repository policy requires direct sibling-source inspection before a Codex verdict or proof-sufficient claim; that checkout is unavailable here.

Before merge

  • Resolve merge risk (P1) - The new fail-closed recovery path can prevent Codex stdio startup when process inspection or bounded cleanup is unavailable; that is intentional, but requires maintainer acceptance for existing POSIX deployments.
  • Resolve merge risk (P1) - The repository-required direct inspection of the Codex app-server protocol/runtime could not be completed because ../codex is absent in this review environment.
  • Complete next step (P1) - A Codex-area maintainer must complete the direct upstream contract check and accept the intentional fail-closed startup behavior before merge.
Agent review details

Security

None.

PR surface

Source +406, Tests +289, Docs +33. Total +728 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 8 519 113 +406
Tests 13 730 441 +289
Docs 1 33 0 +33
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 1282 554 +728

Review metrics

Metric Value Why it matters
Production versus test delta production +425/-113 (net +312); tests/test support +824/-441; docs +33 The bug fix adds a substantial durable lifecycle owner, so its compatibility and startup-failure behavior merit maintainer review.

Stored data model

Persistent data-model change detected: serialized state: extensions/codex/src/app-server/transport-orphan.test-helper.ts, serialized state: extensions/codex/src/app-server/transport-process-snapshot.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the upstream lifecycle contract (recommended)
    Before merge, record direct Codex-source confirmation that initialization prevents native work until the durable registration point and that shutdown behavior matches the recovery assumptions.
  2. Accept the fail-closed recovery tradeoff
    Merge with explicit maintainer acceptance that inaccessible process inspection blocks a fresh POSIX Codex stdio connection rather than risking overlap.

Technical review

Best possible solution:

Retain the owner-plugin registration design if a Codex-area maintainer confirms the direct upstream initialization and shutdown contract, then merge only after the normal exact-head CI gates are green.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible with high confidence: current main starts a detached POSIX stdio child without a durable registration or reconnect-time reaper, and the added crash test encodes the hard-kill/reconnect sequence. This reviewer did not execute that sequence.

Is this the best way to solve the issue?

Unclear: the repair is located at the spawn owner and reuses the existing containment owner, which is the right architectural boundary, but the required direct Codex runtime-contract inspection remains unavailable.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3399dd67b7e8.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: A hard Gateway stop can otherwise permit overlapping native Codex work after reconnect.
  • merge-risk: 🚨 compatibility: Existing POSIX stdio deployments newly depend on process inspection and durable registration before startup.
  • merge-risk: 🚨 availability: When cleanup cannot verify an old child is gone, the PR intentionally blocks replacement startup.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate. Its body describes native crash/reconnect probes and the checked source contains a behavior-level process test, but this reviewer did not independently execute them and could not complete the required sibling Codex contract check.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main transport history and blame attribute the surrounding stdio startup path to Peter Steinberger, and the supplied PR metadata maps the current lifecycle work to steipete. (role: recent area contributor; confidence: high; commits: 3a16070e979b, b661be4679a8; files: extensions/codex/src/app-server/transport-stdio.ts, extensions/codex/src/app-server/shared-client.ts)
  • Ming Yoo: The prior process-containment repair established the descendant-cleanup surface that this PR extends to recovery after a crashed parent. (role: adjacent lifecycle contributor; confidence: medium; commits: cde3458c842e; files: extensions/codex/src/app-server/transport-process-containment.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record direct inspection of the required sibling Codex app-server initialization and shutdown contract before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-29T13:52:45.105Z sha 463d050 :: found issues before merge. :: [P1] Preserve startup when process inspection is unavailable
  • reviewed 2026-08-29T14:52:58.052Z sha 40df986 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 29, 2026
@steipete
steipete force-pushed the codex/reap-app-server-orphans branch from b8ec3a6 to d7aa5dc Compare August 29, 2026 15:42
@steipete

steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor Author

The final head d7aa5dc488657caed44d8da2e8de0a67c290be3a preserves early child stderr/exit events while registration awaits process inspection. Its forced-order regression failed before the correction; 111 startup/shared-client/stdio tests passed after it. The one rebase absorbs the already-landed async-task fixture cleanup in #132643; 17 related tests and both native/fixture crash-recovery probes passed afterward.

The PR body now includes the full local checks/build results, Alpine compatibility proof, direct upstream source references, and disposition of the previous review's rank-up request. The deliberate fail-closed cleanup is retained: no replacement child is started when an old registered child cannot be verified gone. Linux uses procfs and needs no procps package. No config or SQLite schema changes.

Exact-head CI 33260972583 completed successfully with no failed jobs. Native review artifacts are validated and the PR is land-ready. A refreshed review was requested for the additional startup lifecycle correction.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 10ee252 into main Aug 29, 2026
196 of 197 checks passed
@steipete
steipete deleted the codex/reap-app-server-orphans branch August 29, 2026 15:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 29, 2026
… boot

The reaper landed in #132610 authorizes SIGKILL from pid+pgid+startedAt.
On macOS, startedAt comes from ps lstart and is only second-granular, so
a registered child that dies and has its pid recycled within the same
second could hand its identity to an unrelated process that then gets
killed (group-killed when it is a leader); Linux is already
tick-granular with a boot id. Registration now also records the child's
exact command line (/proc cmdline on Linux, ps -o command= elsewhere)
and the reap loop compares it before entering containment: a mismatch
deletes only the stale row, an unreadable command with a still-matching
identity refuses the spawn fail-closed, and rows written by earlier
unreleased builds keep identity-only reaping via an optional schema
field. Verified against pinned codex 0.150.1 (rust-v0.150.1) that the
app-server never retitles its argv. The regression "never kills a
same-second replacement process running a different command" fails
without the gate.

Also registers a best-effort boot sweep service
(codex-app-server-process-reaper) so orphans from a hard-killed gateway
die at the next startup instead of waiting for the next codex spawn;
the before-spawn fail-closed check remains authoritative. Docs updated.
Follow-up to #132610 from #132621's review findings.
steipete added a commit that referenced this pull request Aug 29, 2026
…nup until next use (#132745)

* fix(codex): gate orphan reaper kills on command identity and sweep at boot

The reaper landed in #132610 authorizes SIGKILL from pid+pgid+startedAt.
On macOS, startedAt comes from ps lstart and is only second-granular, so
a registered child that dies and has its pid recycled within the same
second could hand its identity to an unrelated process that then gets
killed (group-killed when it is a leader); Linux is already
tick-granular with a boot id. Registration now also records the child's
exact command line (/proc cmdline on Linux, ps -o command= elsewhere)
and the reap loop compares it before entering containment: a mismatch
deletes only the stale row, an unreadable command with a still-matching
identity refuses the spawn fail-closed, and rows written by earlier
unreleased builds keep identity-only reaping via an optional schema
field. Verified against pinned codex 0.150.1 (rust-v0.150.1) that the
app-server never retitles its argv. The regression "never kills a
same-second replacement process running a different command" fails
without the gate.

Also registers a best-effort boot sweep service
(codex-app-server-process-reaper) so orphans from a hard-killed gateway
die at the next startup instead of waiting for the next codex spawn;
the before-spawn fail-closed check remains authoritative. Docs updated.
Follow-up to #132610 from #132621's review findings.

* fix(codex): persist only a command fingerprint in reaper registrations

appServer.args is operator-configurable and can carry secrets, and the
spawn-identity precedent (argsFingerprint) deliberately hashes argv.
Durable reaper rows now store a sha256 fingerprint of the observed
command line instead of the raw string; the kill gate reads the live
command fresh and compares digests, and the registration test asserts
raw argv never reaches the durable store. Addresses the ClawSweeper P1
on #132745; the companion final-signal finding is refuted in the PR
thread (identity monotonicity: a post-gate replacement cannot carry the
registered start time, and containment revalidates identity before
every signal).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
* fix(codex): reap orphaned app-servers before reconnect

* style(codex): avoid returning the containment timer handle

* fix(codex): inspect Linux children without requiring procps

* fix(codex): tolerate processes exiting during procfs reads

* test(codex): normalize socket fixture binary frames

* fix(codex): preserve startup errors during process registration
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
…nup until next use (openclaw#132745)

* fix(codex): gate orphan reaper kills on command identity and sweep at boot

The reaper landed in openclaw#132610 authorizes SIGKILL from pid+pgid+startedAt.
On macOS, startedAt comes from ps lstart and is only second-granular, so
a registered child that dies and has its pid recycled within the same
second could hand its identity to an unrelated process that then gets
killed (group-killed when it is a leader); Linux is already
tick-granular with a boot id. Registration now also records the child's
exact command line (/proc cmdline on Linux, ps -o command= elsewhere)
and the reap loop compares it before entering containment: a mismatch
deletes only the stale row, an unreadable command with a still-matching
identity refuses the spawn fail-closed, and rows written by earlier
unreleased builds keep identity-only reaping via an optional schema
field. Verified against pinned codex 0.150.1 (rust-v0.150.1) that the
app-server never retitles its argv. The regression "never kills a
same-second replacement process running a different command" fails
without the gate.

Also registers a best-effort boot sweep service
(codex-app-server-process-reaper) so orphans from a hard-killed gateway
die at the next startup instead of waiting for the next codex spawn;
the before-spawn fail-closed check remains authoritative. Docs updated.
Follow-up to openclaw#132610 from openclaw#132621's review findings.

* fix(codex): persist only a command fingerprint in reaper registrations

appServer.args is operator-configurable and can carry secrets, and the
spawn-identity precedent (argsFingerprint) deliberately hashes argv.
Durable reaper rows now store a sha256 fingerprint of the observed
command line instead of the raw string; the kill gate reads the live
command fresh and compares digests, and the registration test asserts
raw argv never reaches the durable store. Addresses the ClawSweeper P1
on openclaw#132745; the companion final-signal finding is refuted in the PR
thread (identity monotonicity: a post-gate replacement cannot carry the
registered start time, and containment revalidates identity before
every signal).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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