fix(codex): bound pending requests after app-server stdout closes #24600
main fromrefs/pull/24600/head·merged by juliusmarminge View on GitHubCodex requests can hang indefinitely when app-server stdout closes while its process stays alive. Bound the exit-status wait to 250 ms, then fail all pending requests with the existing input-ended error. Exit status reported within that window retains its code and PID.
Original description by @VendettaGhub
Codex requests could hang indefinitely if the app server closed stdout while its process remained alive. The protocol waited for process exit even though no further response could arrive.
The EOF handler now races the process-exit diagnostic against the existing input-ended error. An already-available exit diagnostic is preserved; otherwise requests fail promptly without adding a timeout or killing the process. When EOF arrives first, the reported error is the input-ended error. This fixes that specific protocol hang, not every long-session hang.
Two focused regressions cover EOF with a still-running process and preservation of an already-known exit error. Both have been checked against broken variants. Redundant assertions were removed, and all 22 protocol tests, package typecheck, targeted lint, and formatting pass. After merging current main, all 22 protocol tests and the package typecheck pass at 6797dee. The affected package is unchanged by that merge; fresh independent Opus and Sol reviews found no actionable defects. No live Codex session was exercised during this takeover; no UI changed.
Original fix by @VendettaGhub in #12777. Maintainer takeover by Claude Opus 5.5 and Claude Fable 5.1 through T3 Code, independently reviewed by Claude Opus 5.5 and GPT-6.1-Sol through the Codex harness.
Takeover#
Original diagnosis and fix by @VendettaGhub in #12777. Rebuilt on current main in an origin branch. Replaced the immediate EOF race with a 250 ms exit-status grace because real stdout EOF precedes Node's exit event and the race lost crash diagnostics. Kept two focused regression tests; no scratch artifacts are committed.
Evidence#
Fixture matrix · Runtime index, transcripts, driver, stub and source snapshots
Linux x86_64, Node v24.22.1, Effect 4.0.5. Real PATH stub through production protocol client, ChildProcessSpawner and stdio/exit-status mapping. Timestamped transcripts are the recordings for this server-only change. Before 3cc31ed; after 23cee43.
| Fixture | Before recording | After recording |
|---|---|---|
| A — stdout EOF, two pending requests, child alive | Both unresolved over 1000 ms | Both fail at 259–260 ms while child lives |
| B — delayed exit beyond grace | Exit code 23 eventually fails requests | EOF errors stay stable; late writes reject; child reaped |
| C — real exit within grace | Code 37 and exact PID retained | Code 37 and exact PID retained at ~101 ms |
| D — healthy scoped shutdown | Handshake/RPC succeed; child reaped | Same success and cleanup |
What else changed: no render paths changed. EOF classification is delayed by at most 250 ms when an exit effect exists; exit diagnostics arriving after the cutoff are replaced by the input-ended error. No process is killed by the fix.
Verification log
- Main checked for superseding fix; hang still present.
- Protocol tests: 15 → 17 in one existing file. Package: 28 pass across 5 files. Focused lint/typecheck pass.
- Regression reversal: main hangs; immediate-race version fails both timing guards; revised implementation passes.
- Review round 1: Sol MERGE, Opus FIX_FIRST (lost real exit code). Fixed with bounded grace.
- Review round 2: fresh Sol and Opus both MERGE; no remaining concrete findings.
- Proof audit: SUFFICIENT: all four rows, independent replay.
- Final main merge: 7fd2e09 merged as 9607dcb. Affected package byte-identical to captured head; final scoped tests, lint and typecheck pass.
- CI: pending after publication; no merge performed.
- Unverified: actual Codex binary internals, signal-crash variant, other operating systems. No UI/network surfaces changed; browser captures do not apply.
- Models/harness: Claude Opus 5.5 via Claude Agent for tests/implementation and review B; GPT-6.1-Sol via Codex for lead, review A, evidence and proof audits in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
9607dcbMacroscope's review found this PR approvable — This is a narrowly scoped protocol bug fix that bounds pending-request termination after stdout closes while preserving promptly reported process-exit diagnostics. The accompanying regression tests cover both the timeout and exit-status paths, with no product-default or static-analysis configuration changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB +7 B (+0.1%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +7 B (+0.6%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
c4fa462· PR result:9607dcb· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: takeover/pr-12777
- File: .coderabbit.config.ts
- Commit: 9607dcb
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
1552e941-19eb-49d5-a9fc-3bcbd32b9dc1
Commits-
Reviewing files that changed from the base of the PR and between c4fa4629eb645b95aae2beef56c70f705b736049 and 9607dcb499766a3af795b91521d073850aaff4e2.
Files selected for processing: 2-
packages/effect-codex-app-server/src/protocol.test.tspackages/effect-codex-app-server/src/protocol.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
-
Walkthrough
-
After stdout closes, the protocol waits up to 250 ms for a termination result. If no result arrives, it uses the input-stream-ended error. Tests cover both the timeout and a process-exit error received within the grace period.
Changes: Termination handling
Priority:Layer / File(s) Summary Bound termination classification
packages/effect-codex-app-server/src/protocol.ts,packages/effect-codex-app-server/src/protocol.test.tsThe protocol waits up to 250 ms for the termination effect after stdout closes. If it does not complete in that time, the protocol uses CodexAppServerInputStreamEndedError. Tests check the timeout boundary and a process-exit error received after 100 ms. NormalEstimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Sequence Diagram(s)#
sequenceDiagram participant Stdout participant Protocol participant TerminationError participant PendingRequest Stdout->>Protocol: closes Protocol->>TerminationError: wait up to 250 ms alt termination result arrives within 250 ms TerminationError-->>Protocol: process-exit result Protocol->>PendingRequest: classify using termination result else no result arrives within 250 ms Protocol->>PendingRequest: fail with input-stream-ended error endPossibly related issues
- pingdotgg/t3code#23720 — The issue describes failures after the shared Codex app-server is killed. This change updates termination handling after stdout closes.
- pingdotgg/t3code#24300 — The issue describes requests that remain pending when the app-server process dies or becomes unusable. This change bounds pending-request failure after stdout reaches EOF.
Possibly related PRs
- pingdotgg/t3code#23938 — It changes termination-error handling that can run as the effect this PR waits for after stdout closes.
Suggested labels:
size:SSuggested reviewers:
only21mil,macroscopeapp
Merge Risk:
Minimal · up to9607d-
The bounded wait and exit-status behavior have no identified issue that needs resolution before merging.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main fix: bounding pending requests after app-server stdout closes. Description check The description explains the problem, implementation, scope, verification results, evidence, limitations, and review context. It does not use the template headings exactly, and explicit maintainer app… 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 explains the problem, implementation, scope, verification results, evidence, limitations, and review context. It does not use the template headings exactly, and explicit maintainer approval is not clearly stated, but the required information is mostly present.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:ready
juliusmarminge merged this7769d70
juliusmarminge closed this
juliusmarminge removed labelspr:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes