Skip to content

/codex challenge + consult: ${PIPESTATUS[0]} is empty under zsh — hang detection never fires and every clean run reports a spurious failure #2669

Closed

Description

@dk96-creator

Repo: gstack 1.67.1.0 · File: ~/.claude/skills/gstack/codex/SKILL.md · Env: codex-cli 0.149.0, zsh 5.9, macOS 26.5.2 arm64

${PIPESTATUS[0]} is a bash array idiom. zsh has $pipestatus, lowercase and 1-indexed, and does not populate PIPESTATUS. Under zsh the expansion yields an empty string:

$ bash -c 'false | true; echo "[${PIPESTATUS[0]}]"'
[1]
$ zsh  -c 'false | true; echo "[${PIPESTATUS[0]}]"'
[]
$ zsh  -c 'false | true; echo "[${pipestatus[1]}]"'
[1]

The codex skill uses it at three sites, all on codex exec … --json | python pipelines:

  • SKILL.md:1410 — challenge
  • SKILL.md:1567 — consult (new session)
  • SKILL.md:1595 — consult (resume)
_CODEX_EXIT=${PIPESTATUS[0]}
# Fix 1: hang detection — log + surface actionable message
if [ "$_CODEX_EXIT" = "124" ]; then
  _gstack_codex_log_event "codex_timeout" "600"
  _gstack_codex_log_hang "challenge" ...
  echo "Codex stalled past 10 minutes. ..."
elif [ "$_CODEX_EXIT" != "0" ]; then
  # Surface non-zero exits so the calling agent doesn't read "no output" as
  # a silent model/API stall. See #1327.
  echo "[codex exit $_CODEX_EXIT] $(head -1 "$TMPERR" ...)"
  head -20 "$TMPERR" ...
  _gstack_codex_log_event "codex_nonzero_exit" "challenge:$_CODEX_EXIT"
fi

Effect

With _CODEX_EXIT empty, both branches misfire — reproduced directly:

$ zsh -c '_CODEX_EXIT=""
  if [ "$_CODEX_EXIT" = "124" ]; then echo "hang-detection branch"
  elif [ "$_CODEX_EXIT" != "0" ]; then echo "NON-ZERO/error branch"
  else echo "success branch"; fi'
NON-ZERO/error branch
  1. Hang detection never fires. [ "" = "124" ] is false, so on a genuine 600s timeout the user gets no "Codex stalled past 10 minutes" message and neither codex_timeout nor log_hang telemetry is written. The exit-124 path is unreachable on zsh.
  2. Every run reports a spurious failure. [ "" != "0" ] is true, so successful runs take the error branch: they print [codex exit ] with a blank code, dump up to 20 lines of stderr, and log a false codex_nonzero_exit event.

So on zsh both of the protections these blocks exist for — the hang detection, and the #1327 fix for surfacing real non-zero exits — are inoperative, and the second one inverts into noise on every clean run.

Two qualifications, in fairness:

  • The review path is unaffected. /codex review at :1058 uses a bare _CODEX_EXIT=$? with no pipeline, which is correct in both shells. The fail-closed gate added since Two stated guarantees in the codex skill don't hold (v1.60.1.0) #2524 gets a real value. This report is only about the three piped sites.
  • The direction is conservative — a spurious failure, never a spurious pass. It is a correctness and noise problem, not a safety hole. Telemetry counts of codex_nonzero_exit from zsh users will be inflated, and codex_timeout under-reported, which may be worth knowing if those feed any dashboard.

zsh is the default login shell on macOS, and Claude Code's Bash tool inherits it ($0=/bin/zsh, BASH_VERSION unset here), so this is the default path on macOS rather than an edge case.

Suggested fix

Portable one-liner, verified in both shells (success and failure):

_CODEX_EXIT=${PIPESTATUS[0]:-${pipestatus[1]}}
bash: failing → [7]   success → [0]
zsh:  failing → [7]   success → [0]

bash populates PIPESTATUS[0], so the default never evaluates; zsh leaves it empty and falls through to pipestatus[1]. Alternatively, drop the pipeline — redirect codex's --json output to a temp file and run the Python parser over the file, which makes a bare $? correct and matches what the review path already does.

Related: #2524 (both items fixed — thank you), and #1798, a different zsh-vs-bash assumption in setup-gbrain.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions