Aident AI

Codex Exec Exits 0 but No Image? Verify the Artifacts
If codex exec exits with status 0 but the images you requested are missing, treat the run as incomplete. Exit 0 means the Codex process finished without a process-level failure. It does not prove that every requested side effect happened or that every output path exists.
Preserve any partial images, record the JSONL event stream, and verify the exact files before the next pipeline step. Rerun only the missing work after you understand the failure. Do not delete partial output or repeatedly launch the entire batch.
Add an Artifact Postcondition Now
For a batch that should create six images, make the expected paths explicit and fail the job when any file is absent or empty:
Run this check immediately after Codex and before an uploader, renderer, deployment, or downstream agent consumes the output. A successful final message is useful context, but the filesystem is authoritative for a filesystem deliverable.
Capture Codex Events Without Hiding Its Exit Status
OpenAI's current non-interactive documentation recommends codex exec for scripts and CI. The --json flag changes the event stream to JSON Lines, with events such as turn.completed, turn.failed, and error.
In Bash, preserve both that stream and the real Codex exit status:
Then run the artifact postcondition. These checks answer different questions:
The process status tells you whether the command itself failed.
The JSONL stream tells you whether Codex reported a failed turn or error.
The artifact check tells you whether the requested deliverables actually exist.
None of the first two replaces the third.
Confirm That This Is the Same Failure
This pattern has a narrow signature:
The prompt names multiple required images or exact output paths.
Codex begins image generation and may return some generated assets.
Fewer files arrive than requested, or generated images remain outside the requested workspace paths.
The final response implies completion or the command exits 0.
A downstream step discovers that one or more files are missing.
OpenAI Codex issue 37717 reports that pattern on Codex CLI 0.147.0 in non-interactive mode: six image artifacts were requested, two default generated images appeared, none of the requested workspace files existed, and the process returned exit 0. The report also includes a child-manager timeout, but an open issue is not a confirmed root-cause analysis. Use the observable artifact mismatch as your gate instead of assuming every partial generation has the same cause.
Observation | What it proves | Next step |
|---|---|---|
| The process failed | Preserve events and stderr, then diagnose that failure |
JSONL contains | Codex reported a failed turn or error | Stop the pipeline and inspect the event |
Exit 0, but an expected path is absent | Delivery contract failed | Keep partial output and fail the artifact gate |
Every expected file exists and is nonempty | Basic delivery succeeded | Validate format and content before use |
Files exist at unexpected generated-image paths | Generation and workspace delivery diverged | Copy only after reviewing provenance, then fix the prompt or workflow |
Make the Prompt Machine-Checkable
Avoid a loose request such as "make several images." Give the run a finite output contract:
This makes the intended state unambiguous. It still does not make the model's final statement authoritative. Your wrapper must independently check the paths.
If another system needs a structured summary, --output-schema can constrain the final response and -o can save the last message. Ask for a manifest with completed and missing paths, but treat it as a diagnostic record. A structured claim that a file exists is not proof that the file exists.
Validate More Than Existence
An empty or mislabeled file should not pass. Add checks appropriate to the consumer:
Dimensions, aspect ratio, transparency, and semantic review may matter too. Validate only the properties your downstream job actually requires. The goal is a small, deterministic acceptance boundary, not an elaborate second agent.
For a broader pattern that applies to code changes as well as images, see How to Verify AI Coding Agent Tests Actually Pass. If a long generated file was truncated instead of omitted, use the recovery steps in How to Recover an AI-Generated 10,000-Line File.
Recover a Partial Batch Without Making It Worse
When two of six images exist, preserve those two and calculate the missing set. Before retrying, save:
the Codex version and operating system;
the original prompt and required paths;
codex-events.jsonland sanitized stderr;the paths, sizes, and hashes of completed artifacts;
the timestamp and any timeout or failed-turn event.
Then submit a bounded repair request that names only the missing paths. Tell Codex not to overwrite existing files. Recheck the complete six-file contract after the repair.
Avoid broad retry loops. Image generation can consume time or credits, and a blind retry can overwrite good output while reproducing the same partial failure. One evidence-backed retry is safer than repeatedly treating exit 0 as success.
Use Loadout for a Bounded Image Delivery Check
Aident Loadout can find the current image-generation options, validate their inputs, show the live price before execution, and keep provider credentials out of the prompt.
Start with this exact setup phrase:
Follow https://aident.ai/SETUP.md
Then ask:
Find a current image-generation Action. Inspect its schema and preflight one bounded 3:2 image request. Show me the exact credit estimate and wait for approval if execution costs credits. After approval, execute only that one image and verify that the response contains a downloadable image asset before reporting success. Do not publish, run a batch, expose credentials, or bypass the integration layer.
The acceptance condition is explicit: one valid input, one approved execution when required, and one downloadable image asset. Current catalog metadata also warns that some image-generation requests can return text without an image, which is another reason to validate the returned artifact rather than trusting a successful request alone.
Set up Aident Loadout and verify one image deliverable.
Sources
Refresh this guide when OpenAI closes issue 37717 with a released fix, changes codex exec event or exit semantics, or adds a first-class artifact delivery contract.



The one tool
for every tool
your agent needs.
Give any AI agent real capabilities in seconds. Connect 1,000+ tools once, skip the setup headache, and let your agents execute.
