Skip to content

[codex] Reconcile stale running jobs when pid exits - #225

Closed
LawrenceChiu95 wants to merge 1 commit into
openai:mainfrom
LawrenceChiu95:codex/reconcile-stale-running-jobs
Closed

LawrenceChiu95 wants to merge 1 commit into
openai:mainfrom
LawrenceChiu95:codex/reconcile-stale-running-jobs

Conversation

@LawrenceChiu95

Copy link
Copy Markdown

Summary

  • auto-reconcile stale running jobs when the tracked pid no longer exists
  • persist the reconciliation to both state index (state.json) and per-job file (jobs/<id>.json)
  • append a log line so users can see why a job switched to failed

Root Cause

/codex:status trusted persisted state for running jobs without validating whether the worker process was still alive. If a worker died unexpectedly, the job could remain running indefinitely and appear stuck.

Changes

  • plugins/codex/scripts/lib/state.mjs
    • add pid liveness check (process.kill(pid, 0))
    • add reconciliation path in listJobs() for stale running jobs with dead pids
    • mark stale jobs as failed with errorMessage, completedAt, and pid: null
    • mirror updates into per-job json and append a log annotation
  • tests/state.test.mjs
    • add regression test: listJobs auto-reconciles stale running jobs when pid is no longer alive

Validation

  • node --test tests/state.test.mjs
  • node --test tests/runtime.test.mjs --test-name-pattern "status shows phases|status preserves adversarial review kind labels|status --wait times out cleanly|cancel without a job id ignores active jobs from other Claude sessions|cancel with a job id can still target an active job from another Claude session|stop hook logs running tasks to stderr without blocking when the review gate is disabled"

@LawrenceChiu95
LawrenceChiu95 force-pushed the codex/reconcile-stale-running-jobs branch from dda9158 to 0d6000d Compare April 19, 2026 09:34
@LawrenceChiu95
LawrenceChiu95 marked this pull request as ready for review April 19, 2026 09:34
@LawrenceChiu95
LawrenceChiu95 requested a review from a team April 19, 2026 09:34
xoonjaeho added a commit to xoonjaeho/codex-plugin-cc that referenced this pull request Aug 1, 2026
…openai#379)

A tracked job's completion is written by the launcher process that owns it. If
that launcher dies first -- crash, killed session, machine sleep -- the record
is frozen at running/queued with a stale pid forever: `status` keeps listing it,
`result` refuses it, and the rows accumulate.

Adopted upstream PR openai#379 verbatim. It reconciles at `listJobs`, the single read
chokepoint every consumer goes through, so status/result/cancel are all fixed at
once. Preferred over the competing openai#225 because its liveness probe is fail-closed:
only an explicit ESRCH marks a process dead, while openai#225 defaults to "dead" on any
unexpected errno. Wrongly reporting a live job as failed is far worse than leaving
a zombie -- codex turns routinely sit silent for many minutes.

Added the test that openai#379 was missing: a probe failing with EPERM (or any non-ESRCH
error) must leave the job running. Mutation-checked -- flipping that default to
"dead" passed the whole upstream suite before this test existed.

Windows suite: 96 tests / 84 pass / 12 fail, against a 91 / 79 / 12 baseline.
No new failures.
@dkundel-openai dkundel-openai added the duplicate This issue or pull request already exists label Aug 11, 2026 — with ChatGPT Codex Connector

Copy link
Copy Markdown
Collaborator

Duplicate of #425.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants