codex - 💡(How to fix) Fix Detached task-worker exits without writing failed status on broker socket disconnect

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  • Two ghost-running tasks observed today with last activity timestamps minutes before broker reset, then no log entries, no error, dead PIDs

Fix Action

Workaround

Operators must ps -p <PID> to check if the worker is alive. If dead, manually mark task as failed in state.json.

Environment: codex-cli 0.129.0, Linux x86_64 (WSL2 Ubuntu 24.04), npm 11.x.

RAW_BUFFERClick to expand / collapse

Issue

When a codex-companion.mjs task --background task-worker process exits due to broker JSON-RPC socket close/reset, runTrackedJob's catch block is never reached. The job stays permanently in status: "running" in state.json with a now-dead PID.

Reproduce

  1. Start a long-running codex task in background mode
  2. Kill the broker mid-task OR cause broker socket reset (e.g., transient network blip on app-server connection)
  3. task-worker process dies silently
  4. codex status reports "running" indefinitely

Evidence (from local instance)

  • task-worker spawn: codex-companion.mjs lines 641-679 (spawnDetachedTaskWorker with detached: true, stdio: "ignore")
  • State write on completion: lib/tracked-jobs.mjs lines 153-203 — only catch path writes failed status
  • Two ghost-running tasks observed today with last activity timestamps minutes before broker reset, then no log entries, no error, dead PIDs

Proposed fix

Add process.on('exit'/'uncaughtException'/'unhandledRejection') handler in handleTaskWorker that synchronously writes status: "failed" to the job file before exit. Without this, operators cannot distinguish actively-running tasks from dead ones.

Workaround

Operators must ps -p <PID> to check if the worker is alive. If dead, manually mark task as failed in state.json.

Environment: codex-cli 0.129.0, Linux x86_64 (WSL2 Ubuntu 24.04), npm 11.x.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Detached task-worker exits without writing failed status on broker socket disconnect