fix(agent): return failed turns when Codex app-server exits during RPC writes - #83129
Open
fangliquanflq wants to merge 2 commits into
Open
fix(agent): return failed turns when Codex app-server exits during RPC writes#83129fangliquanflq wants to merge 2 commits into
fangliquanflq wants to merge 2 commits into
Conversation
This was referenced Aug 18, 2026
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Codex turns and native compaction now return structured failures when the app-server exits during an RPC write instead of aborting the enclosing conversation with a runtime exception. The failed session is marked for retirement, allowing a later turn to start a clean child, while unrelated runtime errors remain visible.
Symptom
If the Codex child exits after startup succeeds but before
turn/start,thread/compact/start, or an approval response reaches stdin, the write exception can escaperun_turn()orcompact_thread()instead of returning a failedTurnResult.Impact
Affected Codex users can lose the current conversation or compaction call outside the normal structured error path. A dead session may also remain eligible for reuse instead of being retired. Frequency and broader blast radius were not measured.
Bug Cause
Trigger:
agent/transports/codex_app_server.pyinCodexAppServerClient._send()when stdin is closed or a write raisesBrokenPipeErrororValueError.Causal chain:
Why it is wrong: A process can exit between any liveness check and the next write. Transport loss is an expected lifecycle race, but plain
RuntimeErrorcannot be handled narrowly without also hiding unrelated programming failures.Working sibling / contrast: RPC-domain errors and timeouts already become structured session results. Steering and interruption already treat expected control-path failures as non-fatal.
Ruled out: An extra
is_alive()check cannot remove the check-to-write race. Catching all runtime exceptions would mask unrelated defects.Fix
CodexAppServerTransportErrorfor closed or broken child stdin writes.should_retire=True.Related Issue
Fixes #83127
Type of Change
Changes Made
agent/transports/codex_app_server.py- define the transport write exception and clean pending request state after failed sends.agent/transports/codex_app_server_session.py- handle transport loss at turn, compaction, approval-response, steering, and interrupt boundaries.tests/agent/transports/test_codex_app_server_runtime.py- cover typed closed-stdin and pending cleanup behavior.tests/agent/transports/test_codex_app_server_session.py- cover structured retirement, redaction, sibling control paths, and unrelated runtime errors.How to Test
Result: 65 passed.
Checklist