Skip to content

Instantly share code, notes, and snippets.

@marcomd
Created August 22, 2026 14:44
Show Gist options
  • Select an option

  • Save marcomd/1cf8a8681757fba92b739ce5871b84fd to your computer and use it in GitHub Desktop.

Select an option

Save marcomd/1cf8a8681757fba92b739ce5871b84fd to your computer and use it in GitHub Desktop.
This skill answers the review comments on a pull request. It verifies each claim against the code, reacts thumbs up or down, posts a short threaded reply explaining the decision, fixes what was agreed test-first, and commits. By default it stops there, because pushing is a human decision. With `--autofix` flag, the skill does not stop at the com…
name pr-review-triage
description Triage the review comments on the current branch's pull request. Verifies each reviewer claim against the code, reacts thumb-up/thumb-down, posts a short threaded reply explaining the call, then fixes what was agreed TDD-first and commits it as the next numbered phase. Pass --autofix to also push and re-arm the review loop. Activate when the user asks to check, answer, triage, respond to, or fix PR review comments, reviewer feedback, or Codex/bot review findings.
hints [pr_number] [--autofix]
tools Bash, Read, Edit, Write

PR Review Triage

Work through the review comments on the current branch's pull request: verify each claim against the code, react with a thumb, reply with a short explanation, then fix what was agreed and commit.

This is the response side of code review. It does not hunt for new findings.

By default the pass ends at a local commit (Step 6). Passing --autofix additionally pushes and re-arms the loop; that mode, and the only case where pushing is allowed, is Step 7.

Never use em dashes in text posted to GitHub. Prefer regular dashes, commas, or rewrite the sentence. Repository prose (docs/, obsidian_vault/, CHANGELOG.md) keeps the house style it already has.

Note: If the user gave a PR number in the hint, use it instead of resolving one from the branch.
--autofix enables Step 7 (push, wait for Codex, loop). Without it, stop at the local commit in Step 6.

Step 1: Find the PR and read every comment

BRANCH=$(git branch --show-current)
gh pr list --head "$BRANCH" --state all --json number,title,url,state

Get OWNER/REPO from the PR, not from the checkout:

. tools/github/autofix_guards.sh
autofix_require_upstream           # sets BASE_HOST from the URL the push will use
autofix_resolve_base_repo NUMBER   # sets BASE_REPO, refusing if it is ambiguous

Pass --hostname "$BASE_HOST" on every gh api call and use $BASE_REPO in every path, here and in the classifier command below. gh api defaults to github.com whatever the checkout is, so an Enterprise PR would otherwise be triaged against a same-named repository on the public host and the classifier could report CLEAN while a blocker sat unseen on the real one.

gh repo view answers with the current directory's repository, so in a fork checkout every command above would read the fork's same-numbered PR instead of the one being triaged, and the classifier could return CLEAN without ever seeing an upstream blocker. Sourcing the guard reuses the resolution the scripts already use and the tests already cover, rather than restating it here where it would drift.

Every command below uses those two values, so this runs before the first query rather than after it: an earlier version of this step assigned them underneath their own consumers, and the fetch went out with an empty host and repository.

With the PR number, pull all three comment surfaces. They are different API objects and missing one means missing findings:

# Inline review comments (the usual case for bot reviewers)
gh api --hostname "$BASE_HOST" "repos/$BASE_REPO/pulls/NUMBER/comments" --paginate \
  --jq '.[] | {id, path, line, body, user: .user.login, in_reply_to_id, pull_request_review_id}'

# Top-level PR conversation comments
gh api --hostname "$BASE_HOST" "repos/$BASE_REPO/issues/NUMBER/comments" --paginate \
  --jq '.[] | {id, user: .user.login, body}'

# Review summaries (a reviewer can leave findings in the body of the review itself)
gh api --hostname "$BASE_HOST" "repos/$BASE_REPO/pulls/NUMBER/reviews" --paginate \
  --jq '.[] | {id, state, commit_id, user: .user.login, body}'

commit_id is in that projection because Step 7 classifies on it: it is what distinguishes this round's review from the previous round's on a PR that has gone several rounds. Drop it and the two are indistinguishable, which re-triages stale findings or misses the current verdict.

--paginate on all three, not just the inline one. The default page is 30 and all three endpoints return oldest first, so the item that falls off an unpaginated call is the newest one — the round you are triaging right now. A PR that goes several rounds reaches 30 reviews faster than it looks: this skill's own PR hit 18 in six. A truncated listing is indistinguishable from a quiet review, which is the failure this whole step exists to prevent.

Skip comments whose in_reply_to_id is set and whose author is you: those are your own earlier replies, not new findings.

On a loop re-entry, filter to the matched review's pull_request_review_id. Every endpoint returns the whole PR oldest-first, so round three sees round one's findings too, and those are top-level comments by the bot, which the skip rule above does not touch. Triage them again and the ledger reports the first one as a repeat, so the loop halts before it has looked at the round it was woken for. pull_request_review_id is the only field that separates rounds, which is why the projection carries it.

Step 2: Verify each claim in the code before reacting

Do not agree from the comment text alone. A reviewer, human or bot, states a conclusion; your job is to check whether it holds in this repository. For each comment:

  1. Read the file and the functions it names, including the ones it only implies. A claim about a loop needs the loop's body and the data that bounds it (often a data/balance/*.json value).
  2. Establish the concrete failure: the input, the resulting state, and why that is wrong. If you cannot construct one, the comment is not confirmed.
  3. Check whether the suggested fix is correct. A finding can be real while its proposed remedy introduces a worse bug. Say so, fix the finding your own way, and explain the difference in the reply.

Only then decide the thumb.

Step 3: React and reply, per comment

Two different endpoint shapes. Getting them wrong produces 404s:

# Reaction: pulls/comments/{comment_id} — NOT pulls/{pr}/comments/{id}
gh api --hostname "$BASE_HOST" -X POST "repos/$BASE_REPO/pulls/comments/COMMENT_ID/reactions" -f content='+1'   # or '-1'

# Threaded reply: pulls/{pr}/comments/{comment_id}/replies — this one takes the PR number
gh api --hostname "$BASE_HOST" -X POST "repos/$BASE_REPO/pulls/NUMBER/comments/COMMENT_ID/replies" -f body='...'

Quote '+1' and '-1' so the shell does not eat them. For a top-level issue comment, reactions go to repos/$BASE_REPO/issues/comments/{id}/reactions.

Use -F body=@file for long bodies rather than inlining shell-hostile text. If a posted reply comes out mangled, fix it in place with gh api --hostname "$BASE_HOST" -X PATCH "repos/$BASE_REPO/pulls/comments/{id}" -F body=@file rather than posting a second reply.

Reply content, kept short. The point is that the human can understand the call without re-reading the diff:

  • Agreed: what the actual defect is, the fix, and the test names that now pin it.
  • Disagreed: the specific reason it does not hold here, with the file and line that shows it. Do not soften a disagreement into a vague agreement, and do not manufacture a thumb-down for balance.
  • Partly: thumb up the real part, state plainly which part you did not take and why.

Step 4: Fix, TDD, per this repository's rules

  • Tests first. Write the failing test, then the smallest fix. Run the suite: godot --headless -s addons/gut/gut_cmdln.gd -gdir=res://test/unit -ginclude_subdirs -gexit
  • Nothing pure goes into a presentation/ script. A review fix that adds an input, formatting or state decision to a UI file belongs in a pure sibling (extends RefCounted, class_name-d) with its own test/unit/test_*.gd. See CLAUDE.md / AGENTS.md.
  • Prove the new test is not vacuous. Temporarily restore the old behaviour, confirm the test fails, restore the fix. A test that passes against the bug pins nothing, and review fixes are exactly where that happens, because the assertion is written after the answer is known.
  • Keep explanatory comments. Where a fix changes what an existing comment claims, rewrite the prose to explain the new reason. Do not retarget a constant and leave stale reasoning beside it.

Step 5: Closeout

Follow the standard workflow in AI_CONTEXT.md:

  • docs/, CHANGELOG.md (append to the current unreleased section), and README.md where affected.
  • Wiki: update every affected page under obsidian_vault/, refresh index.md only if the catalog changed, and append a log.md entry headed ## [YYYY-MM-DD] fix | Issue #N: <count> findings from the PR #M review. Record what was agreed, what was rejected and why, files touched, and the test count. A second round is normal — pushing the first round's fixes triggers a fresh review of the new commits — so name the round in the heading (from the second PR #M review round) rather than filing two entries that read as the same pass.
  • Write the general lesson into the wiki, not just the patch. "A range check must bound the work a value causes, not only the value" outlives the one command it was found in.

Step 6: Commit

  • One commit for the whole review pass, numbered as the next phase of this branch's series (51.7 is followed by 51.8), matching the existing git log labels.
  • Check whether the branch is already pushed before touching history. git status -sb and the reviewed commit named in the review body tell you. Anything on the remote is off limits to --amend and rebase; a later round is always a new numbered commit on top, never an edit of the round it follows.
  • Commit, never push. Marco reviews and pushes. Step 7 is the single exception, and only when --autofix was passed explicitly on this invocation.
  • Verify counts before writing them into a message. Count new tests with git diff -U0 <test files> | grep -c '^+func test_' rather than estimating.

Step 7: Autofix loop (opt-in, --autofix only)

Only when the invocation explicitly passed --autofix. Without that flag, stop at Step 6.

This mode closes the review loop: push the round's commit, wait for Codex to review the new head, and re-enter this skill on the findings. Drive it with the built-in /loop in self-paced mode, so the wake-ups can chase a condition instead of a fixed clock:

/loop /pr-review-triage --autofix

What blocks, and what is merely noted

Codex's side of this contract is AGENTS.md, under Code Review Rules: it judges the PR as a merge decision, blocks only on P0 or P1, and ends its summary with MERGEABLE or BLOCKED. This section is the responding half.

Do not classify by reading. Run the classifier:

LEDGER=$(git rev-parse --git-path pr-autofix-NUMBER.json)
gh api --hostname "$BASE_HOST" "repos/$BASE_REPO/pulls/NUMBER/reviews"  --paginate > /tmp/reviews.json
gh api --hostname "$BASE_HOST" "repos/$BASE_REPO/issues/NUMBER/comments" --paginate > /tmp/issue.json

gh api --hostname "$BASE_HOST" "repos/$BASE_REPO/pulls/NUMBER/comments" --paginate \
  | tools/github/autofix_classify_review.py \
      --reviewer 'chatgpt-codex-connector[bot]' --operator 'YOUR_LOGIN' \
      --reviews /tmp/reviews.json --issue-comments /tmp/issue.json \
      --handled-from "$LEDGER"
# {"verdict": "BLOCKED"|"ADVISORY_ONLY"|"CLEAN", "blocking_findings": [...],
#  "advisory_findings": [...], "unparsed": N}

All three surfaces from Step 1, because a P0 placed in a review summary or a conversation comment is still a blocker. The extra two are passed as files and handled comes from the ledger, rather than being assembled into one document by hand: an earlier version of this block used jq --slurpfile ... $c[0], which is correct when the file holds one JSON array and silently wrong when it holds a stream of objects, and Step 1 can produce either. A command whose correctness depends on how its input happened to be made is a trap, not an instruction.

--handled-from reads handled_non_threaded from the ledger. Those two surfaces have no thread to reply under, so that list is the only record they were answered; passing an empty one reopens every historical finding on every entry and the loop never reaches the current round.

--operator is the login the loop replies as, and only its replies count as triage: anyone can write "I reproduce this" under a finding, and that is discussion, not an answer. Override tokens are honoured from anyone, because those are deliberate instructions rather than a claim that the work is done. Each finding carries a source of inline, review or conversation, which tells you whether there is a thread to reply in.

BLOCKED means at least one P0 or P1 is outstanding. ADVISORY_ONLY means only P2 or P3 remain. CLEAN means every finding has an answer. Codex's MERGEABLE maps onto the last two, and the verdict is recomputed here rather than taken on trust, because a review that omits it or changes its badge format has to fail closed rather than read as mergeable.

Severity What the round does
P0, P1 Verify, react, reply, fix, push, go again. These are the only findings that hold the loop open.
P2 Verify, react, reply always. Fix while the polish budget lasts; after that, record as accepted-and-deferred and move on.
P3 Verify, react, reply. Never fixed by the loop.
Unrecognised Treated as blocking, and counted in unparsed. The severity is a badge image inside a comment body, so its format belongs to someone else; a classifier that read an unknown finding as advisory would declare convergence forever and say nothing.

Every finding gets a reply, whatever its severity. Only the gate changes, never the courtesy: an unanswered advisory leaves the thread ambiguous, which is the condition this whole skill exists to remove.

P0 and P3 have never been observed on a real PR here. They are defined so the boundary is not a surprise, and nothing depends on them arriving.

The polish budget

At most two rounds that changed code for advisory findings, and a round that also fixed a blocker spends nothing. What the budget rations is the extra round: one that exists only because of polish, and that therefore buys another whole review cycle. A round already running for a P0 or P1 costs nothing more to carry a small P2 fix alongside, so charging it would penalise the free case and push advisories into rounds of their own, which is the opposite of the point.

So a round spends budget when it committed an advisory fix and had no blocking findings. A run whose first three rounds were all P1 has spent none of it. Keep the counter in the ledger, because it is one of the two things GitHub does not record.

Free is not quite the same as costless: a P2 fix still enlarges the diff the next review reads. In a blocked round, take the advisories that are small and in scope and leave the rest; the budget governs whether polish may have a round to itself, not whether every advisory must be taken.

Once the budget is gone, an advisory-only round is a complete round with no commit:

  1. verify each finding as usual;
  2. reply, saying it is confirmed, non-blocking, and deferred by the budget;
  3. no commit, no push;
  4. label the exit and stop.

An advisory-only round after the budget converges even without a +1, but only once the head has a terminal signal. On a multi-commit push an intermediate SHA can produce an advisory-only review while the head's run is still queued, and this exit writes no commit, so it never passes through autofix_push.sh and never meets its settling. Converging there would put status:to-approve on a head that may still come back with a P0: the same rule as --continuing, on the one path that has no push to enforce it. Waiting for the reviewer to volunteer approval is what produced twenty-three rounds on this PR: two thirds of its findings were P2, and polish has no natural end.

Human overrides in a thread

A reply in a finding's thread can override the policy. The vocabulary is exact, one token alone on its line:

Token Effect
@loop fix Treat as blocking whatever the severity says
@loop defer Treat as non-blocking
@loop false-positive Drop the finding entirely

Exact, because free prose would be a natural-language parser wearing the costume of configuration. The token is the discriminator and never the author: the loop's replies and a human's arrive under the same account, so the loop must never write one of these tokens, even when quoting this table. Overrides are read before severity.

Where round one starts

The loop is invoked with the branch in whatever state it is already in, so decide before doing anything:

  • Findings already pending → normal Steps 1 to 6, then push and wait.
  • Nothing to triage but unpushed commits exist → skip to the push, subject to the in-flight check below. Those commits have never been reviewed, and waiting for a verdict on a SHA the remote has not seen would time out.
  • Nothing to triage and nothing to push → stop immediately and say so. Never push an empty round to provoke a review.

How Codex reports, and the state machine it implies

Codex signals through reactions on the PR description plus, when it has findings, a review. Read all three together; no single one of them is sufficient:

Signal Meaning
eyes reaction on the PR body A review is running right now.
Review whose commit_id is the pushed SHA Findings. This is the round to triage.
+1 reaction on the PR body Clean. No review and no comment is posted.

Codex removes its own +1 when it starts a run and re-adds one only if that run is clean. So a +1 present after eyes has cleared always refers to the run you are waiting on, which is what makes the clean exit reliable on round 5 as well as round 1. That inference holds only while one run is in flight at a time, which is why the push waits out an active review below. The reaction names the bot, not a commit, so two overlapping runs cannot be told apart afterwards.

The eyes reaction is what makes the wait tractable. Measured latency on PR #64 was 2m59s to 7m01s, so no fixed interval is right, but "is it still running?" is directly observable rather than inferred. Without it, a missing review is indistinguishable from a slow one.

Push, with guards

The guards are a script, not a block to paste. tools/github/autofix_push.sh <PR> refuses and explains rather than pushing, and test/python/test_autofix_push_script.py drives every refusal path with stubbed git and gh. They lived in this file as Bash once. Nothing executed them, the tests over them asserted strings in this Markdown, and a review found three real defects in them while the suite stayed green. A guard that cannot be run cannot be trusted, which is the whole reason the file exists.

PRE_PUSH_HEAD=$(git rev-parse '@{u}')   # what Codex was last looking at
tools/github/autofix_push.sh NUMBER              # strict: this loop did not close the last round
tools/github/autofix_push.sh NUMBER --continuing # it did, so one quiet sample is enough
# PUSHED_SHAS=<sha...>   every commit this push added, oldest first
# PRE_PUSH_REVIEWS=<review ids that existed before the wait>
# BASELINE_PLUS_ONE=<iso8601|none>
# PUSHED_SHA=<sha>

Push everything that is ready, and wait on every commit it added. Codex reviews each pushed commit separately, so a push of three draws three reviews; the script reports them as PUSHED_SHAS, oldest first. The round's verdict is the head's, and the others are watched only so that a review landing on one of them is triaged rather than lost. Keep $PRE_PUSH_HEAD in that watch list too, because the script waits out a running review but cannot know whether the one that already finished on the old head was ever triaged.

Waiting for every listed SHA looks tidier and is wrong twice over. Codex does not always review the intermediate commits: a two-commit push on this PR produced exactly one review, on the head, so the wait would never end. And a clean run adds a global +1 with no commit identity, so a +1 from an intermediate run reads as the head's verdict while the head's own run is still queued.

This used to refuse anything but a single commit. That solved the wrong problem: the defect it came from was a classifier that only looked at the head, which is fixed by watching the list. Splitting a branch into one-commit rounds costs a full review cycle each and, worse, makes the reviewer examine a state that no longer exists while the rest of the work sits parked. Findings then arrive about code a later commit already replaced, and the parked fixes stop applying cleanly. Verify a finding on an intermediate commit against the current tree: it may already be resolved by a later commit in the same push, and saying so is a complete answer.

Take both values from its stdout. Any non-zero exit is a refusal, printed as refuse: <reason> on stderr: abandon the loop and report the reason. Never repair a refusal by retrying it or by forcing past it.

Pass --continuing when, and only when, this loop closed the previous round itself, which means the head's terminal signal was seen. An intermediate review does not authorize --continuing: on a multi-commit push a middle SHA can produce findings while the head's run is still queued, and triaging those closes a review, not the round. Waive the settling there and the fix push lands over the queued run, whose later global +1 then satisfies the settle check for a head nobody read. The bare form is the canonical one precisely because the round-one path, "nothing to triage but unpushed commits exist", is the case where the loop did not close the previous round: writing the flag into the default example would disable the safety on the one entry that needs it.

The script does not try to work out whether the head it is replacing was reviewed. It cannot: a +1 is a reaction on the PR body, so it names the bot and not a commit, and a clean run posts no review object at all. Five rounds of PR #70 went into trying to bind one to the other and every attempt was refuted. The way out is that the question is not GitHub's to answer. The loop knows the previous round is closed because it is the thing that closed it, having just triaged that round's verdict.

So the rule is a human one, borrowed from how Marco does it by hand: do not push while the light is red, and if you cannot vouch for what came before, wait until you are sure nothing is queued. Without --continuing the script requires a sustained absence of eyes, longer than the slowest observed start-up, because a queued run has not raised its flag yet and absence of the flag alone proves nothing. With it, one clean sample is enough.

Strict is the default deliberately. Forgetting the flag costs time; passing it wrongly costs a round pushed over an unreviewed head. This is a probabilistic bound rather than a proof, which is why the exit is always labelled: a human sees the PR before it merges.

What it does, in order, and why each step is there:

Guard Why
Refuses main, a dirty tree, a missing upstream, a diverged upstream A diverged upstream means someone else pushed, so stop and hand back. The clean-tree rule is broader than one push, and is stated below.
Waits out an eyes reaction before pushing, ~10 minutes then refuses, and without --continuing waits for a sustained absence of it Two runs in flight cannot be told apart afterwards. A +1 is a reaction on the PR body, so it names the bot and not a commit, and the older run's clean verdict would read as approval of the SHA about to be pushed.
Reports BASELINE_PLUS_ONE read after that wait Reading it before is the same race one step later: a +1 the older run adds while you wait would look newer than the snapshot, and the first poll after the push would call the unreviewed new SHA converged.
Clears status:to-approve, treating only an absent label as benign A new round is not approved. A lookup or removal that fails on auth or a transient error must not read as "not present".
Refuses on a failed git push Otherwise the loop waits out its whole deadline for a review of a SHA the remote never received, and reports reviewer inactivity, which sends the next person to look at the bot instead of the push.
  • A red suite is never pushed. The script cannot see Step 4's run, so this one is yours: if it has failures, stop the loop and report them.
  • The push authorization covers fixes, nothing else. A round that verifies every finding as false is a complete and successful round, and it ends at the replies: there is no commit, so there is nothing for the reviewer to look at again. Do not manufacture a closeout-only commit to keep the loop alive. Still do the Step 5 closeout and commit it, but leave that commit unpushed under the Step 6 default, and stop.
  • The tree must be clean before the loop starts, not just before each push. Unrelated uncommitted work is how a review fix silently acquires files the reviewer never saw, and the Step 5 closeout appends to obsidian_vault/log.md, so a pending edit to that file collides head-on. Park unrelated work on its own branch first; do not stash it and hope, because the closeout will have rewritten the same file by the time you pop it.

Wait, then classify

Sleep via ScheduleWakeup, roughly 240s for the first look and ~300s after. Pass the same /loop /pr-review-triage --autofix input back as prompt on every call, or the loop dies at the first wake-up, and end it with stop: true rather than by simply not scheduling again.

Check the terminal signals before the running signal. A fast review can finish inside the first 240s (the quickest observed was 2m59s), so you may never see eyes at all. On each wake-up, in this order:

  1. Review authored by the Codex reviewer whose commit_id is any SHA in $PUSHED_SHAS → findings. The author binding is not decoration: a human approval or another bot's comment on the same SHA would otherwise end the wait and send the loop into triage before Codex has said anything. Step 1 already fetches the author. Re-enter this skill from Step 1 as the next round, anchored to that review's id. Normally that is just $PUSHED_SHA; check $PRE_PUSH_HEAD too, because a review that landed on the old head while the script was waiting out eyes is a real round nobody has triaged. A finding is untriaged when no reply of yours sits under it, and that is the whole test. Both review-id references fail, in opposite directions: a ledger starts empty, so historical reviews read as new, while $PRE_PUSH_REVIEWS contains reviews that completed but were never triaged, so those read as historical and their findings vanish silently. That needs only an ordinary interleaving, a review landing on the old head while a later round is mid-triage. The thread is ground truth and needs no bookkeeping: Step 1 already fetches in_reply_to_id, so subtract the ids that have been replied to from the bot's top-level comments. $PRE_PUSH_REVIEWS still says what this round is waiting on; it never says what has been answered.

    Only inline comments have a thread to reply under, so reply-presence answers for them alone. Step 1 reads three surfaces, and a finding in a review-summary body or a top-level conversation comment has no in_reply_to_id relationship at all: nothing can sit "under" it, and an issue comment does not even carry pull_request_review_id. For those two, record the id you answered in the ledger and skip what is already there, or the loop re-triages the same historical finding on every entry and halts before it reaches the current review. Inline findings need no such record, because the thread already holds the answer.

  2. +1 newer than BASELINE_PLUS_ONE, still the only signal after a settle window, and no untriaged blocking finding anywhere on the PR → converged. Stop and report. An advisory-only round after the polish budget is spent converges too, +1 or no +1.

    The last clause is what stops a clean head from closing a round that still owes an answer. Push A, B and C, triage A, push fix D: the watch list is now D, and B's untriaged findings have fallen out of it, so a clean verdict on D would end the loop with B unanswered. Do not fix that by carrying SHAs forward in the ledger; use the ground truth that Step 1 already computes, the bot's top-level comments minus the ones replied to. A register can go stale, and the thread cannot. The second half is not ceremony: the reaction is global, so on a multi-commit push an intermediate run's clean +1 arrives while the head's run is still queued. Give it the same sustained quiet the pre-push wait demands, and treat any eyes appearing in that window as proof the round was not finished.

  3. eyes on the PR body → still running. Sleep again without counting it against the start-up deadline, capped at ~10 wake-ups so a bot that dies mid-run cannot hold the loop open forever.

  4. None of the above → Codex has not started yet. Sleep again, up to 4 wake-ups (~20 min); past that, stop and say plainly that no verdict landed for $PUSHED_SHA rather than reporting it as clean.

If eyes clears and neither a review for $PUSHED_SHA nor a fresh +1 appears, stop and report it as indeterminate. That combination should not happen, so do not paper over it with an assumption in either direction.

Stop conditions

Keep the round counter and the findings ledger at $(git rev-parse --git-path pr-autofix-<NUMBER>.json), which is local by construction and never committed. Resolve it with git rev-parse rather than writing .git/... directly: in a linked worktree or a submodule checkout .git is a file, so the hardcoded path cannot be created and the loop loses its round counter in exactly the setups an agent is most likely to be handed. Halt on the first of these and report why:

Condition Why it stops
Fresh +1 on the PR body Codex is clean. This is the success exit.
No signal at all after 4 wake-ups Codex never started. Do not guess a verdict.
eyes never clears after ~10 wake-ups The run stalled. Hand back rather than wait on.
eyes cleared with no review and no +1 Indeterminate, and should not happen. Report it.
Every finding rejected No fix means no commit, so there is nothing to re-review.
Test suite red Never push a broken branch.
Push guard refused Diverged upstream, missing upstream, or main.
A finding contradicts an earlier round's fix where it was applied. The same class as an earlier round's is not enough That fix was supposed to make this finding impossible, so another automated attempt will not either.
Round 5 reached Backstop against a loop that will not settle.

The repeat condition is a class, and only a reader can judge it. Codex issues a fresh id for the same underlying claim each round, so id-based dedup never fires. A content hash does better and is worth keeping as a cheap exact-match check, path plus a hash of the normalized body, appended for every finding you reply to:

printf '%s' "$BODY" | tr -s '[:space:]' ' ' | shasum -a 256 | cut -c1-12

But do not mistake it for the guard. It catches only a reviewer restating a claim verbatim, which is the rare case, and nearly everything it misses is work worth doing rather than a halt worth firing. What it misses most often is a fix that relocates the defect: it draws a differently worded finding, hashes differently, and sails through. PR #70 is the worked example, and it is a worked example of a false halt. Round one agreed with both process findings and shipped fixes that moved each hole one step over, so round two described two defects in that new place, six findings produced six distinct hashes, and the loop stopped anyway because it read them as the same class. Marco overrode the halt and round three fixed all of them. The same thing happened at rounds four and six: three halts, three overrides, every finding eventually fixed, and not one circular argument prevented. A relocated defect is new work, so catching it is not what the guard is for.

So the question at the top of every round is a judgment call, not a lookup, and it is asked against what an earlier fix claimed to change, never against the goal that fix served: is the reviewer saying that specific claim is factually unmet, in the place it was applied? If yes, stop.

A new instance of a known class is not a repeat. The judgment has to be made at claim altitude because the ledger's class labels are written well above it, on purpose: "verify the PR is the right PR" usefully covers four rounds of distinct defects for a reader, but asked at that altitude, every later finding touching the same subsystem matches something already recorded. Classes only accumulate, never retire, so a guard reading at class altitude fires on round two of every run and then keeps firing. That is not convergence, it is the loop refusing to work: round two of PR #70's live run halted before Step 4, so no fix was written and autofix_push.sh was never even called, and the same halt came again at rounds four and six. Round seven shows how wide the false match gets. Three findings, every one of them a first-time defect, and all three matched an existing class label.

A finding is a new instance, to be verified, fixed and pushed like any other, when any of these holds:

  • the earlier fix's own claim still holds where it was applied, and this is a different claim about the same code. Round six of PR #70 made a comparison run in both directions; round seven found that comparison reading a cached ref that a concurrent push invalidates. Same lines, different defect;
  • it is about code that did not exist when that fix was written;
  • the earlier fix was correct where it was applied, and this is the same idea missing somewhere else, including one file over.

It is a repeat, and it stops the loop, only when the reviewer contradicts an earlier fix's own claim at the place that fix was applied: the change was made, it was supposed to make this finding impossible, and the reviewer says it did not. One recurrence is enough there, because the evidence is that specific. Anything looser has no true positives to its name. Across seven rounds of PR #70 the class-altitude version fired three times and was wrong three times, and each halt was overridden by hand before the findings got fixed.

Record both kinds in the ledger: the class with the round that first raised it, and for a repeat the round whose fix it contradicts, so the next round inherits the judgment instead of re-deriving it. Round 5 is the backstop for a run that keeps finding new instances, which is what it is for.

Mark the exit so a human can see it

A loop that ends quietly leaves the PR looking identical to one still mid-review. On a converged exit, label it:

tools/github/autofix_mark_converged.sh NUMBER

That is a script and not a bare gh pr edit for one reason: the label may not outrun the head it describes. A round that rejects every finding converges without a fix, but it still writes a Step 5 closeout commit and leaves it unpushed, and labelling there marks the PR approval-ready with a commit nobody has reviewed in front of it. Pushing that commit later goes around autofix_push.sh, which is what would otherwise have cleared the label. The script refuses on a dirty tree or anything unpushed, so the precondition is enforced rather than remembered.

Converged means the automated review cycle is genuinely finished: a fresh +1, or a round in which every finding was verified false. Both mean the same thing to a human, which is that nothing is left for the reviewer and the PR is waiting on them.

Do not apply it on an abnormal exit (red suite, refused push guard, repeated finding, no verdict, round cap). Those need attention rather than approval, and labelling them approval-ready is worse than leaving them bare, because it converts "the loop gave up" into "the loop signed off".

Label them the other way instead:

tools/github/autofix_mark_attention.sh NUMBER "<why it stopped>"            # needs-attention
tools/github/autofix_mark_attention.sh NUMBER --blocked "<why it stopped>"  # verdict-blocked

Use --blocked when the halt leaves confirmed P0 or P1 findings outstanding, and the bare form for everything else. The two share every precondition and differ only in which label a human should read, which is the whole reason the blocked state exists: without it a halt with blockers left over looks exactly like one with none.

Leaving an abnormal exit bare was the same ambiguity status:to-approve was added to remove, one case over: a halt looked exactly like a loop nobody had started. status:needs-attention is the other half of the pair, and the two are mutually exclusive, so each script clears the other's label and a new round clears both. The reason is required, because a flag that says "look at this" without saying at what is barely better than the silence it replaces.

It carries none of the converged script's preconditions on purpose. Approval is a claim about a specific reviewed head, so it demands a clean tree and nothing unpushed; "a human should look" is true whatever the tree looks like, and most halts happen with a closeout commit sitting unpushed. Requiring a clean tree there would make the label unreachable in exactly the case it exists for. The label is also removed before pushing a new round, so it never outlives the state it describes.

The exit report is not a PR comment. Report it in the terminal to whoever invoked the loop, and durably in the Step 5 obsidian_vault/log.md entry, which already owns the round-by-round record. Never post a top-level summary comment on the PR: no round table, no ledger, no rationale, however interesting the run was. Three of them landed on PR #70 at 2,700 to 3,400 characters each and buried the threaded replies from Step 3 that are the actual review response. What the PR carries is those per-comment replies, the commits, and on a converged exit the label. That is the whole visible surface and it is enough for a human to see where the loop stopped.

On a converged exit, label before writing the closeout. The order is forced, not stylistic. The closeout appends to obsidian_vault/log.md, which dirties the tree, and committing it leaves HEAD unpushed; autofix_mark_converged.sh refuses in both states, so writing the closeout first makes the success label unreachable on every clean verdict. The one moment the guard can pass is immediately after the verdict, while the tree is still clean and the reviewed head is still the live head. So: verdict, then label, then write and commit the closeout under the Step 6 default.

A clean verdict is not itself a round, so it adds no new log.md entry. Without that, the final closeout can never be both on the remote and terminal: push it and the label is cleared and a fresh run triggered, a clean result demands its own closeout, and that is another commit. The round that pushed the last fix already has an entry saying what it pushed and what it was waiting for; a clean verdict completes that entry rather than starting another. Report it in the terminal, add the outcome to the existing entry only if a later commit touches log.md anyway, and stop.

One residual, stated rather than papered over. That closeout commit sits unpushed in front of an approved PR. Pushing it through autofix_push.sh clears the label first, which is correct, but a manual git push does not, and the label is then stale. A label cannot be scoped to a SHA on GitHub, so this cannot be closed in the tooling; what closes it is pushing a converged branch through the script like any other round.

status:to-approve lives in .github/issue-labels.json. It survives the issue-label resolver because the resolver's managed set is enumerated (status:needs-triage and the form-emitted groups) rather than derived from the catalog, which test/python/test_issue_labels.py pins in test_a_status_outside_the_managed_set_survives_a_form_edit.

The human control plane

GitHub is where a human sees and steers the loop; the ledger is only the loop's own memory. The three result labels are mutually exclusive and are terminal: they say what a person should do now, so they go on when the loop stops, not while it works. A round in progress is already legible from Codex's eyes reaction and the absence of any of them.

State Marker Meaning
Review running eyes, no label The loop is waiting. Nothing for a human to do
Stopped, blockers outstanding status:verdict-blocked P0 or P1 left unfixed. A human decides how to proceed
Stopped, nothing blocking status:to-approve The automated cycle is finished; the merge decision is human
Stopped, abnormal or ambiguous status:needs-attention Something needs looking at before anything else happens
Paused by a human status:on-hold Set by a person, never by the loop

Every push clears all three result labels first, which autofix_push.sh enforces.

status:on-hold is a stop switch, and it is checked before every outward action: before a push, before any label edit, and at the top of each round. Local work is cheap to discard, so it is not checked before every edit to a file; what must never happen is the loop acting on the world after a person asked it to wait.

Follow-up issues

The loop does not open issues. Not yet, and this is a considered starting point rather than an oversight.

The gates for a good follow-up are all judgement calls: confirmed with a concrete case, reproduces unchanged on main, actionable, not a duplicate, groupable by root cause. Judgement is the category this loop has needed several rounds to get right every single time, and the asymmetry is unforgiving: a wrong label is retracted in a second, while a wrong issue sits in everyone's tracker.

So when a finding is confirmed but not caused by this PR, verify it against main, say so in the thread, and leave the decision:

Confirmed, but it reproduces on main and is not introduced by this PR. Non-blocking here, and a follow-up candidate rather than something I have filed.

Record the candidate in the round's log.md entry. If the loop's candidates turn out to be the ones a human would have filed, automatic filing can be switched on later behind the limits already agreed: one issue per root cause, at most two per PR, and status:needs-attention instead of a third.

Whether a finding belongs to this PR at all:

Check Decision
Introduced or made worse by this PR Stays in the PR
Reproduces unchanged on main Follow-up candidate
An improvement with no concrete failure Skip, and say so
Pre-existing but P0 or P1 status:needs-attention, human decides

What the loop must never do

  • Widen scope. Every round obeys Step 4's TDD rules and the no-new-findings rule; an autofix round is not a licence to tidy something the reviewer did not raise.
  • Rewrite pushed history. Each round is a new numbered commit, exactly as in Step 6.
  • Run unattended past a stop condition. Ending the loop with a report is the correct outcome, not a failure to persist.

Rules

  • Verify before agreeing. Every time.
  • A confirmed finding whose suggested fix is wrong still gets a thumb up, and a reply explaining the different fix.
  • Report the suite output honestly, including failures.
  • Do not expand scope. Findings the reviewer did not raise go to the user as a note, not into this commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment