codex-pr-review-loop
Codex PR Review Loop
Run a GitHub PR through Codex review until the latest reviewed commit has no actionable Codex feedback, or until the next change needs the user's judgement.
Steps
-
Establish the PR target. Get to exactly one ready-for-review PR and a local branch that can safely modify its head. Handle only these setup cases:
- Existing PR: inspect its base, head branch, draft state, and remote head SHA; check out or create a local branch for that PR head if needed.
- No PR, on a feature branch: confirm the working tree is clean, push the branch if needed, and create a ready-for-review PR.
- No PR, on the base branch: stop and ask for a PR or feature branch.
- Draft PR: stop before triggering review. If an
@codex reviewcomment was already left while it was draft, leave a new trigger after the PR becomes ready because the old mention may not run.
Completion criterion: you can name the ready PR, base branch, head branch, local branch to modify, and target remote head SHA; or you have stopped because the PR is draft, no PR target can be established from the base branch, or the user must choose the target.
-
Maintain a review ledger. Keep a lightweight in-thread ledger for every round. Record the round number, target PR head SHA, trigger comment identity or timestamp, Codex acceptance evidence such as an eyes reaction, Codex result source, findings and classifications, fix commit SHA if any, and verification commands. Completion criterion: the latest round can be distinguished from older reviews and comments by SHA and trigger.
-
Trigger Codex review. Comment
@codex reviewon the ready PR. If the user gave a review focus, append it after the command, e.g.@codex review for security regressions and missing tests. Record the target SHA in the ledger before waiting. Completion criterion: the trigger comment exists on the ready PR and the ledger records the commit SHA it targets. -
Wait with state-based polling. Poll fast only until you know whether Codex accepted the job, then switch to slower state-based polling and report only meaningful state changes. For Codex review, absence of a result is never clean; clean requires evidence tied to the latest PR head. If Codex has accepted the job but not returned output, keep waiting or report the pending state if pausing; do not advance to collection or triage. Completion criterion: you have Codex output for the target SHA, or you have stopped with a concrete setup/access failure.