Repository navigation
fix(codex): await app-server cleanup when startup rejects - #157229
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 24, 2026, 8:43 AM ET / 12:43 UTC (Revision 2). ClawSweeper reviewWhat this changesThe Codex plugin waits for app-server child cleanup before failed shared or isolated startup returns, with lifecycle tests and updated runtime documentation. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open. Current main still has the reported early-return cleanup path, but the proposed fix can leave a timed-out or canceled startup pending indefinitely when child-process registration stalls. Priority: P1 Review scores
Verification
How this fits togetherThe Codex plugin starts an app-server child for agent runs and records its process identity before handing out a client. Failed acquisition should close the child and return an error to the waiting agent run. flowchart LR
A[Agent run] --> B[Codex client acquisition]
B --> C[Spawn app-server child]
C --> D[Register child process]
D --> E{Startup succeeds?}
E -->|Yes| F[Ready client]
E -->|No| G[Close child and report error]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +23, Tests +90, Docs +6. Total +119 across 5 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep child custody with the transport owner after abort, close the spawned process promptly, and let the caller settle after process exit while a service-owned task completes any late registration cleanup. Do we have a high-confidence way to reproduce the issue? Yes, at source level: hold the post-spawn registration write pending, then abort or expire acquisition. This read-only review did not execute that fault. Is this the best way to solve the issue? No. Joining physical cleanup addresses the orphan symptom, but acquisition must not await the unbounded registration write after its deadline. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against da5e443fe5bb. LabelsLabel changes: No label changes. Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Startup validation observes the catalog home through real filesystem I/O. Advancing the fake clock cannot establish that stdin teardown has started, so the shared and isolated cleanup checks could race that lookup. Subscribe to the existing stdin close event before acquisition and await it while retaining the separate assertion that acquisition stays pending until the synthetic process exits. Preserve all eight lifecycle variants. The original 23-file shard reproduced the premature assertion on main. Validation: 20 standalone runs (132 tests each), three original-shard runs (864 tests each), scoped lint/format, and independent review passed. Fixes the fixture introduced in #157229.
Startup validation observes the catalog home through real filesystem I/O. Advancing the fake clock cannot establish that stdin teardown has started, so the shared and isolated cleanup checks could race that lookup. Subscribe to the existing stdin close event before acquisition and await it while retaining the separate assertion that acquisition stays pending until the synthetic process exits. Preserve all eight lifecycle variants. The original 23-file shard reproduced the premature assertion on main. Validation: 20 standalone runs (132 tests each), three original-shard runs (864 tests each), scoped lint/format, and independent review passed. Fixes the fixture introduced in openclaw#157229.
Refs #157107. Thanks @mmartoccia for the report.
What Problem This Solves
Fixes Codex startup failures returning before their app-server child has exited. The reporter observed 47 orphaned app-server processes in 30 minutes while an authored provider API-key SecretRef pointed to an unset environment variable.
User Impact
Failed, canceled, and timed-out startup now waits for its spawned transport to finish cleanup. A healthy shared caller keeps its client. Cleanup can extend beyond the startup deadline while process registration settles. No configuration, dependency, schema, or migration changes are required.
Why This Change Was Made
createStdioTransport()spawns the child atextensions/codex/src/app-server/transport-stdio.ts:169. Inshared-client.ts, failed initialization/authentication and late transport creation scheduledcloseAndWait()without awaiting it; the final abandoned shared claimant also retired the child through the non-awaitedclose()path.The existing shared-client lifecycle now records the transport-creation promise and joins physical cleanup before returning the failure. Work that has not begun transport creation remains independently cancellable. Spawn ownership stays in
createStdioTransport; cleanup ownership stays inshared-client/shared-client-lifecycle. The ordering change is failure-after-cleanup; secret resolution and provider retry policy are unchanged. The exact SecretRef trigger remains the reporter's observed reproduction; the regression independently reproduces and fixes the same early-rejection lifecycle defect.Sibling inspection found no equivalent leak: Claude CLI prepares credentials before spawning and awaits transport exit in
finally; ACPX catalog inspection receives its generation's AbortSignal, and its runtime closes and awaits the helper during abort/disposal.The sibling Codex source was personally inspected at commit
41e22fee981a63b3698df7ed36bad393cda24715:codex-rs/app-server-transport/src/transport/stdio.rs:71–80turns stdin EOF into connection closure;codex-rs/app-server/src/lib.rs:1036exits the stdio connection loop, and:1187awaits thread shutdown. OpenClaw retains its existing bounded force-kill fallback.Evidence
pnpm test extensions/codex/src/app-server/shared-client.test.ts --maxWorkers=1. Wall times: 22.26 / 21.62 / 20.26 seconds; test execution accounts for about 2–2.5 seconds per run, with most time in transformation/imports.pnpm check:changed --base ba65d492cf3e3dd8e49999b30133c09684eaf7eapassed on the exact committed head, including extension/test typechecks, dead-code scans, extension lint, and runtime import cycles. Its initial unused import and obsolete export findings were fixed.--mode branch --base origin/mainreview: scoped-clean through P2 on1451edb1ac1a4a4f52dd7f83f284fa8b11380fe4.tbx_01m39edvjwj8t2seepv6qj2vg3for tests (provisioning run);tbx_01m39gbz7bgct6h22291g7k3n8for final checks (exact-commit provisioning run). Proof results come from remote command exit status; stopping a lease can cancel its provisioning workflow.