Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(codex): bound pending requests after app-server stdout closes #24600

Mergedjuliusmarmingemerged 4 commits intomain fromrefs/pull/24600/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Codex 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.

FixtureBefore recordingAfter recording
A — stdout EOF, two pending requests, child aliveBoth unresolved over 1000 msBoth fail at 259–260 ms while child lives
B — delayed exit beyond graceExit code 23 eventually fails requestsEOF errors stay stable; late writes reject; child reaped
C — real exit within graceCode 37 and exact PID retainedCode 37 and exact PID retained at ~101 ms
D — healthy scoped shutdownHandshake/RPC succeed; child reapedSame 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. Approvability

      Verdict: Approved at 9607dcb

      Macroscope'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).
    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: c4fa462 · PR result: 9607dcb · Source CI: success

      Scenario 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.

    3. Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      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.ts
      • packages/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

      Layer / File(s)Summary
      Bound termination classification
      packages/effect-codex-app-server/src/protocol.ts, packages/effect-codex-app-server/src/protocol.test.ts
      The 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.
      Priority: Normal

      Estimated 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
        end

      Possibly 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:S

      Suggested reviewers: only21mil, macroscopeapp

      Merge Risk: Minimal · up to 9607d

      The bounded wait and exit-status behavior have no identified issue that needs resolution before merging.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main fix: bounding pending requests after app-server stdout closes.
      Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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
      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge added labelsbugfix

    5. juliusmarminge added labelspr:ready

    6. juliusmarminge merged this7769d70

    7. juliusmarminge closed this

    8. juliusmarminge removed labelspr:ready

Sign in to join this conversation.