`--output-last-message` doesn't create parent dirs; write fails after the turn completes yet exits 0, silently losing the final message
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start at the codex exec handling for --output-last-message and reproduce the missing-parent-directory command from the issue. Trace the final-message write and verify that parent directories are handled or that a failed write produces a non-zero exit; rerun the JSONL reproduction and confirm the expected file and exit status.
Written by the indexing model from the issue text.
Description
What happened
codex exec --output-last-message <path> does not create the parent directory of <path>. If the directory doesn't exist, the failure surfaces only after the turn completes — the model does all its work, the JSONL stream ends with turn.completed, and then the final-message write fails with a line on stderr:
Failed to write last message file "/tmp/.../missing-dir/out.md": No such file or directory (os error 2)
Worse, the process still exits 0, so the failure is invisible to any script checking the exit code. The tokens are spent, the final message is lost, and nothing but a stderr line (easily swallowed in headless/background contexts) indicates anything went wrong.
Repro
codex exec -s read-only --skip-git-repo-check --json \
--output-last-message /tmp/does-not-exist-$RANDOM/out.md \
"Output exactly: REPRO" </dev/null
echo $? # prints 0; no file was written
Observed on codex-cli 0.144.5, macOS 26 (Darwin 25.5.0, arm64).
Expected
Any of these would fix it (in descending order of preference):
- Create parent directories before writing, like most output-file flags.
- Validate the path at argument-parse time and fail fast — before the run spends tokens.
- At minimum, exit non-zero when the write fails so orchestration scripts can detect the loss.
Why it matters
--output-last-message is the natural primitive for headless orchestration (one output file per background worker). In that setting the flag's current behavior is the worst possible combination: the cost is incurred, the artifact is lost, and the exit code reports success. We now mkdir -p defensively before every dispatch, but the failure mode is subtle enough that it seems worth fixing at the source.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.5k
- Avg merge
- 1m
- Merged PRs (30d)
- 1k
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openai/codex
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug CLI windows-os
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
macOS sandbox blocks hw.optional.arm64 sysctl, causing Flutter to misdetect Apple Silicon as x64 Openbug CLI sandbox
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug CLI TUI
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
CLI config enhancement skills
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
A-linter
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
oxc-project/oxc#26863 ·