Repository navigation
fix(review): stop a reviewer that never ends, and never resume a failed run - #697
Conversation
…ed run On #507 a GLM reviewer repeated one word up to the 32k output limit, 4 turns in a row, about 21 minutes each. Nothing stopped it, and a later round would have resumed that same session. - Each reviewer run now has a wall-clock limit, OFFLOAD_REVIEW_TIMEOUT (default 1800 s, 0 = off). Past it, the script stops the run's whole process group and falls back to the next backend, unless the review is already on the PR. It does not limit tokens. - A run that ends without posting drops its saved session (backend_forget_session, or backend_cleanup), so the next round starts fresh. - Any .review-in-*.txt in a reviewer's own folder is allowed. A reviewer that also saved the PR body (.review-in-prbody.txt, #508) made the round exit 1 although both reviews posted. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | e373014f3b49 |
approve |
Verdict: approve
Findings
None. The change works as documented. I verified the hard parts by running them (see below).
Non-blocking
- scripts/offload-review/backends/claude.sh:3 — the header count is stale. It says "three functions, and two optional ones", but the list below it now has three optional functions (
backend_ready,backend_cleanup,backend_forget_session). Same in glm.sh:3 and in SKILL.md "Add a backend" ("one optional one", two listed). Fix: update the counts, or drop them. - scripts/offload-review.sh:338 — a backend that exits 124 by itself reads as a timeout.
run_limitedreturns 124 both for a timeout and for a child that exits 124 on its own. In the second case,attemptappends a falsestopped after <N>sline toreview.log, and thetriedline saystimed out. I found no backend that exits 124 today, so the risk is low. Fix: use a marker the backends cannot return (for example 125), or print the elapsed time. - scripts/offload-review.sh:335-336 —
OFFLOAD_REVIEW_TIMEOUTis validated inside each attempt. A bad value fails every backend in the chain, one after the other, and each failure also drops that backend's session (forget_session). Fix: validate once at startup, before any reviewer runs. - scripts/offload-review.sh:365 —
forget_sessionalso runs when the attempt failed beforebackend_runstarted. A failure inensure_wtorcd(exit 1) drops a good round-1 session, although no review run happened. The result is a fresh round 2, which the later-rounds prompt supports, so no data is lost. It is stricter than the stated rule ("a run that ends without posting"). - scripts/offload-review.sh:338 —
> review.logtruncates the log and drops earlier diagnostics.backend_has_session 2>>review.log(line 279) writes bob's--list-sessionserror there first;run_limited ... > review.logthen wipes it. This is pre-existing: the oldbackend_run ... > review.loghad the same effect. Fix in a later change: use>>. - No automated test for
run_limitedorforget_session. The repo has no shell-test harness at all, so this matches current practice.run_limitedis subtle shell (process groups, traps), so a regression would be silent. Worth a harness if scripts grow more logic.
What I checked
- Read the full diff (4 files) and the whole
scripts/offload-review.sh, all three backends, SKILL.md, andreview-prompt-later-rounds.md. - Ran
run_limitedin isolation (local bash, no Go): a child exit code passes through (7); a timeout returns 124 and kills the whole tree, including a grandchildsleep 30(no leak); the child gets a process group of its own, apart from the parent's. - Ran
run_limitedinside a nested background subshell, as the real script calls it (run_reviewer &→attempt→run_limited): the reviewer is killed, and an unrelated background job in the main group survives. Sokill -- "-$pid"cannot hit the script's own group. - Checked trap handling: the INT/TERM trap is cleared on both exit paths; the parent's EXIT trap does not fire in the attempt subshell, so
skipdirsurvives concurrent reviewers. - Checked
forget_session: argument order ofwt_ofis correct; it runscdbefore the backend's$(pwd -P)-based helpers; the bob fallback tobackend_cleanupis guarded; a not-set-up backend (exit 4) keeps its session; a run that posted keeps its session (posted_nowruns first, and a gh read failure counts as posted). - Checked the widened file rule
.review-in-[a-z0-9-]+.txt: it still matches only root-level names, keeps the three documented names, and fixes the #508 false exit 1. - Checked the timeout race: a review posted just before the deadline is accepted (
posted_nowruns beforeforget_session), and the stray "stopped" message is stderr only. - No Go code changes, so no data-dependence update is needed and no Go tests apply.
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | e373014f3b |
blocking |
Verdict: blocking
Findings
- scripts/offload-review.sh:365 —
forget_sessiondrops a saved session even whenbackend_runnever ran.- What fails:
run_reviewercallsforget_sessionfor anyrc != 4when no review was posted. Butattemptalso exits 1 on failures that happen beforebackend_runstarts: theOFFLOAD_REVIEW_TIMEOUTvalidation (line 336),ensure_wt(line 273), thecd(line 275), and the prompt write (line 296-333). In those cases the session is not "the one that failed" — no run happened — yet it is deleted. Worst case: a typo likeOFFLOAD_REVIEW_TIMEOUT=30min round 2. Every backend in the chain fails at validation before running, and each one loses that reviewer's round-1 session (glm:.glm-cc/session-id;claude:.claude-review-session;bob: the whole~/.bob/tmp/<hash>dir via thebackend_cleanupfallback). The script exits 1 with a clear reason, the user fixes the variable and re-runs, and both reviewers start round 2 fresh. The round-1 context is gone, with no message about that loss. The same holds for anensure_wtfailure (worktree lock held over 60 s) in round 2. - Proof: trace —
attempt(line 336)exit 1→run_reviewerline 362rcis 1, not 4 → line 365forget_session "$r" "$b"→ the backend'sbackend_forget_session/backend_cleanupremoves the session.backend_runat line 338 was never reached. This contradicts the commit's own intent: "does not resume a session that may be the one that failed" — here it certainly was not. - Fix: validate
OFFLOAD_REVIEW_TIMEOUTonce at startup, next to the backend-name checks (lines 82-92), so a bad value stops the script before any session is touched. And forget a session only whenbackend_runactually ran — for example,attemptwrites aranmarker into$skipdirafterrun_limited, andrun_reviewercallsforget_sessiononly when that marker exists.
- What fails:
Non-blocking
backends/claude.sh:46— afterbackend_forget_session, the old session's transcript stays under~/.claude/projects/<worktree-path>/, and--cleanupnever removes it:backend_cleanupdeletes only the session that the current.claude-review-sessionnames, which is the new session by then.glmhandles this deliberately (transcript kept in.glm-cc/for diagnosis, removed by--cleanup). Forclaudethe forgotten transcript is neither kept by design nor removed. Small disk and hygiene leak, on the user's own machine.scripts/offload-review.sh:229-240— a run that finishes on its own in the same second the limit is reached getsrc=124and the "timed out" label instead of its real exit code. If it posted,posted_nowstill protects it, so only the log line is wrong. Cosmetic.- SKILL.md says "stopped with all its processes". That holds for the process group (verified below, including children started with
&inside the run). A process that moves itself into a new process group would escape the kill; no current backend does that.
What I checked
- The full diff (4 files) and the whole content of each:
offload-review.sh, both changed backends,SKILL.md. - The code around every change:
attempt,run_reviewer,chain_for,posted_now,ensure_wt, the final worktree checks;backends/bob.sh(unchanged, but thebackend_cleanupfallback inforget_sessionruns it);review-prompt.mdandreview-prompt-later-rounds.md(to check the widened.review-in-*allowlist against the files the prompts actually write). - The
.review-in-[a-z0-9-]+.txtwidening: justified — the commit message names the incident (#508) where a reviewer's own.review-in-prbody.txtmade the round exit 1. The three filenames the later-rounds prompt writes all match. run_limitedverified by running it on this machine, in the same nesting as the real script (background subshell,||context), under both/opt/homebrew/bin/bash5.2 and/bin/bash3.2:set -min the subshell gives the backgroundedbackend_runits own process group on both versions.- A group TERM kills the job, its foreground children and its
&children — all stay in the group. Nothing of the run survives. - Exit codes propagate: success → 0, failure → the real code (7 in the test), fast failure before the limit → the real code, not 124. No zombie is left on either path.
- The TERM-then-KILL-after-5s order also covers a stopped (SIGSTOP) process.
- The timeout/fallback/forget flow against the SKILL.md text:
posted_nowruns beforeforget_session, so a run that posted but exited non-zero (including 124) keeps its session; a not-set-up backend (rc 4) keeps it too; gh read failure counts as posted. All match the documented behavior. forget_sessionpaths for all three backends: correct worktree (cdbeforepwd -P-based helpers), guardedrmin each backend.- No Go builds or tests were run (not approved). No live
claude/bobruns; therun_limitedtests usedsleeponly.
Round-1 review fixes for #697. - Forget a saved session only when the backend started. A failure before it (worktree lock, prompt) keeps the session for the next round. - Check OFFLOAD_REVIEW_TIMEOUT once at startup, before any worktree exists. - Mark a stopped run with a file, not exit code 124. A backend that exits 124 by itself is no longer labelled a timeout. - Append to review.log, so an earlier diagnostic stays. - claude: forgetting a session also removes its transcript. - Fix the function counts in the backend headers and SKILL.md. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Round 1 replies (commit b455aa7)Reviewer 2, blocking:
Reviewer 2, non-blocking: Reviewer 1, non-blocking:
|
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | b455aa7db069 |
approve |
Verdict: approve
Findings
None. The new commit fixes every round-1 finding, and I found no new defect in it.
Earlier findings, re-checked
Mine (round 1, all non-blocking):
- Stale function counts in the headers and SKILL.md — fixed. All four headers now say "the optional ones listed below".
- A backend that exits 124 by itself reads as a timeout — fixed.
run_limitednow creates a marker file on a real stop, and both labels key on that marker, not on exit code 124. I verified it: a child that exits 124 on its own creates no marker and keeps "exit 124" in thetriedline; a real timeout creates the marker. OFFLOAD_REVIEW_TIMEOUTvalidated in each attempt — fixed. Validated once at startup (scripts/offload-review.sh:96-97), before any worktree or session exists.- Session dropped when the backend never ran — fixed.
attemptwrites aranmarker just beforerun_limited(line 342), andrun_reviewerforgets the session only when that marker exists (line 375). A failure inensure_wt,cd, or the prompt write keeps the session. > review.logtruncation — fixed. It appends now (line 345), so thebackend_has_sessiondiagnostic stays.- No shell-test harness — not changed. The author states end-to-end tests with a fake
ghand test backends. Accepted; the repo has no harness to put one in.
Reviewer 2 (round 1):
- Blocking, session dropped before the backend ran — fixed, same
ranmarker and startup validation as my items 3 and 4. - Claude transcript leak after
backend_forget_session— fixed. It now callsbackend_cleanup, which removes the transcript under~/.claude/projectsand the id file. - Run ending at the limit mislabeled — fixed, same marker file.
- A process that leaves its process group escapes the stop — not changed, acknowledged by the author. No backend does that. Accepted.
Non-blocking
- scripts/offload-review.sh:96-97 — a bad
OFFLOAD_REVIEW_TIMEOUTnow blocks--cleanup. The validation runs before the cleanup branch (line 104). A user with a broken value in the environment cannot clean up the reviewer worktrees until they fix the variable. Cleanup does not run a review, so it does not need the timeout. Fix: move the check after the cleanup branch. - scripts/offload-review/backends/claude.sh:46-48 — the two backends now differ on diagnosis. After a failed run, glm keeps its transcript in the worktree, but claude deletes its transcript under
~/.claude/projects. The comment says why (the id file would name a newer session at--cleanuptime). The trade-off is deliberate; note it only.
What I checked
- Last review: round 1, e373014, 2026-10-25T13:35:03Z
- New commits read: 1 (b455aa7 fix(review): forget a session only after the backend ran)
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review: reviewer 2's round-1 review (its blocking finding matches my non-blocking items 3 and 4; I checked the fix), the author's reply comment (I checked each claim against the code), and commit b455aa7 (full diff and the changed code around it).
- Read the updated
scripts/offload-review.shsections in the file, not only the diff: startup validation,run_limited,attempt,run_reviewer; and all three backend headers plus claude'sbackend_forget_session. - Ran the new
run_limitedsignature in local bash (no Go): a child that exits 124 on its own creates no marker and returns 124; a real timeout kills the run and creates the marker. So the label cannot lie anymore. - Checked the marker wiring:
ranandstoppedmarkers live in$skipdir, names include reviewer and backend, no collision with the$skipdir/$breason files for any real backend name; each backend runs at most once per reviewer per round, so no stale marker can mislabel a later attempt. - Checked
review.loglifetime:ensure_wt'sgit cleanremoves it at each attempt, so>>appends only within one attempt — the intended fix. - Syntax-checked
offload-review.shand all three backends withbash -n: all pass. - No Go code changes, so no data-dependence update and no Go tests apply. Live tests were not approved; I ran no
claude,bob, orghreview commands beyond reading the PR.
amiddavid
left a comment
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.310 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | b455aa7db069 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed correctly, and the new commit adds no defect.
Round-1 findings
forget_sessiondropped a session even whenbackend_runnever ran — fixed.OFFLOAD_REVIEW_TIMEOUTis now checked once at startup (offload-review.sh:96-97), before anyghcall or worktree. Verified live:OFFLOAD_REVIEW_TIMEOUT=30m scripts/offload-review.sh 697prints the error and exits 1, nothing else runs.attemptwrites aranmarker (offload-review.sh:342) immediately beforerun_limited, andrun_reviewerforgets the session only when that marker exists (offload-review.sh:374). So a failure inensure_wt,cdor the prompt write keeps the session. The marker lives in$skipdir, which is a freshmktemp -dper script run, so no stale marker can leak into a later round. Names are per reviewer and backend, so the two concurrent reviewers cannot collide.
- Non-blocking, claude transcript leak — fixed.
backend_forget_sessionnow callsbackend_cleanup(backends/claude.sh:49-51), which deletes the transcript under~/.claude/projectsand the sid file. Checked the context:forget_sessionruns the backend aftercd "$wt", soclaude_sid_file'spwd -Presolves to the right worktree. A later--cleanupfinds no sid file and returns 0 early. - Non-blocking, boundary "timed out" label — fixed. The label now comes from a
stoppedmarker file, not exit code 124. Verified by running the newrun_limitedunder bash 5.2 and bash 3.2: success → rc 0, no marker; a child that exits 124 by itself → rc 124, no marker, no timeout label; a real timeout → rc 124, marker created, whole group killed. This also fixes reviewer 1's item 2. - Non-blocking, "all its processes" wording — not changed, as the author said. No backend puts a process in a new group. Agreed; nothing to do.
Reviewer 1's round-1 items
All six are addressed by the same commit. I checked each in the diff: the header counts in bob.sh, claude.sh, glm.sh and SKILL.md now say "optional ones listed below" (correct); the exit-124 and startup-validation items are the same fixes as mine above; >> review.log (offload-review.sh:345) keeps the backend_has_session diagnostics that 2>>review.log wrote earlier; the no-harness item is acknowledged, not changed, which matches repo practice (no shell-test harness exists). Agree with the author's handling.
The new commit, reviewed as a first review
run_limited's new<marker>argument matches its only call site (offload-review.sh:345); the marker is created only on the timeout path, after the group kill andwait, and both consumers (attempt:346,run_reviewer:375) test for the file, not the exit code.- The
ranmarker is written after the last pre-run step that can fail (the prompt write), so every failure that can still occur beforebackend_runkeeps the session. exit "$rc"still returns 124 on a real timeout, so the outerattempt ... || rc=$?plumbing is unchanged and correct.review.logis cleaned byensure_wt'sgit cleanat the start of each round, so the switch from>to>>cannot grow the log across rounds.- The updated doc comments (
run_limited,backend_forget_session, SKILL.md, backend headers) match the new behavior.
Non-blocking
None new.
What I checked
- Last review: round 1, e373014, 2026-10-25T13:36:11Z
- New commits read: 1 —
b455aa7dfix(review): forget a session only after the backend ran - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review: the fix commit
b455aa7d(read as a first review, above), and the author's round-1 replies comment of 2026-10-25T13:47:23Z (each reply checked against the code). - Ran the new
run_limitedunder/opt/homebrew/bin/bash5.2 and/bin/bash3.2, in the same nesting as the real script: marker created only on a real timeout; a self-exit-124 creates no marker; the group kill still stops the whole run; exit codes propagate. - Ran the startup validation live with
OFFLOAD_REVIEW_TIMEOUT=30m: exits 1 with the message before any network call or worktree change. - Re-read the changed sections of
offload-review.sh(validation,run_limited,attempt,run_reviewer,forget_session), all three backend files andSKILL.mdat the new head. - No Go builds or tests were run (not approved). No live
claude/bobruns; therun_limitedtests usedsleepandexitonly.
fix(review): let --cleanup run with a bad OFFLOAD_REVIEW_TIMEOUT The OFFLOAD_REVIEW_TIMEOUT check ran before the --cleanup branch. A bad value made `--cleanup` exit 1, although cleanup runs no reviewer. Move the check after the --cleanup branch. It still runs before any reviewer worktree or session is touched. Follow-up to #697. Listed in #658. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Summary
offload-reviewnow has a wall-clock limit. A run that never ends is stopped, and that reviewer falls back to the next backend.OFFLOAD_REVIEW_TIMEOUTstops the script at startup, before any worktree exists..review-in-*.txtfile in its own folder. Before, one extra file made a round exit 1 although both reviews posted.What we found
backend_has_sessionis then true, because the failed run'ssession-idfile is still there..review-in-prbody.txtin its own folder. The file check allowed only 3 names.What changed
scripts/offload-review.sh:run_limitedruns the backend in its own process group. Past the limit it stops the whole group, first with TERM, then with KILL after 5 s, creates a marker file and returns 124. The marker, not the exit code, says the run was stopped. A backend that exits 124 by itself reads asexit 124. A plain kill of the backend's pid would leave its children running.OFFLOAD_REVIEW_TIMEOUT, in seconds. The default is 1800 (30 minutes).0turns it off.review.logends withoffload-review: stopped after <N>s, and theTried first:line saystimed out.posted_nowalready checks that, so a reviewer that posted just before the stop does not get a second review.OFFLOAD_REVIEW_TIMEOUTis checked once at startup.review.logis appended to, not overwritten.forget_sessioncalls the backend'sbackend_forget_session. A backend without that function getsbackend_cleanupinstead..review-in-*.txt.backends/glm.shandbackends/claude.sh:backend_forget_sessionremoves the saved session id. For claude it also removes the transcript under~/.claude/projects. For glm, the transcript stays in.glm-cc/for diagnosis, and--cleanupremoves it after the merge.bobhas no session-id file, so it usesbackend_cleanup..claude/skills/offload-review/SKILL.md: documents the time limit, the "a failed run is never resumed" rule, and the new optional backend function.How it was tested
All tests ran on the laptop with a fake
ghand test backends. The test files are not committed.OFFLOAD_REVIEW_TIMEOUT=4, and a second backend that posts right away.sleep 600process was left behind, so the whole process group was stopped.review.logended with the stop line.resume=0, "round 2 starts fresh").run_limitedon its own:0means no limit./dev/null, so a background job is never stopped by SIGTTIN.30mexits 1 with a message. No worktree is made.exit 124, with nostopped afterline.bash -npasses on all changed scripts.Not tested: a real GLM run that hits the limit. That needs a model that degenerates on purpose.
Open questions
Technical notes
set -mgives the backend its own process group.set +mright after keeps the rest of the script as it was. The INT/TERM trap stops the group if the review script itself is stopped.forget_sessionruns in a subshell, as the cleanup code does, so one backend's functions never leak into another's.