Detached task-worker exits without writing failed status on broker socket disconnect
Open 💬 1 comment Opened May 8, 2026 by vstandos
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
- Start a long-running codex task in background mode
- Kill the broker mid-task OR cause broker socket reset (e.g., transient network blip on app-server connection)
- task-worker process dies silently
codex statusreports "running" indefinitely
Evidence (from local instance)
- task-worker spawn: codex-companion.mjs lines 641-679 (
spawnDetachedTaskWorkerwithdetached: true, stdio: "ignore") - State write on completion:
lib/tracked-jobs.mjslines 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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗