fix(server): release Codex sessions after transport termination #20992
main fromrefs/pull/20992/head·opened View on GitHubWhen the Codex app-server is killed, later turns can keep using its failed transport and repeatedly fail during thread resume or creation until T3 restarts.
Expose the protocol's existing termination signal to the Codex adapter and fail its event stream after buffered events drain. The session manager then evicts and cleans up the failed session. Later work opens a replacement and resumes the saved native thread; an ambiguous in-flight submission is not replayed.
Scope and approval#
No prior issue or maintainer approval is claimed. This is submitted under the contribution guide’s exception for a small, focused fix of an obvious bug: once the Codex child process has exited, its terminal transport cannot serve another request, yet the cached adapter session remains available and repeatedly fails until T3 restarts. The production change connects the protocol’s existing termination signal to the session manager’s existing eviction path. It adds no product setting, default, workflow, schema, or automatic turn replay. The larger test diff proves recovery and isolation through the real adapter and session manager.
Acceptance criteria#
- A terminated Codex transport releases its cached provider session; later work reopens a session and resumes the same native thread ID.
- An in-flight submission with an unknown outcome fails without automatic resubmission.
- Other provider instances remain usable, settings are preserved, and failed-session resources are finalized.
Validation#
- 238 scoped tests passed; server and Codex package typechecks passed.
- Two adapter/session-manager recovery tests fail on the unchanged baseline and pass with this patch.
- A separate child-process test verifies termination reporting after SIGKILL.
- Independent review reran all three new cases successfully; no blocking findings.
- Scoped lint reports two pre-existing unused-variable warnings.
The manager tests simulate transport death; SIGKILL is covered separately. This repairs recovery after process death, not the memory growth that may cause a process to be killed.
Implemented with GPT-6.1-Sol through the Codex harness in T3 Code; independently reviewed with GPT-6.1-Sol.
- 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
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
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:
a2bb0ac7-4790-4070-a302-1d2fcd2b5c05
📥 Commits
-
Reviewing files that changed from the base of the PR and between 13aa882c22d584de5388dfce3b3ca413387ba059 and d87cea08929dc085e48350a8eab7e3464903a401.
📒 Files selected for processing: 4
-
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsapps/server/src/orchestration-v2/ProviderSessionManager.test.tspackages/effect-codex-app-server/src/client.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; 9 remain after this review.
-
📝 Walkthrough
-
Codex transport termination failures now reach adapter event-stream consumers. Tests cover termination observation, failed-session removal, continued use of a healthy session, and resumption of a saved native thread.
Changes: Codex transport termination
Layer / File(s) Summary Expose client termination
packages/effect-codex-app-server/src/client.ts,packages/effect-codex-app-server/src/client.test.tsThe client exposes a termination effect that fails with the transport error. A test checks termination observation and failure of a later request after process exit. Forward termination through the adapter
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.tsThe adapter forwards client termination failures to its event queue. The session event stream now propagates queue failures. Test session failure and recovery
apps/server/src/orchestration-v2/ProviderSessionManager.test.tsThe test harness accepts supplied adapters. Codex transport-death tests check session removal, continued availability of a healthy session, and resumption of the saved native thread. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant CodexTransport participant CodexAppServerClient participant CodexAdapterV2 participant ProviderSessionManager CodexTransport->>CodexAppServerClient: Report transport termination CodexAppServerClient->>CodexAdapterV2: Termination effect fails CodexAdapterV2->>CodexAdapterV2: Fail event queue CodexAdapterV2->>ProviderSessionManager: Event stream reports failure ProviderSessionManager->>ProviderSessionManager: Remove failed sessionSuggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
d87ce-
When the Codex app-server process dies, its sessions now fail cleanly and are released instead of hanging on a dead transport. Later work opens a fresh session that resumes the saved thread, and other sessions keep working. No merge-blocking issues were identified. At most, a few in-progress streamed text fragments from the moment of the crash may be lost.
Security architecture risk: 🔵 Low · up to
d87ce-
The change improves recovery after a provider process exits while preserving saved-thread identity and avoiding automatic replay of uncertain work. No new external access or privilege expansion was identified. Rare concurrent cleanup and reopening behavior remains incompletely established.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- observed — The cleanup unit is the failed provider session, which can own multiple attached threads, rather than just the outstanding request. The recovery test verifies that a separate healthy provider instance remains available; it does not establish exhaustive cross-session concurrency coverage.
Trust Boundaries and Controls
- inferred — The new signal carries a transport failure into cleanup, not new request authority. Its consumer constructs the failure using the adapter's existing session identity. The inspected change does not add a caller-supplied cleanup target or bypass request authorization.
Resilience and Maintainability Implications
- observed — Existing cleanup combines a current-runtime check, awaited idle-fiber interruption, and atomic entry removal. Removal can nevertheless retry against the current entry under a reusable session ID, while idle generations restart for replacements. These controls narrow the proposed stale-cleanup race, but inspected evidence does not conclusively settle every overlapping release/reopen schedule.
Hardening Proposals
- proposed — Consider binding asynchronous release decisions to the expected runtime identity through atomic removal, with a targeted transport-failure/reopen interleaving test. This would strengthen cleanup ownership without treating the unconfirmed race as a vulnerability.
-
Pre-merge checks:
4-
Check name Status Explanation 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. Title check The title clearly and concisely describes the primary change: releasing cached Codex sessions after transport termination. Description check The description explains the problem, proposed change, scope exception, acceptance criteria, and focused validation results. It does not use the template's exact "Problem," "Change," and "Verification… Full details: Description check
-
Explanation
The description explains the problem, proposed change, scope exception, acceptance criteria, and focused validation results. It does not use the template's exact "Problem," "Change," and "Verification" headings, but it provides the required information under equivalent sections.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Closing: this is covered by #26188, which landed. Reopen if a needed part is still missing.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
d87cea0Macroscope's review found this PR approvable — This is a narrowly scoped Codex transport-recovery fix that releases dead sessions, preserves buffered events, avoids replaying ambiguous turns, and reopens saved threads through existing manager behavior. The production changes are small and are covered by targeted client and session-manager tests, with no default, schema, deployment, or static-analysis changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).