paseo icon indicating copy to clipboard operation
paseo copied to clipboard

bug: Codex agent permanently stuck in error with "Failed to resume Codex thread ... Codex app-server client is closed" (0.2.5 stable) — needs manual paseo agent reload

Open kouyichi opened this issue 3 months ago • 1 comments

What's broken

A Codex agent whose codex app-server process dies becomes permanently stuck in error with:

Failed to resume Codex thread <threadId>: Codex app-server client is closed

Every subsequent prompt/resume fails identically. The only recovery is manual paseo agent reload <id>. We hit this 3 times in 3 days (2026-08-05, 08-06, 08-07) on paseo CLI 0.2.5 (latest stable on npm) / Linux, each time requiring a manual reload.

Stack (from daemon log, paseo 0.2.5)

Error: Failed to resume Codex thread 019fb866-...: Codex app-server client is closed
    at CodexAppServerAgentSession.ensureThreadLoaded (codex-app-server-agent.js:2675)
    at CodexAppServerAgentSession.startTurn (codex-app-server-agent.js:2864)
    at AgentManager.streamForwarder (agent-manager.js:1301)
caused by: Error: Codex app-server client is closed
    at CodexAppServerClient.request (codex/app-server-transport.js:136)
    at CodexAppServerAgentSession.ensureThreadLoaded (codex-app-server-agent.js:2650)

Verified root cause (0.2.5)

  1. CodexAppServerClient (app-server-transport.js) sets this.disposed = true on child process exit (line ~125).
  2. The session side has no termination handler in 0.2.5: codex-app-server-agent.js contains no unexpectedTerminationHandler/handleUnexpectedTermination at all, and connect() is simply if (this.connected) return;.
  3. So when the app-server dies (crash, OOM, or killed during an account re-login cleanup — our trigger was a stale app-server holding an old OAuth session, after codex logout + login with a different account; turns first failed with "Your access token could not be refreshed..."), the session keeps connected === true and keeps referencing the disposed transport.
  4. Next startTurn → connect() early-returns → ensureThreadLoaded() → client.request("thread/loaded/list") → Promise.reject(new Error("Codex app-server client is closed")) (transport.js:135-136). Agent lands in error forever.

Fixed on main, not in any stable release

Commit c8de1b1 / PR #2757 "Fail active agents when their provider process exits" (2026-08-01) added setUnexpectedTerminationHandler to the transport and handleUnexpectedTermination to the session (sets connected = false, so the next connect() re-spawns the app-server and resumes the thread). Regression coverage exists in codex-app-server-agent.process-exit.test.ts ("idle Codex app-server exit reconnects without publishing a failed turn").

npm latest stable is still 0.2.5 (0.3.0-beta.2 is the only build carrying the fix). All stable users are affected.

Expected behavior

An agent whose app-server died should transparently reconnect on the next turn (or at least not block forever on a disposed transport), instead of requiring manual paseo agent reload.

Request

  • Ship the fix: publish 0.2.6 (or promote 0.3.0 stable) containing #2757, or backport it to the 0.2.x line.
  • Consider a regression test for the stable-line behavior (app-server exit while idle → next turn reconnects) since 0.2.5 demonstrably lacks it.

Optional hardening for main (not required — the #2757 architecture already covers the common case): connect() only short-circuits on this.connected without checking the client is still usable; a get isDisposed() on CodexAppServerClient + if (this.connected && !this.client?.isDisposed()) return; would close any path where a disposed transport is referenced with connected left true.

Environment

  • paseo 0.2.5 (CLI + daemon, installed via npm), Linux x86_64
  • Provider: codex (gpt-5.6-sol) via codex app-server --enable goals

Related

  • #2761 — stale agent state after runtime disappears (same family)
  • #2468 — resume failure → endless retry
  • #947 — resume failures surfaced as explicit errors (the surfacing half; recovery was missing in 0.2.x)

kouyichi avatar Aug 07 '26 10:08 kouyichi

Thanks for the report. Fixed in v0.3.0 via #2757. Reopen if you still see it after updating.

paseo-bot avatar Aug 08 '26 16:08 paseo-bot