fix(codex): a failed write to the app-server no longer leaves requests hanging #27924
main fromrefs/pull/27924/head·merged by maria-rcks View on GitHubProblem#
The Codex protocol's outgoing writer (packages/effect-codex-app-server/src/protocol.ts) runs in a forked fiber with no error handler. If a write to the app-server's stdin fails while its stdout stays open (for example EPIPE after the app-server closes stdin), the writer fiber dies silently and nothing marks the transport terminated:
- Pending requests never resolve.
- Later requests are accepted into the unbounded outgoing queue with no writer behind it, so they wait forever too.
onTerminationnever fires, soclient.awaitTerminationnever fails and the adapter keeps using the shared Codex session. Codex runs on that instance stay stuck until T3 restarts.
The read side already routes its failures through handleTermination, and the ACP transport already reports writer failures (packages/effect-acp/src/protocol.ts). The Codex writer is the one path without that handling.
Change#
Catch writer failures and pass them to the existing handleTermination as a CodexAppServerTransportError with a new write-output-stream operation. This reuses the read-side behavior: pending requests fail with that error, new requests are rejected immediately, and the client reports termination, so the adapter's existing termination path retires the session.
Scope and approval#
This is a small, focused fix for an obvious bug: a background writer whose failure goes unhandled and leaves requests waiting with no timeout. It adds one catch on the writer, one new literal for the error's operation, and one regression test. Behavior is unchanged when writes succeed, and nothing changes in contracts, clients, or the UI.
Related: #24300 reports requests to a dead shared Codex app-server going unanswered. This PR closes one path to that symptom. I have not established that it causes #24300, and it does not address the backlog case described there. Open PRs #18764, #20992 and #25123 work in the same area (process-exit detection, session release, request deadlines), but none of them handles a failed write. With #25123 alone, a failed write would still leave thread and turn starts waiting for its two-minute deadline.
Verification#
I found this by reading the transport while investigating stalled Codex sessions on Linux. I then reproduced it with the test and the subprocess check below. I have not tied it to a specific field incident.
- Regression test (
fails pending requests when a write fails while input stays openinprotocol.test.ts): onmain, termination is never reported and the test times out after 5 s. With this change it passes. It checks that termination carries the write failure, and that both the pending request and a later request fail with that same error. vp run check:changedat the PR head, in the repo dev container (Linux, Node 26.13.0): format, lint, both knip passes, typecheck of the 4 affected packages, and tests (21 in 2 files) all pass.src/protocol.test.ts,src/client.test.tsandsrc/_internalin the package pass (42 tests).- Runtime check with a real child process. The child closes its stdin and stays alive with stdout open. It is driven through
CodexClient.layerChildProcesswith aninitializerequest:
main
fixture alive with stdout open: true
initialize: still pending when the probe gave up after 10 s
client termination reported: none
this branch
fixture alive with stdout open: true
write cause: EPIPE
initialize failed after 16 ms: CodexAppServerTransportError, operation=write-output-stream
client termination reported: CodexAppServerTransportError (same error as the request)
Not checked: pipe behavior on Windows and macOS, a real codex app-server closing its stdin (the check used a stand-in process), and the full test suites, which CI runs.
GPT-6.1-Sol through the Codex harness found the defect and wrote the first fix. Claude Opus 5.5 through Claude Code ported it to main, reduced it and verified it. Both were orchestrated in T3 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
b059eacMacroscope's review found this PR approvable — Failed writes now trigger the existing transport-termination cleanup, so pending and subsequent requests fail instead of hanging. Successful operation is unchanged, and reported regression and subprocess checks support the limited failure-path change.
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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: d92c437
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f8787c56-c1f8-47c1-a587-3ad5b1aa2e3b
Commits-
Reviewing files that changed from the base of the PR and between d92c437baa19409f99416a44f748f148f4317c65 and b059eacb3b4aaf60472d9a051f779282685df9a3.
Files selected for processing: 3-
packages/effect-codex-app-server/src/errors.tspackages/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; 9 remain after this review.
-
Walkthrough
-
The outgoing stdout stream now reports write failures as transport termination errors with operation
write-output-stream. Tests verify that the error preserves the original cause and fails both pending and subsequent requests.Changes: Stdout write failure handling
Layer / File(s) Summary Report and verify stdout write failures
packages/effect-codex-app-server/src/errors.ts,packages/effect-codex-app-server/src/protocol.ts,packages/effect-codex-app-server/src/protocol.test.tsThe transport-operation type includes write-output-stream. The outgoing stream passes stdout write failures to termination handling as transport errors. The test verifies that pending and subsequent requests fail with the same termination error, which retains the original cause.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
- pingdotgg/t3code#22422: The issue concerns termination that leaves work pending or unreported. This change tests that stdout write failure termination fails pending requests.
Possibly related PRs
- pingdotgg/t3code#18764: Propagates protocol termination to the client and adapter; this change routes stdout write failures into the termination path.
- pingdotgg/t3code#21322: Forwards client termination to the Codex adapter; this change reports stdout write failure through termination handling.
- pingdotgg/t3code#26188: Exposes transport termination after app-server exit; this change adds stdout write failure as another termination cause.
Suggested labels:
bugfixSuggested reviewers:
juliusmarminge,only21mil
Merge Risk:
Minimal · up tob059e-
Write failures are routed through termination handling. No merge-blocking issue was identified.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary fix: failed app-server writes no longer leave requests hanging. It uses a suitable conventional commit format. 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. Description check The description includes all required sections. It clearly explains the problem, the change, scope justification, related issue context, focused regression coverage, runtime verification, test results… Full details: Description check
-
Explanation
The description includes all required sections. It clearly explains the problem, the change, scope justification, related issue context, focused regression coverage, runtime verification, test results, and known limitations.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified as-is at
b059eacb3b4aaf60472d9a051f779282685df9a3on linux. no code changes or pushes.used repo Playwright with
/usr/bin/google-chrome, the real dev web client, and real Codexgpt-6.1-solturns through the local proxy. created the project and thread through the ui, pointing at the real git checkout/home/user/main. ran one dev server at a time with separate empty state directories andvp iin each checkout.reproduced first on
github/mainat54c5f25249: a normal turn returnedMAIN_BASELINE_OK. then, using ptrace on only the dev server's actual codex app-server, invokedshutdown(0, SHUT_RD)and held the process stopped so stdout stayed open. submittingWRITE_FAILURE_PROBEleft the thread working for at least 62 seconds without an error. this injects the actual stdin write failure without a stand-in provider or transport.repeated the same prompts and fault on the exact pr head. the ui transitioned to failed, and the server reported
CodexAppServerTransportError, operationwrite-output-stream, caused bywrite EPIPE. the dead session/process was retired. without restarting t3, the next turn returnedRECOVERY_OKfrom a replacement codex process. a further turn successfully ran a shell tool to read the project's git sha and package name, then returnedTOOL_ROUNDTRIP_OK.short runtime transcript:
main: 54c5f25249 real codex pid=21066; shutdown(stdin, SHUT_RD)=0; stdout open next turn: still working at 62s; no terminal provider error pr: b059eacb3b4aaf60472d9a051f779282685df9a3 real codex pid=25708; shutdown(stdin, SHUT_RD)=0; stdout open 21:44:44.904 provider turn start failed: write-output-stream / write EPIPE 21:44:44.913 provider-session-runtime-failed failed turn visible in web client; dead pid retired same running t3 server, replacement codex pid=26900 next turn: RECOVERY_OK shell-tool roundtrip: TOOL_ROUNDTRIP_OKblacksmith checks passed:
vp test run packages/effect-codex-app-server/src/protocol.test.ts packages/effect-codex-app-server/src/client.test.ts(24 tests), andvp run check:changed d92c437baa19409f99416a44f748f148f4317c65(format, lint, both knip passes, four package typechecks, 21 tests). the snapshot initially lacked ancestry; fetching the exact head and base repaired that setup. all 31 reported ci checks were successful.main, same write-failure prompt remains pending:

pr, same write-failure prompt becomes a terminal error:

recording of submitting the failed write on the pr:

same-thread recovery and the subsequent shell-tool roundtrip:

Not verified#
native ios/android clients, the electron shell, macos/windows pipe behavior, and remote/relay/tunnel connections were not exercised on this linux vm. the fault was deliberately injected into a real codex process; i did not establish a naturally occurring codex stdin closure or a cause for any reported production incident. these captures prove failure handling and recovery, not a performance comparison.
maria-rcks merged this34cfd24
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes