codex-plugin-cc icon indicating copy to clipboard operation
codex-plugin-cc copied to clipboard

Fix #202: zombie job blocks subsequent task calls when process crashes

Open D2758695161 opened this issue 7 months ago • 3 comments

Problem

When a Codex task process crashes or is killed externally, its job record remains in status running permanently. All subsequent task calls in the same Claude session fail with:

Task {job-id} is still running. Use /codex:status before continuing it.

Root Cause

In esolveLatestTrackedTaskThread(), when an active task job is found, the function unconditionally throws an error if the job status is running - without checking whether the actual process is still alive.

Fix

In esolveLatestTrackedTaskThread(), before blocking on an active task:

  1. Check if the PID is alive using process.kill(pid, 0)
  2. If the process is dead (EPERM or process doesn't exist), mark the job as ailed via upsertJob() and continue
  3. Only throw the blocking error if the process is actually alive

This ensures zombie jobs don't block subsequent task calls.

Testing

Minimal targeted fix - no behavioral change for healthy jobs. Only affects the zombie job edge case where the process has died but the job status wasn't updated.

Fixes #202

D2758695161 avatar Apr 13 '26 17:04 D2758695161

claiming this issue.

Implementation: PR #218 — fix handles zombie jobs by checking if PID is alive with process.kill(pid, 0) before blocking. If dead, marks job as failed via upsertJob().

D2758695161 avatar Apr 14 '26 01:04 D2758695161

Claiming this bug fix. The fix approach is clear: on job start, verify process liveness; if dead, upsertJob() with failed status. This prevents zombie jobs from blocking subsequent task calls.

D2758695161 avatar Apr 14 '26 08:04 D2758695161

Additional evidence — zombie variant where subsequent calls are NOT blocked

Observed on plugin v1.0.2, Linux. Same root cause (task-worker PID exits, state.json status remains "running"), but with a behavior that differs from this issue's title: subsequent calls in the same slug were accepted and completed normally, not blocked.

Timeline (same workspace slug)

  • T+0 Job 1 spawned (kind=task, write=true)
  • T+2min Last log entry, then no further events
  • T+21min Job 2 spawned in same slug
  • T+22min Job 2 completed normally (~1m26s)
  • T+66min state.json still reports Job 1 status="running", phase="running", pid recorded

Confirmed at observation time

  • ps -p <Job1 pid> returns no such process
  • state.json jobs[].status still "running" for Job 1
  • broker process for the slug still alive on its socket; new RPC requests accepted
  • Job 2's record added to jobs[] cleanly (via upsertJob's unshift), no displacement of Job 1's record

Interpretation (probable)

  • task-worker process crashed or was killed mid-turn (last log line is a routine command completion, then silence — no graceful shutdown message)
  • broker's activeRequestSocket was released automatically on socket disconnect (app-server-broker.mjs:74-77, 225-233 — clearSocketOwnership on close/error)
  • state.json has no PID liveness reconciliation on read (lib/state.mjs:58-74, 149-150 — pure parse + return)
  • tracked-jobs only clears the recorded pid on normal completion/error paths (lib/tracked-jobs.mjs:143-152, 158-178, 185-201), so a hard crash leaves a stale "running" entry indefinitely
  • subsequent fresh/background calls succeed because the broker gate is process-level (activeRequestSocket); the --resume-last path that consults state.json (codex-companion.mjs:311-317, 441-443) would still block on the zombie

Why this comment

  • The "blocks subsequent task calls" framing in the title may be one of two variants. We observed the other: broker auto-releases, state.json stays stale forever. A reconciler is still needed, but the user-visible symptom for fresh calls is "first call disappeared, second call worked fine" rather than "everything stuck."
  • Confirms the same root cause this issue identifies (no PID liveness check on state reads), with a direct-observation timeline.

Related

  • #218 (handle zombie jobs when process crashes but status remains "running")
  • #225 (Reconcile stale running jobs when pid exits)
  • #262 (reject crashed brokers via PID-alive probe)

If the reconciler runs on state.json reads or on broker reconnect, this variant should be covered. PID-alive probes on the broker side alone may not be sufficient — the stale state.json entry would still mislead --resume-last and /codex:status.

rae-hugo-kim avatar May 28 '26 08:05 rae-hugo-kim