Skip to content

Fix BSD mktemp suffix bug in codex skill temp file templates#2285

Open
cathrynlavery wants to merge 1 commit into
garrytan:mainfrom
cathrynlavery:fix-mktemp-bsd-suffix
Open

Fix BSD mktemp suffix bug in codex skill temp file templates#2285
cathrynlavery wants to merge 1 commit into
garrytan:mainfrom
cathrynlavery:fix-mktemp-bsd-suffix

Conversation

@cathrynlavery

Copy link
Copy Markdown
Contributor

Problem

On macOS/BSD, mktemp does not randomize the Xs when the template has a suffix after them. mktemp "$TMP_ROOT/codex-err-XXXXXX.txt" creates a literal codex-err-XXXXXX.txt, and any subsequent invocation with the same template fails:

$ mktemp /tmp/codex-err-XXXXXX.txt
/tmp/codex-err-XXXXXX.txt
$ mktemp /tmp/codex-err-XXXXXX.txt
mktemp: mkstemp failed on /tmp/codex-err-XXXXXX.txt: File exists

When that happens the variable ends up empty and the 2>"$TMPERR" stderr capture that follows breaks. This affects any session that runs a codex mode more than once (or two concurrent sessions sharing $TMP_ROOT).

Fix

Drop the .txt suffix from the mktemp templates for TMPERR, _PROMPT_FILE, and TMPRESP in codex/SKILL.md.tmpl (3 code blocks) and the generated codex/SKILL.md, keeping the two files in sync. Nothing downstream depends on the extension — every use goes through the shell variable (2>"$TMPERR", head, grep, rm -f).

Verified on macOS (Darwin 25.5.0) that the suffix-less form randomizes correctly on repeated calls:

$ mktemp /tmp/codex-err-XXXXXX
/tmp/codex-err-VrAY6O
$ mktemp /tmp/codex-err-XXXXXX
/tmp/codex-err-lmhc07

Note: the same suffixed-template pattern also exists in claude/SKILL.md.tmpl, office-hours/SKILL.md, scripts/resolvers/review.ts, and bin/gstack-developer-profile; this PR intentionally scopes to the codex skill, where the double-invocation failure was hit in practice.

On macOS/BSD, mktemp does not randomize the X's when the template has a
suffix after them: 'mktemp $TMP_ROOT/codex-err-XXXXXX.txt' creates a
literal codex-err-XXXXXX.txt, and any second invocation fails with
'mkstemp failed ... File exists', leaving the variable empty and breaking
the stderr capture that follows.

Drop the .txt suffix from the mktemp templates for TMPERR, _PROMPT_FILE,
and TMPRESP in codex/SKILL.md.tmpl and the generated codex/SKILL.md.
Nothing downstream depends on the extension; every use goes through the
shell variable.
@trunk-io

trunk-io Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant