Opens in a new tab
Explainer

The Codex worker may still be running after the window closes

In brief

A host restarts while a coding worker is making a patch. Recovering the process, its files and its permissions is the difference between continuing the job and doing it twice.

7 min read

Is this the right starting point?
Before you read
Practical application/process-supervision experience, including Git workspaces, child processes and failure recovery.
What you will take away
Design a Codex worker supervisor that records ownership, reconciles uncertain outcomes and verifies artifacts after cancellation or restart.
Sources
Three tubes containing pale cubes, orange spheres and arrow shapes connect to a metal capsule with a lit window; flat geometric pieces rest on a short conveyor and in a tray beside it.
On this page6 sections

The release tool comes back after a restart. Its window looks ready for a fresh attempt, but somewhere on disk there may already be a patch. The Codex worker that wrote it may still be editing. In this hypothetical job, clicking Run again could put two writers into the same files. First we need to find the one we already started.

Starting codex exec gives the host a worker process to look after, not just an answer to wait for. Keep the task, events and workspace in one execution record. Then a wait that timed out can be distinguished from a worker that actually stopped.

The author of this CAD Studio report ran into a related problem. The Mac application launches codex exec --json, turns its events into chat steps and resumes a thread for further work. The author reports waiting, retrying and terminating child processes because an earlier writer can remain alive and prevent resume. It is one implementation’s experience, not a guarantee about every Codex integration, but it makes the ownership problem easy to recognize.

Choose the interface for the job you have

OpenAI documentation separates three integration choices. Exec suits scripts and bounded jobs. The SDK supports programmatic task control. App-server serves products needing persistent conversations, streaming, interruption, tools and approvals.

For a one-shot check, a child process returning structured output may be enough. A product with returning users, approvals and interrupted conversations needs a longer memory. Building all of that around shell launches can become more work than choosing the SDK or app-server. Pick the smallest interface that supports the behavior the host must own.

Even our single patch job leaves several pieces behind: input, output, errors, a process, a directory, a thread and files. Recording how they belong together is what makes the next startup useful. The host can look for this job rather than search the machine for something that resembles it.

A host application owns the execution ID, thread lease, deadline and permissions around a codex exec child process, then separately accepts its terminal event and artifacts.
The host keeps ownership of a worker’s lifecycle. After a timeout or crash, it must inspect what remains; neither event establishes that files or external state are unchanged.

“File changed” is a place to look

Just before the host restarts, the worker reports a file change. That is a promising clue: the patch may be worth recovering. It is not yet the tested patch the task asked for. A test could fail next, or a command could begin without ever reporting its finish.

With codex exec --json, the host receives JSONL: one JSON event on each line. OpenAI’s evaluation guidance shows how to save and parse those events, including commands and file changes, to check for required steps and artifacts. Use that sequence with the process exit, actual files and task-specific checks. The final message is still the agent’s report, not a substitute for looking at its work.

Suppose the reopened window shows only “file changed.” Perhaps the worker stopped there. Perhaps the chat display omitted the next event. Save the raw stream before turning it into a tidier view, so the distinction is recoverable. Keep secrets out at the source and control access to traces separately from access to artifacts. Someone reviewing the patch does not automatically need everything the worker encountered while producing it.

Recover the writer before replacing it

Give the attempt an execution ID before launch. Record its process and available thread IDs, directory, requested sandbox and approval settings, start time, deadline and expected output. Incoming events can update a heartbeat that shows recent activity. Cancellation and cleanup remain the host’s responsibility; a worker that has vanished cannot reliably explain its own disappearance.

Now imagine host A loses contact while its worker keeps editing. Host B sees that A’s ownership claim has expired and prepares to resume. Expiry does not mean the first writer stopped. B needs to inspect the recorded process and workspace, then recover ownership only after the earlier writer has stopped or been safely isolated. An atomic lease records one owner and an expiry as a single coordinated claim, renewed while that owner stays active. The supervisor must enforce the claim too, preventing an old worker from writing after its replacement takes over.

The skill execution guide follows the same questions through an interruption: what changed, what might still be changing, and what is the worker allowed to do next? Keeping those answers lets B continue a known task. A new launch by itself answers none of them.

Inspect Git state, artifacts and permitted destinations before replaying the request. The first run may have changed a file or completed an external action before the host lost its response. Classify what you find as completed, failed, still running or unknown. As the reconciliation guide explains, an uncertain write calls for readback before another write, not an assumption that nothing happened.

The deadline rings while a test is still running

Our patch job reaches its deadline with a command active. Stop adding work and request interruption, but keep watching: the deadline is not an exit receipt. A bounded grace period lets the host drain output, including a final event just after the timer. If the child remains, termination and escalation may be necessary. Record both the signals sent and the exits actually observed.

The child can have children of its own. A shell may have launched a test process before the interruption. Killing only that shell could leave the test running while a new worker changes the same files. Cancellation needs the owned process group, or its platform equivalent, rather than a broad process name that might catch somebody else’s session. The question is which owned processes stopped, not whether the button was pressed.

The patch can survive all of them. Stopping processes does not undo a file edit or an external action. Decide whether to keep, revert or hold the artifacts after inspecting them. For code, review the diff and untracked files and check the build and tests. The CAD application needs its own model and geometry checks. A clean-looking conversation can end with unfinished files, and an interrupted conversation can leave useful work worth saving.

Keep the permission boundary with the attempt

The reported CAD command uses workspace-write sandboxing and an approval policy chosen by its host. Official guidance calls for the permissions the task needs. Preserve the selected settings in the execution record: they help explain what this particular attempt could have reached or changed.

Suppose the patch needs a dependency download that the selected network policy denies. Keep the failed operation visible. The host can decide whether to supply the dependency, authorize a bounded download or leave the task unfinished. Silently opening unrestricted network access would change the worker’s reach, not merely repair the one missing dependency.

A completed patch can wait for review without being published. Publication, messaging and remote deletion produce effects outside the workspace and need explicit authorization and a recorded result. After a crash, that record tells the host whether preparation can resume or whether it must first check an external action that may already have happened.

Restart at the awkward moment on purpose

Test the restart just after the patch is written. Can the host find it, identify the original worker and tell whether editing continues? Then try a deadline with a surviving descendant, malformed JSONL, a missing terminal event and two hosts trying to resume together. Each case should leave a bounded state and enough information to choose a next action. Repeatedly launching a worker is not a useful answer to any of those tests.

Finding the patch is only half the exercise. Deterministic checks can establish specific requirements in the trace and files; qualitative review must judge what those rules cannot. A well-managed worker can produce a bad patch. A capable worker can lose a good one through a poorly managed host. Test the work and the supervision separately.

When the release tool returns, its execution ID can now lead back to a particular worker, thread, directory and trace. A finished patch goes to verification. A surviving writer has its ownership resolved. Uncertain partial work stays on hold while the host inspects it. The window may be new, but the job has a recoverable past, and nobody has to start a second copy just to find out what the first one did.

Sources & context

Sources linked in this article. Read alongside the author’s analysis; a citation does not independently verify a publisher’s claims.

Report an error or outdated detail

More on OpenAI

All OpenAI coverage

Keep reading

Where to go next