repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

Run Codex the way OpenAI documents for CI, so auth holds (#42)

b49a2d301903e3d4e11f2393196521b618e7b125

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

## What forced this
Codex reviewed nothing on every PR — its cross-family comment was always
the "unavailable" fallback, and it stayed that way even after the
`CODEX_AUTH_JSON` secret was reseeded from a locally-verified login. So
the secret was never the fault; the invocation was.

## The call
Match OpenAI's official CI/CD auth guide. Three divergences, any one
fatal: `codex exec --ephemeral` is not a valid exec flag (the documented
CI form is plain `codex exec --json`); the seeded `auth.json` was left
world-readable when Codex refuses anything looser than `600`; one
rolling cache was shared across all branches so concurrent PRs raced on
token rotation.

## What we deliberately didn't do
Didn't switch to `openai/codex-action@v1` — the hand-rolled job keeps
the fail-open + comment control we want, and now matches the documented
pattern. Kept seed-only-if-missing (already correct — it preserves the
tokens Codex refreshes).

## Evidence
Verified against `learn.chatgpt.com/docs/auth/ci-cd-auth`: seed only if
missing, persist the refreshed file, `chmod 600`, `codex exec --json`.
Confirmed live that the "unavailable" persisted with a known-good
secret, isolating the cause to the invocation. Codex stderr is now teed
into the run log so the next failure is diagnosable.

## Surface touched
`.github/workflows/adw-codex-review.yml` only.

## If this ages badly
If Codex returns `401`, reseed the secret (refresh token
revoked/expired); if a run shows a real error in the now-surfaced
stderr, act on that. Fail-open throughout — a broken Codex never blocks
a merge.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB)_

Co-authored-by: Claude <noreply@anthropic.com>

Changed files (1)

+25 / −9 text lines

Diff layout

.github/workflows/adw-codex-review.yml

Modified

+25 / −9 text lines

3939 uses: actions/cache/restore@v4
4040 with:
4141 path: ~/.codex/auth.json
42 key: codex-auth-${{ github.run_id }}
42 # Branch-scoped: OpenAI warns not to share one auth.json across
43 # concurrent jobs — two PRs rotating the same restored token races and
44 # can invalidate the refresh token. Each branch rolls its own; a new
45 # branch cold-starts from the secret.
46 key: codex-auth-${{ github.head_ref }}-${{ github.run_id }}
4347 restore-keys: |
44 codex-auth-
45 - name: Seed auth from secret if cache cold
48 codex-auth-${{ github.head_ref }}-
49 - name: Prepare Codex auth (seed only if cache cold)
4650 env:
4751 CODEX_AUTH_JSON: ${{ secrets.CODEX_AUTH_JSON }}
4852 run: |
49 mkdir -p "$HOME/.codex"
50 if [ -s "$HOME/.codex/auth.json" ]; then
53 export CODEX_HOME="$HOME/.codex"
54 mkdir -p "$CODEX_HOME"; chmod 700 "$CODEX_HOME"
55 # Seed ONLY if missing — overwriting the restored file discards the
56 # tokens Codex rotated last run (OpenAI CI guidance), breaking refresh.
57 if [ -s "$CODEX_HOME/auth.json" ]; then
5158 echo "auth.json restored from cache"
5259 else
53 printf '%s' "$CODEX_AUTH_JSON" > "$HOME/.codex/auth.json"
60 printf '%s' "$CODEX_AUTH_JSON" > "$CODEX_HOME/auth.json"
5461 echo "auth.json seeded from CODEX_AUTH_JSON secret"
5562 fi
63 # Codex refuses a group/world-readable auth.json, and the cache does not
64 # preserve mode — pin 600 every run or auth silently fails.
65 chmod 600 "$CODEX_HOME/auth.json"
5767 - name: Install Codex
5868 run: npm install -g @openai/codex
6676 REPO: ${{ github.repository }}
6777 run: |
6878 set +e
79 export CODEX_HOME="$HOME/.codex"
6980 gh pr diff "$PR" --repo "$REPO" > pr.diff
70 codex exec --json --ephemeral "You are smith's cross-family reviewer (read AGENTS.md). Give an independent, file-anchored review of this pull request diff — correctness, security (untrusted Lua plugins, secrets, injection), and fit against docs/SPEC.md — flagging what a same-family reviewer might rationalize away. Concise markdown. Diff follows:
81 # `codex exec --json` is the exact non-interactive form OpenAI documents
82 # for CI — no `--ephemeral` (not a valid exec flag; it made codex error
83 # out and read as "unavailable"). auth is picked up from $CODEX_HOME.
84 codex exec --json "You are smith's cross-family reviewer (read AGENTS.md). Give an independent, file-anchored review of this pull request diff — correctness, security (untrusted Lua plugins, secrets, injection), and fit against docs/SPEC.md — flagging what a same-family reviewer might rationalize away. Concise markdown. Diff follows:
7185 $(cat pr.diff)" > out.jsonl 2> codex.err
72 echo "codex exit=$?"
86 rc=$?; echo "codex exit=$rc"
7387 jq -rs '[.. | objects | (.text? // .message?.content? // .delta? // empty)] | map(select(type==\"string\" and . != \"\")) | last // \"\"' out.jsonl > review.md 2>/dev/null
7488 if [ ! -s review.md ]; then
89 # Surface why, so "unavailable" is never a black box again.
90 echo "::group::codex stderr (diagnostic)"; tail -40 codex.err 2>/dev/null || true; echo "::endgroup::"
7591 echo "_Codex was unavailable for this review (auth/window/tooling — advisory, non-blocking). See the run log._" > review.md
7692 fi
7793 {
94110 uses: actions/cache/save@v4
95111 with:
96112 path: ~/.codex/auth.json
97 key: codex-auth-${{ github.run_id }}
113 key: codex-auth-${{ github.head_ref }}-${{ github.run_id }}
99115 - name: Mark codex-reviewed (fail-open, never gates)
100116 if: always()