Repository navigation
fix(codex): session stops responding after Codex unloads a thread with background terminals - #166693
Conversation
Codex unloads an idle thread with no subscribers by clearing its listener before shutdown, so background terminals end without an item/completed the OpenClaw connection can observe. The admission kept its shared app-server client lease and live-thread protection forever, which later prevented a retired client from closing. Treat thread/closed, thread/archived, and thread/deleted as the final receipt for every native command on that thread. Co-Authored-By: Claude Opus 5.5 <[email protected]>
releaseCodexBoundLiveThread waits for a retired app-server client to exit before a writer handoff. Any other lease can keep that client alive indefinitely, and the wait ran under the thread mutation queue and binding lease without observing cancellation. One pinned client wedged every later turn for the session, even after the run was aborted or timed out. Race the exit wait with the lifecycle signal. Cancellation still never proceeds to a write; it only releases the queue and lease so the next attempt can retry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Startup reused the whole-turn timeout, so an interactive turn (48h default) could hang silently in app-server startup for hours. Cap startup at ten app-server request timeouts (10 minutes by default) when that is shorter than the turn budget; observed startups take seconds to a few minutes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 2:21 PM ET / 18:21 UTC. ClawSweeper reviewWhat this changesThe Codex plugin releases background-command leases when their thread closes, makes retired-client handoffs cancellable, and bounds startup independently of long turn budgets. Merge readiness✅ Ready for maintainer review This focused repair remains necessary on current main. No concrete introduced correctness or security defect was found. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s Codex plugin sends agent turns to a Codex app-server and retains client leases while native background commands remain active. Thread lifecycle receipts and cancellation determine when those resources can be released so later session turns can proceed. flowchart TD
A[Session message] --> B[Codex plugin startup]
B --> C[Thread ownership handoff]
C --> D[Codex app-server]
D --> E[Background command leases]
D --> F[Thread lifecycle receipts]
F --> E
E --> G[Client release and later turns]
B --> H[Bounded timeout or cancellation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +49, Tests +73. Total +122 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep lease settlement and cancellable handoff in the existing Codex lifecycle owners, with startup bounded separately from turn execution. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the path: retain background-command leases, unload their thread, retire the client, then attempt a handoff that waits for its exit. The reported live diagnosis supports this mechanism; this review did not execute it. Is this the best way to solve the issue? Yes, the patch repairs the existing resource owners and reuses the shared abort helper while preserving concrete-process settlement and guarded writes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 16095df1d750. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…h background terminals (openclaw#166693) * fix(codex): settle background commands when Codex closes their thread Codex unloads an idle thread with no subscribers by clearing its listener before shutdown, so background terminals end without an item/completed the OpenClaw connection can observe. The admission kept its shared app-server client lease and live-thread protection forever, which later prevented a retired client from closing. Treat thread/closed, thread/archived, and thread/deleted as the final receipt for every native command on that thread. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codex): let cancellation end a retired-owner exit wait releaseCodexBoundLiveThread waits for a retired app-server client to exit before a writer handoff. Any other lease can keep that client alive indefinitely, and the wait ran under the thread mutation queue and binding lease without observing cancellation. One pinned client wedged every later turn for the session, even after the run was aborted or timed out. Race the exit wait with the lifecycle signal. Cancellation still never proceeds to a write; it only releases the queue and lease so the next attempt can retry. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codex): bound app-server startup independently of the turn budget Startup reused the whole-turn timeout, so an interactive turn (48h default) could hang silently in app-server startup for hours. Cap startup at ten app-server request timeouts (10 minutes by default) when that is shorter than the turn budget; observed startups take seconds to a few minutes. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…h background terminals (#166693) * fix(codex): settle background commands when Codex closes their thread Codex unloads an idle thread with no subscribers by clearing its listener before shutdown, so background terminals end without an item/completed the OpenClaw connection can observe. The admission kept its shared app-server client lease and live-thread protection forever, which later prevented a retired client from closing. Treat thread/closed, thread/archived, and thread/deleted as the final receipt for every native command on that thread. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codex): let cancellation end a retired-owner exit wait releaseCodexBoundLiveThread waits for a retired app-server client to exit before a writer handoff. Any other lease can keep that client alive indefinitely, and the wait ran under the thread mutation queue and binding lease without observing cancellation. One pinned client wedged every later turn for the session, even after the run was aborted or timed out. Race the exit wait with the lifecycle signal. Cancellation still never proceeds to a write; it only releases the queue and lease so the next attempt can retry. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(codex): bound app-server startup independently of the turn budget Startup reused the whole-turn timeout, so an interactive turn (48h default) could hang silently in app-server startup for hours. Cap startup at ten app-server request timeouts (10 minutes by default) when that is shorter than the turn budget; observed startups take seconds to a few minutes. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 94fc081)
What Problem This Solves
Fixes: a Codex-backed session stops responding to every message after Codex unloads an earlier thread of that session that had started background terminals.
User Impact
User impact: a session no longer hangs indefinitely after a thread rotation or idle unload. If startup still cannot finish, the turn fails after a bounded wait (10 minutes with the default
requestTimeoutMs) instead of waiting up to the 48-hour turn budget.Why This Change Was Made
A live Gateway's main session hung for 13 hours. A heap snapshot of the stuck process showed this chain:
item/completed. Codex unloads an idle thread with no subscribers by clearing the thread listener, shutting the thread down (which ends its background terminals), and then broadcastingthread/closed(codex-rs/app-server/src/request_processors/thread_lifecycle.rs,unload_thread_without_subscribers). Theitem/completedevents are written to the rollout after the listener is gone, so the connection never receives them.CodexNativeProcessClientignoredthread/closed, and four leases leaked on one app-server.releaseCodexBoundLiveThreadwaited for the retired app-server to exit before handing the thread to a new client. The wait ignored cancellation and ran while holding the thread mutation queue and the binding lease, so every later turn for the session queued behind it.This PR makes three changes:
CodexNativeProcessClienttreatsthread/closed,thread/archived, andthread/deletedas the final receipt for every native command on that thread. This releases the client lease and live-thread protection.releaseCodexBoundLiveThreadraces the retired-owner exit wait with the lifecycle abort signal. Cancellation never continues to a write. It only releases the queue and lease so a later attempt can retry.resolveCodexStartupTimeoutMscaps startup at ten app-server request timeouts when that is shorter than the turn budget. Observed startups take seconds to a few minutes.Evidence
native-process-authority.test.ts: a confirmed background command is settled bythread/closed. Before the fix the source authority was never released.pnpm test extensions/codex/src/app-server/native-process-authority.test.ts --maxWorkers=1: 13.6 s wall, 3 ms of test time.shared-client.test.ts, "lets cancellation end a writer handoff to a retired owner that other leases keep alive": before the fix the handoff stayed pending after abort. 16.4 s wall when run alone (module load), 20 ms of test time.attempt-timeouts.test.ts: startup bound for a 48-hour turn budget with a 60 s request timeout is 600 s. Under 1 ms of test time.shared-client.test.ts,thread-lifecycle*.test.ts,native-process-authority.test.ts,run-attempt-native-process-authority.test.ts,attempt-timeouts.test.ts,attempt-startup*.test.ts, andrun-attempt*.test.ts. One unrelated failure,run-attempt.fork-provenance.test.ts("forks a sender-attributed turn using the exact submitted text without changing its display"), fails the same way onorigin/mainwithout these changes.node scripts/check-changed.mjspasses: extension typecheck, extension test typecheck, lint, format, and ratchets.activeLeases: 4andcloseWhenIdle: true. The four leases belonged to backgroundexeccommands whose processes no longer existed, and the Codex rollout recordeditem_completedfor each at the moment the thread unloaded. Restarting the Gateway cleared the hang.🤖 Generated with Claude Code