Repository navigation
feat(review): fall back to the next reviewer backend, ending with Claude Code - #679
Merged
Merged
Conversation
…ude Code When GLM was made the default (#675), a colleague without a GLM key file got a failed review at once: there was no fallback. - Each reviewer now tries the backends in order: the chosen one, then OFFLOAD_FALLBACK (default "bob claude"). So the default order is glm, then bob, then claude. - The next backend runs only when the reviewer has not posted a review of this round and head. A reviewer never posts twice. - A backend may define backend_ready. One that is not set up (no key file, no bob command) is skipped without a run. - Each backend has its own worktree, review-pr<N>-<backend>-r<1|2>, so its session files never mix with another backend's. - In round 2 each reviewer starts with the backend that wrote its round-1 review, so it resumes that session. - The marker names the backend that wrote the review, and the last line lists the backend of each reviewer. - --no-fallback (or OFFLOAD_FALLBACK="") turns it off, to compare one backend with another. - New backend claude.sh: the user's own Claude Code, with OFFLOAD_CLAUDE_MODEL to pick the model. - Worktree creation takes a lock, because with fallback the two reviewers can create worktrees at the same moment. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Oct 23, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | f067b21ec176 |
blocking |
Verdict: blocking
Findings
- scripts/offload-review.sh:184-187 —
posted_nowcan say "not posted" when the review is posted, so the next backend posts a second review- What fails: a reviewer posts its review, then
posted_nowchecks the PR.grep -qexits as soon as it finds the marker. Ifghis still writing review bodies at that moment, it gets SIGPIPE and exits 141.set -o pipefail(line 43) makesposted_nowreturn 141.run_reviewerreads that as "not posted" and runs the next backend for the same reviewer. That backend posts a second review of the same reviewer, round and head. The script then exits 0 and reports success. This breaks the rule "a reviewer never posts twice", and it costs a full extra review run. - Proof: the mechanism, on this machine with
/bin/bash3.2.57 and the default grep:Output:set -euo pipefail posted_now() { { printf 'match early\n'; head -c 200000 /dev/zero | tr '\0' 'x'; } | grep -q 'match early'; } if posted_now; then echo posted; else echo "not posted (rc=$?)"; fi
posted: NO (rc=141). The match was found; the pipeline still failed. In the real call,gh api --paginatewrites each review body as its own output, so any bytes after the marker (the rest of that review, later reviews, a next page) givegha write that fails aftergrepexits. It is a race: it needs enough text after the marker to span a write. Review bodies of a few KB, and more rounds, make it more likely. The same fetch at line 316 is safe, because command substitution reads all output before grep runs. - Fix: read the whole output first, then grep, in the style of
posted()at line 123:posted_now() { local now now=$(gh api --paginate "repos/$repo/pulls/$pr/reviews" --jq '.[].body') grep -qE "<!-- offload-review reviewer=$1 round=$round sha=$sha backend=[a-z0-9_-]+ verdict=(approve|blocking)" <<<"$now" }
- What fails: a reviewer posts its review, then
Non-blocking
- scripts/offload-review.sh:208 — exit code 4 means "backend not set up" only by contract.
attemptalso returnsbackend_run's own exit code. A reviewer tool that itself exits 4 is reported as "not set up", with no review.log path in the message. Pick an exit code the tools cannot return, or haveattemptwrap the tool's code. - scripts/offload-review.sh:191-198 and 329-330 — the marker greps scan whole review bodies. From round 2 on, a review may quote another reviewer's marker line. The quote then matches too, and
tail -1can pick the quoted backend. Effect: round N+1 starts with the wrong backend first, or the summary line names the wrong backend. Low harm: the review still posts, only the resume order can be wrong. Anchoring the grep to line 1 of a body would need a different fetch; at least keep this in mind. - scripts/offload-review/backends/glm.sh:3 and bob.sh:3, and SKILL.md "Add a backend" — these still say a backend defines "one optional" function.
backend_readyis a second optional one now. Update the three headers so a new backend author learns aboutbackend_ready. - The new fallback logic (chain order,
posted_now, worktree lock) has no tests. The repo has no shell test harness at all, so this matches current practice. The pure parts (chain_for, the marker parsing) could be tested if a harness ever appears.
What I checked
- The full diff of head f067b21 against base 40868e3:
SKILL.md,offload-review.sh, and the three backends, line by line. - The whole current
scripts/offload-review.sh,backends/glm.sh,backends/bob.sh,backends/claude.sh,SKILL.md,review-prompt.md, anddocs/design.md. - Every call site of
wt_ofafter its argument order changed from<reviewer>to<backend> <reviewer>: all consistent (lines 167, 210, 288, 320). - The fallback invariants the PR promises: dedup of the chain (line 71-72), per-reviewer fallback, "never posts twice" via
posted_now, round-2 resume order viachain_for. The first three hold; theposted_nowrace above breaks the last two under the conditions given. - Session survival across rounds:
git clean -e .glm-cc/ -e .claude-review-session(line 174) keeps the glm and claude session state; bob keeps its sessions outside the worktree. The changed-files allowlist (line 325) covers both new names. - The cleanup path (lines 98-111) with the new per-backend worktree names, and the
claude.shcleanup guards on the session id. - Bash semantics on this machine, with tests, not by reading alone: empty-array expansion under
set -uinchain_for(safe in bash 3.2.57 and 5.2), and thegrep -q+ pipefail race in finding 1 (reproduced, rc=141). - Did not run the script itself, any Go build, or any remote-box test: live tests are not approved, and this PR touches no Go code.
amiddavid
commented
Oct 23, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | f067b21ec176 |
blocking |
Verdict: blocking
Findings
- scripts/offload-review.sh:185 —
posted_nowcan call a posted review "not posted", so the next backend runs and posts a duplicate review.- What fails:
gh api ... | grep -qruns underset -o pipefail(line 43).grep -qexits at the first match and closes the pipe. Ifgh apiwrites after that, it dies of a broken pipe (SIGPIPE, exit 141). A failedgh apicall gives the same result.pipefailthen makes the whole pipeline non-zero, soposted_nowreports false even though the review is on the PR.run_reviewer(lines 281-290) records a failure and starts the next backend. That backend writes and posts a second review of the same reviewer, round and head. This breaks the invariant "a reviewer never posts twice" (SKILL.md) and spends a second full model run, with no error reported. - Proof: the mechanism, run on this machine:
$ bash -c 'set -uo pipefail prod() { printf "%s\n" "MARKER"; sleep 0.3; python3 -c "print(\"x\"*200000)"; } if prod | grep -q "MARKER"; then echo MATCH; else echo "FALSE NEGATIVE rc=$?"; fi' FALSE NEGATIVE rc=1grep -qmatched, the producer then hit the closed pipe, andpipefailturned the match into a false negative. Code trace: line 43 setspipefail; lines 184-187 pipegh apiintogrep -q; line 281if posted_now "$r"takes the false branch; lines 285-290 continue the loop overchain_for. Honest trigger analysis: the API lists reviews oldest first (checked on PR #675), so the marker usually sits near the end of the stream and the pipe drains. The realistic doors are (a) any transientgh apifailure at exactly this call, and (b) more than the 64 KiB pipe buffer of review text after the marker line — two long reviews posted by the two parallel reviewers can approach that. Both are silent. - Fix: buffer the answer before grepping, and fail safe on a
gherror — an uncertain answer must stop the chain, not start another backend. The final check (lines 316-331) still reports a truly missing review with exit 1:This also matchesposted_now() { local now now=$(gh api --paginate "repos/$repo/pulls/$pr/reviews" --jq '.[].body') \ || { echo "posted_now: gh api failed; assuming posted, not trying the next backend" >&2; return 0; } grep -qE "<!-- offload-review reviewer=$1 round=$round sha=$sha backend=[a-z0-9_-]+ verdict=(approve|blocking)" <<<"$now" }
posted()at line 123, which greps a saved string.
- What fails:
Non-blocking
- scripts/offload-review.sh:280 —
attempt "$r" "$b" || rc=$?disablesset -eand the ERR trap for the whole ofattempt. Verified on this machine: afalseinside a function called in a||list does not stop the function. Before this PR, the reviewer function ran backgrounded, whereset -eapplied: a mid-function failure aborted the run with the trap message. Now a failure ingit merge-base(line 230) or while writing.review-prompt.md(lines 232-269) is swallowed, and the backend runs on a broken prompt (for examplegit diff ..HEADafter a failedmerge-base). I found no likely trigger — the fetch at line 156 makes amerge-basefailure implausible — but the safety net is gone. Considerset -eexplicitly inside the subshell at line 205. - Doc drift around
backend_ready. SKILL.md "Add a backend" (line 165) still says "three functions, and one optional one" and omitsbackend_ready;backends/glm.sh:3andbackends/bob.sh:3say "one optional one" too, whilebackends/claude.sh:3-8documents two. Also the script header (line 35) still says exit 1 means "a reviewer failed", while SKILL.md now says "No backend posted a review for a reviewer". - scripts/offload-review.sh:288 — the failure message names
review.logeven when none exists. Whenensure_wtfails (line 209), the attempt exits before any log is written in that worktree, so the path intriedpoints at nothing. - backends/claude.sh runs with the user's own Claude Code settings. That is its stated purpose, but it also means the reviewer's traffic goes through whatever endpoint the user's settings define — here, Context Guru, a lossy context-management proxy. The glm backend isolates its config for exactly this reason. Worth a sentence in the backend header, so a user who sees odd review quality knows where to look.
- scripts/offload-review.sh:319 — the final audit checks only worktrees of backends in this run's
chain. A worktree left by an earlier run with a different--backendis skipped even if its prompt names this round and head. Only an audit hole; the reviewer that ran there was checked by that run.
What I checked
- Read
CLAUDE.md,docs/design.md, the full diff (40868e38..HEAD), the whole currentscripts/offload-review.sh, all three files inscripts/offload-review/backends/, and the changed parts of.claude/skills/offload-review/SKILL.md. - Traced every call site of the new
wt_of <backend> <reviewer>argument order; the cleanup glob and its backend-name parsing; theensure_wtlock (creation, 60 s timeout, release on failure) and thegit cleanexcludes (.glm-cc/,.claude-review-session);chain_for(prev-backend extraction from markers, dedup, round-2 ordering);attempt(ready check, worktree, prompt build, session resume, exit-code-4 protocol);run_reviewer(posted check,triedmessages); the final verification loop (worktree selection by prompt grep, changed-files allowlist, HEAD check,usedreport); the round/todo/--same-headlogic (unchanged by this PR). - Checked the claude backend for safety: the session-id regex guard before
find -delete, thermguards, sid file handling acrossgit clean, and--maxdepth 2against Claude Code's projects layout. - Checked the SKILL.md claims against the code: default order glm→bob→claude, per-reviewer fallback, "never posts twice" (broken by finding 1), round-2 resume of the round-1 backend,
--no-fallback, exit-code table, cleanup list. - Ran no Go builds or tests (not approved). Ran two local shell simulations only; they touch no repo code. Confirmed the GitHub reviews API order on PR #675 (a different, merged PR; I did not read this PR's reviews or comments).
- Found no test infrastructure for this script in the repo, so I do not count missing tests as a finding.
Found by both GLM reviewers of #679, round 1. Under pipefail, `gh api ... | grep -q` fails with SIGPIPE when gh writes after grep has matched. A posted review then reads as missing, and the next backend posts a second review of the same reviewer. posted_now now saves the answer, then greps it, as posted() does. A gh failure counts as posted, so an uncertain answer stops the chain. The final check still reports a review that is really missing. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
|
Author reply to both reviewers, round 1 (head Reviewer 1, finding 1, and reviewer 2, finding 1 (the same bug):
|
amiddavid
commented
Oct 23, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | ed20f9da65ba |
approve |
Verdict: approve
Findings
None. The one blocking finding of round 1 is fixed, and I verified the fix myself (below).
Status of the round-1 findings
- Mine, finding 1, and reviewer 2, finding 1 (the same bug):
posted_nowcould read a posted review as missing, so the next backend would post a duplicate. Fixed ined20f9da.- The fix matches what both reviews proposed:
posted_nowsavesgh's whole answer in a variable, then greps it (scripts/offload-review.sh:188-193). No pipe intogrep -qis left. - I verified the mechanism myself, on this machine with
/bin/bash3.2.57:- The old form, on a match with the producer still writing:
posted: NO (rc=141)(round 1). - The new form, same producer:
posted: yes. - A
ghfailure: prints "could not read the PR's reviews; not trying another backend" and returns 0, so the chain stops.
- The old form, on a match with the producer still writing:
- I checked the "counts as posted" choice for false success. It cannot hide a missing review. The final check (lines 321-336) fetches the reviews again and prints "Reviewer r did not post its review" with exit 1. If
ghfails there too,set -eends the script with exit 1. Both paths report the problem. - I checked the author's claim "No other
| grep -qis left in the script or the backends": true. The remaininggrep -qcalls (lines 123, 192, 328, and bob.sh:25) all read a saved string, a here-string, or a file. None is on the right of a pipe.
- The fix matches what both reviews proposed:
- My non-blocking notes and reviewer 2's non-blocking notes: not fixed, not rejected. The commit changes only
posted_now. These notes stay open for a later change; none blocks this PR:- Exit code 4 from a reviewer tool reads as "not set up" (mine).
- Marker greps scan whole review bodies, so a quoted marker can mislead
chain_for(mine; harmless here: this round's run picked glm, the backend I used in round 1, as intended). - Doc drift:
backend_readymissing from the "Add a backend" docs and from the glm.sh and bob.sh headers (mine and reviewer 2's). attempt "$r" "$b" || rc=$?disablesset -einside the attempt (reviewer 2; I checked their reasoning and agree, and agree no likely trigger exists).- The failure message names
review.logeven when none exists (reviewer 2). - The claude backend runs through the user's own endpoint (reviewer 2; stated purpose of the backend).
Non-blocking
- scripts/offload-review.sh:282 — when
posted_nowreturns 0 becauseghfailed, and an earlier backend was tried,run_reviewerprints "posted with $b". The message before it says the reviews could not be read, so the operator is not misled. A clearer wording would say "unknown".
What I checked
- Last review: round 1, f067b21, 2026-10-23T10:20:56Z.
- New commits read: 1 (
ed20f9dafix(review): read the PR's reviews whole before grep in posted_now). Full diff read; onlyposted_nowand its comment changed. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (10:21:55): read in full. Its blocking finding is the same bug as mine; fixed. Its non-blocking notes are listed above with a status.
- Author reply (10:23:24): read in full. It states the fix, the "gh failure counts as posted" choice, and the "no other
| grep -q" claim. I verified each claim myself; all three hold. - Commit
ed20f9da: reviewed as a first review would. The change is small and correct; the commit message follows the repo rules (conventional title,Signed-off-by,Assisted-By).
- Ran local shell simulations of the new
posted_now(match path andgh-failure path) with/bin/bash3.2.57, the shell this machine runs the script with. No Go builds, no remote-box tests: live tests are not approved.
amiddavid
commented
Oct 23, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.309 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | ed20f9da65ba |
approve |
Verdict: approve
Findings
None.
Earlier findings
- My finding 1 and reviewer 1's finding 1 (the same bug):
posted_nowcould read a posted review as missing, so the next backend posted a duplicate. Fixed ined20f9da65ba.- The new form saves the whole answer with command substitution, then greps it.
grepruns only afterghfinished, so no broken pipe. Verified with the round-1 reproduction, reshaped for the new form: the match now reads "MATCH (fix works)" where the old form read "FALSE NEGATIVE". - A
ghfailure now returns 0, so an uncertain answer stops the chain instead of starting another backend. Verified that path too: it returns 0. The final check (lines 316-333 in the new file) still reports a truly missing review with exit 1, and a failure of that fetch aborts the script underset -e. The fail direction is now safe in every case I can reach. - The author's claim "no other
| grep -qis left" holds: every remaininggrep -qin the script and the backends reads a saved string or a file, never a live pipe.
- The new form saves the whole answer with command substitution, then greps it.
Non-blocking
The round-1 non-blocking notes are still open. None blocks the merge; the author did not reply to them, and this round's budget is used.
- Doc drift, flagged by both reviewers:
backend_readyis missing from SKILL.md "Add a backend" and from theglm.sh:3andbob.sh:3headers; the script header (line 35) still words exit 1 as "a reviewer failed". - Reviewer 1's note on exit code 4: a reviewer tool that itself exits 4 reads as "not set up". Agree after checking
attempt— the code passesbackend_run's status through. - Reviewer 1's note on quoted markers in
chain_forand the summary line: agreed as low harm; the grep pinsreviewer=$r, so a wrong backend needs a quoted marker of the same reviewer with a different backend. - My round-1 notes that stay:
attempt ... || rc=$?disablesset -einside the attempt; the failure message at line 288 can name areview.logthat does not exist; the claude backend inherits the user's endpoint; the final audit skips worktrees of backends outside this run's chain.
What I checked
- Last review: round 1, f067b21, 2026-10-23T10:21:55Z.
- New commits read: 1 —
ed20f9da"fix(review): read the PR's reviews whole before grep in posted_now". Read the full diff and the changed function in the file around it. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files; the inline file is empty).
- New items since my last review, and what I did:
- Commit
ed20f9da: reviewed line by line. It changes onlyposted_now. Checked both exit paths (answer read whole;ghfailure returns 0), thelocal nowon its own line, and that the error message goes to stderr. No regression found:posted_nowis used only byrun_reviewer, and the final verification still catches a missing review. - Author's comment at 10:23:24: checked each claim. The fix matches the description; the "no other
| grep -q" claim verified by grep over the script and the backends. - Reviewer 1's round-1 review (posted at 10:20:56, before my round-1 review; I read it now for the first time): its finding 1 is the same bug as mine, now fixed. Its non-blocking notes checked as described above; I do not repeat them as findings.
- Commit
- Ran no Go builds or tests (not approved). Ran two local shell simulations of the fixed function only; they touch no repo code.
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
claudeis the user's own Claude Code, so it is the Anthropic fallback.What changed
scripts/offload-review.sh:OFFLOAD_FALLBACK(defaultbob claude).backend_ready.review-pr<N>-<backend>-r<1|2>, so the session files of 2 backends never mix.(reviewer 1: glm reviewer 2: bob).--no-fallback, orOFFLOAD_FALLBACK="", turns it off. Use it to compare one backend with another.backends/claude.sh(new): runsclaude -pwith the user's own login.OFFLOAD_CLAUDE_MODELpicks the model.backends/glm.sh,backends/bob.sh: addbackend_ready.SKILL.md: documents the fallback and theclaudebackend.How it was tested
The real script ran in a scratch git repo, with a fake
ghand 3 fake backends. Each fake backend can be marked "not set up" or "fails". No model was called.review.log--no-fallback, glm failsresume=1--cleanupbash -npasses on the script and all 3 backends.🤖 Generated with Claude Code