/codex temp-file creation fails on macOS (BSD mktemp): .txt suffix after XXXXXX + trailing-slash TMP_ROOT · Issue #2091 · garrytan/gstack · GitHub
Skip to content

/codex temp-file creation fails on macOS (BSD mktemp): .txt suffix after XXXXXX + trailing-slash TMP_ROOT #2091

Description

@scotthardin

Summary

On macOS, /codex (all three modes) fails before Codex ever runs: the mktemp
calls that create the stderr/prompt/response temp files error out, the bash block
exits 1, and the user sees no review. Two compounding bugs, both in gstack.

Environment

  • gstack: 1.58.4.0
  • macOS: 26.5.1 (Apple silicon)
  • mktemp: /usr/bin/mktemp (BSD)
  • $TMPDIR: /var/folders/.../T/ (note the trailing slash — macOS default)

Symptom

mktemp: mkstemp failed on /var/folders/.../T//codex-err-XXXXXX.txt: File exists
mktemp: mkstemp failed on /var/folders/.../T//codex-prompt-XXXXXX.txt: File exists
/opt/homebrew/bin/bash: line 13: : No such file or directory
=== CODEX_EXIT=1 ===
(The empty TMPERR/_PROMPT_FILE vars then cascade into "No such file or directory"
for every later "$TMPERR" / cat "$_PROMPT_FILE".)

Root cause

  1. Suffix after the placeholder. skills/codex/SKILL.md uses templates like
    mktemp "$TMP_ROOT/codex-err-XXXXXX.txt" (also codex-prompt-XXXXXX.txt,
    codex-resp-XXXXXX.txt). GNU mktemp tolerates a suffix after XXXXXX; BSD
    mktemp (macOS) requires the placeholder at the END of the template
    and
    mishandles the .txt suffix.
  2. Trailing slash in TMP_ROOT. bin/gstack-paths emits TMP_ROOT straight
    from $TMPDIR, which on macOS ends in /. The template then expands to a
    double-slash path (…/T//codex-err-…), compounding the failure.

Affected code

  • skills/codex/SKILL.md (and SKILL.md.tmpl) — Steps 2A / 2B / 2C, every
    mktemp "$TMP_ROOT/codex-*-XXXXXX.txt".
  • bin/gstack-pathsTMP_ROOT carries $TMPDIR's trailing slash.

Suggested fix

Drop the .txt suffix (X's at the end) and strip the trailing slash:

TR="${TMP_ROOT%/}"
TMPERR=$(mktemp "$TR/codex-err-XXXXXX")
_PROMPT_FILE=$(mktemp "$TR/codex-prompt-XXXXXX")
Either fix alone helps; both together is the robust portable form. Optionally have
gstack-paths normalize TMP_ROOT (_tmp_root="${_tmp_root%/}") so every skill
that consumes it benefits, not just /codex.

Repro

macOS, default $TMPDIR: run /codex review in any git repo. The first mktemp
in Step 2A fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions