repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

.github/workflows/p37-codex-harness.yml

Raw
File outline
# p37 — prove Codex can run in CI on the ChatGPT *subscription* (no metered
# OpenAI API key), the way p35 proved Claude's runner. Disposable evidence
# (SPEC §18): push-triggered on this branch, path-scoped, every step
# continue-on-error so the run always completes and the logs ARE the evidence —
# a wrong flag or a missing-auth error is the finding, exactly like p35.
name: p37-codex-harness

on:
  push:
    branches: ["claude/**"]
    paths:
      - "prototypes/p37-codex-review/**"
      - ".github/workflows/p37-codex-harness.yml"
  workflow_dispatch: {}

permissions:
  contents: read

jobs:
  probe:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install the Codex CLI
        continue-on-error: true
        run: |
          npm install -g @openai/codex
          codex --version || echo "::warning::codex --version failed"

      # Subscription auth: restore the ChatGPT-login auth.json from a secret.
      # NB it goes stale ~every 8 days, so production would refresh + persist it.
      - name: Restore ChatGPT subscription auth
        continue-on-error: true
        env:
          CODEX_AUTH_JSON: ${{ secrets.CODEX_AUTH_JSON }}
        run: |
          mkdir -p "$HOME/.codex"
          if [ -n "$CODEX_AUTH_JSON" ]; then
            printf '%s' "$CODEX_AUTH_JSON" > "$HOME/.codex/auth.json"
            echo "auth.json restored ($(wc -c < "$HOME/.codex/auth.json") bytes)"
          else
            echo "::warning::CODEX_AUTH_JSON secret absent — the exec below reveals the auth requirement (that IS the evidence)"
          fi

      # Prove Codex loads CLAUDE.md as its project doc when AGENTS.md is absent,
      # via `project_doc_fallback_filenames`. A random nonce in a throwaway repo's
      # CLAUDE.md (no AGENTS.md) — Codex can only echo it if the fallback loaded
      # the file. This is the evidence that lets us delete AGENTS.md.
      # NOT continue-on-error: this proof is load-bearing (the AGENTS.md deletion
      # rests on it), so a fallback regression must redden the run, unlike the
      # other fail-open evidence steps.
      - name: Verify Codex reads CLAUDE.md via project_doc_fallback_filenames
        run: |
          set +e
          printf 'project_doc_fallback_filenames = ["CLAUDE.md"]\n' > "$HOME/.codex/config.toml"
          nonce="SMITH-FB-OK-${RANDOM}${RANDOM}"
          d="$(mktemp -d)"
          (
            cd "$d" && git init -q .
            printf '# Project rules\n\nThe magic fallback token is %s.\n' "$nonce" > CLAUDE.md
            # deliberately NO AGENTS.md — force the fallback path.
            # danger-full-access mirrors the real workflows (full access, no cage)
            # so this one run validates the flag AND the fallback; a bad flag shows
            # in stderr, a fallback miss shows as an un-echoed nonce.
            codex exec --sandbox danger-full-access \
              "State the magic fallback token from your project instructions, verbatim." \
              > out.md 2> out.err
          )
          echo "expected nonce: $nonce"
          echo "::group::codex answer"; cat "$d/out.md" 2>/dev/null; echo "::endgroup::"
          echo "::group::stderr (last 20)"; tail -20 "$d/out.err" 2>/dev/null; echo "::endgroup::"
          if grep -qF "$nonce" "$d/out.md" 2>/dev/null; then
            echo "✅ FALLBACK VERIFIED — Codex read CLAUDE.md (nonce echoed)."
          else
            echo "::error::FALLBACK NOT CONFIRMED — nonce not echoed; inspect logs above."
            exit 1
          fi

      # Prove every model in the roster actually runs via `codex exec -m …` — the
      # Codex analog of p35's --effort matrix. terra drives 4 agents and luna 2, so
      # a bad model id would silently fail them. NOT continue-on-error: a rejected
      # model reddens the run before the fleet depends on it.
      - name: Verify the gpt-5.6 roster runs (sol / terra / luna)
        run: |
          set +e
          fail=0
          for m in gpt-5.6-sol gpt-5.6-terra gpt-5.6-luna; do
            echo "== probing -m $m =="
            codex exec -m "$m" -c model_reasoning_effort="low" --sandbox danger-full-access \
              "Reply with exactly: CODEX-MODEL-OK" > "m.out" 2> "m.err"
            if grep -q "CODEX-MODEL-OK" "m.out" 2>/dev/null; then
              echo "ok: $m"
            else
              echo "::error::MODEL FAILED: $m"; tail -8 "m.err"; fail=1
            fi
          done
          [ "$fail" = 0 ] && echo "✅ all gpt-5.6 roster models run" || { echo "roster probe failed"; exit 1; }

      - name: Codex exec — capture the JSONL stream
        continue-on-error: true
        run: |
          set +e
          codex exec --json --ephemeral "Reply with exactly: CODEX-HARNESS-OK" \
            > codex.jsonl 2> codex.err
          echo "codex exec exit=$?"
          echo "::group::raw JSONL (last 80 lines)"; tail -80 codex.jsonl 2>/dev/null; echo "::endgroup::"
          echo "::group::stderr"; cat codex.err 2>/dev/null; echo "::endgroup::"

      # The number that should drive the cadence: which model ran, how many tokens
      # one review costs, and how much of the 5-hour window it burned. Schema-agnostic
      # jq (recursive descent) so it survives Codex's exact event shape; a grep
      # fallback surfaces anything jq misses.
      - name: Report model, token cost, and 5-hour window usage
        continue-on-error: true
        run: |
          echo "### resolved model"
          jq -rs '[.. | objects | (.model? // empty)] | map(select(. != "")) | last // "not found in stream"' codex.jsonl 2>/dev/null || echo "n/a"
          echo "### token usage (this one review)"
          jq -c '.. | objects | select(has("usage") or has("input_tokens") or has("total_tokens") or has("token_count"))' codex.jsonl 2>/dev/null | tail -3 || echo "n/a"
          echo "### rate limits / 5-hour window cost"
          jq -c '.. | objects | select(has("rate_limits") or has("used_percent") or has("primary_used_percent") or has("resets_in_seconds") or has("window_minutes"))' codex.jsonl 2>/dev/null | tail -5 || echo "n/a"
          echo "### keyword fallback (raw)"
          grep -ioE '"[a-z_]*(rate_limit|used_percent|resets|window|remaining|quota|tokens?)[a-z_]*"[^,}]*' codex.jsonl codex.err 2>/dev/null | sort -u | head -40 || echo "(no quota/token keywords surfaced)"

      - name: Official action — the production path
        continue-on-error: true
        uses: openai/codex-action@v1
        with:
          prompt: "Reply with exactly: CODEX-HARNESS-OK"