fix(server): start a new Codex app-server after the old one exits #21013
main fromrefs/pull/21013/head·opened View on GitHubProblem#
If the shared Codex app-server process dies, for example when a kernel OOM kill hits its agent scope, Codex stops working for every thread until the T3 server restarts. Each later turn fails within milliseconds with ProviderAdapterEnsureThreadError, caused by CodexAppServerTransportError: ... 'read-process-exit-status' failed (Process interrupted due to receipt of signal: 'SIGKILL').
The Codex client records the exit and fails every later request with it. But the adapter's session event stream never ends, so the session manager keeps the dead session live and hands it to every new turn.
Seen on Linux. A global OOM killed codex app-server in its t3code-codex-*.scope, and every Codex turn failed for about 2.5 hours afterwards.
Change#
- The Codex app-server client exposes
awaitTermination, which completes when its transport ends (process exit or closed output). It uses the protocol's existingonTerminationhook. - The Codex adapter fails its session event stream with
ProviderAdapterEventStreamErrorwhen the client terminates. The session manager already releases a session whose provider stream fails (markedruntime_error), so the next turn opens a new session and spawns a new app-server.
Claude, the ACP providers and Pi already recover from a dead process; Codex was the only adapter that never reported it. The systemd agent scope launcher needs no change, because unit names get a new random suffix on each spawn.
Scope and approval#
A small, focused fix for an obvious bug: a crashed provider process should not disable that provider until the server restarts. The fix adds one field to the Codex client and one watcher in the Codex adapter, and reuses the session manager's existing release path for failed provider streams. It does not change product behavior, contracts or other providers.
Verification#
- New test
ProviderSessionManagerV2 starts a new Codex app-server after the old one exits(ProviderSessionManager.test.ts). It drives the real session manager and Codex adapter against a replayed app-server that exits after its first thread starts.- Before the fix, the second
ensureThreadfailed withProviderAdapterEnsureThreadErrorcaused byCodexAppServerProcessExitedError, the same failure path as production. As committed, the test times out on the old code because the session never closes. - After the fix it passes, and two app-servers were started.
- Before the fix, the second
vp test run:ProviderSessionManager.test.ts66 passed;CodexAdapterV2.test.ts168 passed;effect-codex-app-server36 passed; Codex replay integration tests (OrchestratorReplayFixtures144,OrchestratorReplayRecovery4,ThreadMergeBack4,ThreadFork6) all passed.tsc-rs --noEmitpasses forapps/serverandpackages/effect-codex-app-server.- Not checked: a real OOM kill of a live
codex app-serverend to end.
Made with Claude Opus 5.5 in Claude Code (via T3 Code).
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
d0cd6b9Macroscope's review found this PR approvable — This is a focused Codex crash-recovery bug fix using existing termination and session-release paths, with normal processing unchanged and integration coverage for restarting after process exit. The remaining changes are test-only or additive internal plumbing, with no defaults, schema, security, billing, deployment, or static-analysis impact.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
deeeaffc-8f18-4577-ac58-eee8889fa568
📥 Commits
-
Reviewing files that changed from the base of the PR and between 13aa882c22d584de5388dfce3b3ca413387ba059 and d0cd6b98723dfb553a00d2db231692e451e36d7d.
📒 Files selected for processing: 3
-
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsapps/server/src/orchestration-v2/ProviderSessionManager.test.tspackages/effect-codex-app-server/src/client.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
📝 Walkthrough
-
The Codex app-server client exposes an effect that completes when the server terminates. The Codex adapter uses that signal to fail the session event queue. A replay-backed test checks that thread creation uses a new app-server instance after termination.
Changes: Codex app-server termination
Layer / File(s) Summary Expose app-server termination
packages/effect-codex-app-server/src/client.tsThe client records the transport termination error and exposes awaitTerminationto await it.Propagate termination to the event queue
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsA session-scoped fiber waits for app-server termination, then fails the event queue with a provider event stream error. Verify thread creation across server lifetimes
apps/server/src/orchestration-v2/ProviderSessionManager.test.tsA replay-backed test checks native thread IDs across two app-server lifetimes and verifies that the client factory opened two instances. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant CodexAppServerTransport participant CodexAppServerClient participant CodexAdapterV2 participant EventQueue CodexAppServerTransport->>CodexAppServerClient: onTermination(error) CodexAppServerClient-->>CodexAdapterV2: awaitTermination returns error CodexAdapterV2->>EventQueue: fail with provider event stream errorSuggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
d0cd6-
The recovery test exercises a new Codex app-server after the old one exits. No confirmed issue remains that should block merging.
Security architecture risk: 🔵 Low · up to
d0cd6-
The change restores recovery within the existing provider-session boundary without adding a new external command or privilege path. Remaining uncertainty concerns concurrent teardown and replacement, which the sequential recovery test does not establish.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- observed — The failure domain is shared: threads within a Codex provider session use one app-server, and its termination invalidates that session's event stream rather than only the initiating thread.
Trust Boundaries and Controls
- observed — Termination is handled once by the protocol and stored in a client Deferred. Observation therefore does not depend on the adapter watcher already being waiting when termination occurs. The manager also checks the captured runtime identity before beginning failure handling, although that check does not make the entire release transition atomic.
Resilience and Maintainability Implications
- observed — The newly reached release path includes existing MCP credential cleanup. Cleanup checks credential reservations and other live-session ownership before clearing credentials, so replacement ownership is explicitly considered rather than blindly revoked.
-
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary fix: starting a new Codex app-server after the previous process exits. Description check The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the failure, implementation, scope, focused test coverage, reported results, and the unver… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Description check
-
Explanation
The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the failure, implementation, scope, focused test coverage, reported results, and the unverified real OOM scenario.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Closing: current main already covers this as of b88da91397. If you still see it on a build that includes that commit, reply and we'll reopen.
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes