Skip to content

fix(review): say why a backend was skipped, and flag a round that fell back - #682

Merged
amiddavid merged 2 commits into
mainfrom
fix/review-skip-reason
Oct 23, 2026
Merged

amiddavid merged 2 commits into
mainfrom
fix/review-skip-reason

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

  • When the script skips a reviewer backend, it now says why.
  • When a reviewer did not use the first backend, the script ends with a Note: line, so a fallback cannot go unnoticed.
  • SKILL.md tells the session to check GLM_KEY_FILE before the run, and to report the reason for a skip.

What we found

On #681, both reviewers fell back to Bob, and the script printed only glm (not set up).

  • The real cause: the session started on 2026-10-20. The user added GLM_KEY_FILE to ~/.zshrc on 2026-10-23. A running session never sees a new line in the shell profile.
  • The reviewing session took "not set up" as a fact about the machine, and accepted the Bob round.
  • Sessions often run for days, so this is the common case, not a rare one.

What changed

  • backends/glm.sh: backend_ready prints its reason. The reasons:
    • claude is not on PATH;
    • GLM_KEY_FILE is not set;
    • GLM_KEY_FILE is set in the shell profile but not in this session, which started before it. The fix is a new session, or a prefix on the command;
    • the key file is missing or not readable;
    • the key file has no gateway URL.
  • scripts/offload-review.sh:
    • The Tried first: line shows the reason, for example glm (not set up: GLM_KEY_FILE is set in your shell profile but not in this session ...).
    • A Note: line at the end, when any reviewer did not use the first backend.
  • SKILL.md: check the variable in this session before the run, and tell the user the reason before you accept a round that fell back.

The profile check runs $SHELL -ic and prints only set or nothing. It never prints the path or the key.

How it was tested

Case backend_ready says
This session (older than the profile line) "set in your shell profile but not in this session, which started before it ..."
GLM_KEY_FILE set to the real file ready
GLM_KEY_FILE=/nope "names a file that is missing or not readable"
No variable, no profile (SHELL=/bin/sh) "is not set (see the GLM setup guide)"

bash -n passes on the script and the backend.

🤖 Generated with Claude Code

…l back

On #681 the whole round went to Bob, and the script said only
"glm (not set up)". The real cause: the session started before the user
added GLM_KEY_FILE to the shell profile, so it never saw the variable.
The reviewer took "not set up" as a fact about the machine.

- backend_ready may print a reason. glm's names the exact cause: no
  claude on PATH, GLM_KEY_FILE unset, set in the profile but not in this
  session, a file that is missing, or no gateway URL in it.
- The "Tried first" line shows that reason.
- When a reviewer did not use the first backend, the script ends with a
  Note line that says to tell the user before accepting the round.
- SKILL.md: check GLM_KEY_FILE in this session before the run, and
  report the skip reason; do not read "not set up" as a fact about the
  machine.

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 aea32cb131ae blocking

Verdict: blocking

Findings

  1. scripts/offload-review.sh:348 — the new Note: fires on a normal round-2 resume, where no backend fell back, and points at "Tried first" lines that were never printed.

    • What fails: round 2 after any round-1 fallback — the exact situation this PR was written for. chain_for (lines 197–204) puts each reviewer's round-1 backend first, so it can resume its session. Reviewer 1 posts with bob, reviewer 2 with glm. No backend was skipped and no backend failed. The Note loop still fires, because "reviewer 1: bob" does not end in ": glm". It says "not every reviewer used glm, the first backend" — false for reviewer 1, whose first backend was bob. It also says "The reason is in the 'Tried first' lines above" — no such line exists, because run_reviewer prints "Tried first" only when a backend was actually skipped (line 292, tried empty here).
    • Proof: chain_for line 201 puts prev first when round > 1; used entries are built as "reviewer $r: $b" (line 341); the loop at lines 347–349 tests only the suffix ": $backend". I ran the loop with used=("reviewer 1: bob" "reviewer 2: glm") and backend=glm: it prints the Note. A resumed session is a documented, intended flow (SKILL.md: "In round 2, each reviewer starts with the backend that wrote its round-1 review"), so the user gets a false alarm on a clean round.
    • Fix: flag the round from what actually happened, not from the backend names. Set a fell_back=1 flag where a backend is skipped (rc=4) or fails (the tried paths in run_reviewer), and print the Note from that flag. Keep the "Tried first" promise only when at least one such line was printed.
  2. scripts/offload-review/backends/glm.sh:68 — the login-shell probe can report the wrong reason for the skip, including in the exact case it was written to detect.

    • What fails: [ "$login" = set ] requires the whole stdout of the interactive shell to be exactly set. Any line the profile writes to stdout is captured with it, so the probe then reports "GLM_KEY_FILE is not set (see the GLM setup guide)" even when the profile does set it. Also, ${SHELL:-/bin/sh} -ic starts an interactive non-login shell: on macOS a variable in .zprofile (or .bash_profile for bash users) is not sourced, so the probe misses it and again says "not set", while a new session would see the variable.
    • Proof: I ran a profile that both exports GLM_KEY_FILE and echoes one line; the captured value was Welcome! Tools loaded.\nset, and the check answered "not set". zsh sources .zprofile only for login shells, which -ic is not.
    • Fix: make the probe print a unique marker and match it anywhere in the captured text, for example printf 'CGPROBE:%s' "${GLM_KEY_FILE:+set}" and [[ $login == *CGPROBE:set* ]]. Use -lic (or check both the login and the interactive rc) so a variable in a login-only profile file counts.

Non-blocking

  • for u in "${used[@]}" (line 347) runs even when used is empty, which happens when both reviewers fail to post. On bash older than 4.4, an empty-array expansion under set -u is a fatal "unbound variable" error. The script guards other arrays with ${arr[*]-} (line 202). This machine has bash 5.2, so it does not fail here.
  • SKILL.md's "Add a backend" section still does not list backend_ready, and does not state its new contract: print the skip reason to stdout. A new backend that prints the reason to stderr loses it, and the script says only "not set up".
  • Two reviewers can attempt the same backend at the same time and both write $skipdir/<backend>. The content is the same, so the worst case is one garbled reason line.
  • The EXIT trap does not run on an untrapped SIGINT or SIGTERM, so skipdir can leak. It lives in TMPDIR, so the leak is small.

What I checked

  • The full diff of the one commit (SKILL.md, scripts/offload-review.sh, backends/glm.sh) and the code around every change: the whole of offload-review.sh and all three backend files.
  • The skipdir EXIT trap against the two subshell kinds that touch it: the attempt subshell and the background run_reviewer. Tested in bash 5.2: neither inherits the trap, so neither deletes skipdir early.
  • The new backend_ready contract for all three backends: bob and claude print nothing and keep exit-only semantics, so the stdout capture changes nothing for them.
  • The login-shell probe, with a simulated profile (proof in finding 2), and the Note loop, with a simulated round-2 resume (proof in finding 1).
  • No builds or tests were run; live tests are not approved. The findings above are proven by code traces and local shell tests only.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 aea32cb131ae blocking

Verdict: blocking

Findings

  1. scripts/offload-review/backends/glm.sh:68 — a profile that prints to stdout makes the probe report the wrong reason

    • What fails: GLM_KEY_FILE is unset in the session, and the shell profile sets it and prints any line to stdout. The probe captures hello-from-profile\nset, not set. The [ "$login" = set ] test at line 69 fails. The user then reads glm (not set up: GLM_KEY_FILE is not set (see the GLM setup guide)) — the opposite of the truth. The profile has the variable; a new session would see it. The commit exists to say the right reason, and this case says the wrong one.
    • Proof: I ran the exact expression from line 68 with a fake HOME, under both shells:
      • Profile: echo hello-from-profile + export GLM_KEY_FILE=/tmp/key.json.
      • SHELL=/bin/bash: captured hello-from-profile\nset.
      • SHELL=/bin/zsh (with ZDOTDIR unset): captured hello-from-profile\nset.
      • Both fail the = set comparison, so line 72 prints the "not set" message. On this machine today the probe works, because the profile's Homebrew lines go to stderr and 2>/dev/null drops them. Any future stdout line in the profile breaks it.
    • Fix: print a sentinel and match it with a glob, so extra profile output cannot break the match. For example, the child prints printf 'CGPROBE:%s' "${GLM_KEY_FILE:+set}", and the test becomes [[ $login == *"CGPROBE:set"* ]].
  2. scripts/offload-review.sh:347 — the Note: line fires in round 2 for a resumed backend, and points at "Tried first" lines that do not exist

    • What fails: a reviewer fell back to bob in round 1. In round 2, chain_for (line 201) puts bob first for that reviewer, so it resumes bob and posts on the first try. tried stays empty, so run_reviewer prints no "Tried first" line (line 292 suppresses it). The used entry is reviewer 1: bob, which fails the *": $backend" match, so the Note fires: "The reason is in the 'Tried first' lines above." No such lines exist in this round's output. Nothing fell back in this round; the reviewer resumed its own round-1 backend by design. The user hunts for lines that were never printed.
    • Proof: trace — round 1: glm not ready, exit 4, bob posts for reviewer 1. Round 2: chain_for 1 returns bob glm claude; backend_has_session is true; bob posts; tried=(); line 292 prints nothing. Main loop: used=("reviewer 1: bob" ...), backend=glm, line 348's [[ $u == *": glm" ]] fails, Note prints. This repeats on every round 2 after any round-1 fallback.
    • Fix: print the Note only when a fallback happened in this round. Let run_reviewer write a marker into $skipdir when it posts with a backend that was not first in its own chain, and have the final loop read that marker. Or keep the Note but change its text for the resume case, and only cite "Tried first" when such a line was printed.

Non-blocking

  • The probe at glm.sh:68 spawns a full interactive login shell, twice per round (once per reviewer) while GLM_KEY_FILE is unset. It runs the whole user profile, with side effects and no timeout. A profile that blocks would hang the round. A sentinel fix (finding 1) could also cache the answer.
  • glm.sh:77: if python3 is missing, glm_field yields empty and the message says "no gateway URL in the key file". The real reason is the missing python3. backend_run requires python3 anyway, so this is an edge case.
  • offload-review.sh:296: a multi-line reason is embedded in one "Tried first" entry. It reads fine; just noting it is intended.

What I checked

  • Read the full diff (SKILL.md, offload-review.sh, glm.sh) and both scripts end to end, plus backends/bob.sh and backends/claude.sh, to check the new backend_ready contract against every backend. bob and claude print nothing on failure, so the ${why:-not set up} default covers them.
  • Read CLAUDE.md and docs/design.md first. This PR touches only review tooling, not the pipeline, so the fail-open and data-dependence rules do not apply.
  • Checked the new skipdir + EXIT trap against the two background reviewers: I ran a bash test with a counter file. The EXIT trap fires once, in the main shell. Background subshells and command substitutions do not fire it, so the shared skipdir is not removed early while a reviewer still writes its reason.
  • Checked concurrent writes to $skipdir/<backend>: both reviewers can attempt the same backend at the same time, but backend_ready is deterministic, so both write the same bytes. Benign.
  • Checked the set -e interactions: the ||-guarded why=$(backend_ready ...) and the [[ ... ]] || { ... } Note loop do not trip the shell's ERR/EXIT paths.
  • Ran the login-shell probe under bash and zsh with fake profiles (findings 1's proof). No Go code changed in this PR; I ran no builds or tests.

… probe robust

From both GLM reviewers of #682, round 1 (the same 2 findings each).

- The Note fired on a normal round-2 resume of an earlier fallback
  backend, and pointed at "Tried first" lines that were never printed.
  run_reviewer now leaves a marker only when it fell back in this
  round, and the Note reads that marker.
- The profile probe needed the shell's whole stdout to be "set", so a
  profile that prints a line read as "not set". It also used -ic, which
  skips .zprofile and .bash_profile. It now prints a CGPROBE: marker,
  matches it anywhere, and runs -lic.

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Author reply to both reviewers, round 1 (head aea32cb131ae). Both reviewers raised the same 2 findings. Both are fixed in 494fae44d91a.

  1. The Note: fires on a round-2 resume, and points at lines that were not printed: fixed.
    • run_reviewer now leaves a marker only when it fell back in this round, meaning a Tried first line was printed. The Note: reads that marker, not the backend names.
    • Tested with a fake round 1 (glm not set up, so both reviewers fell back to bob) and a round 2 (bob resumes and posts on its first try). Round 1 printed the Note:, and round 2 printed none.
  2. The profile probe gives the wrong reason when the profile prints a line, and misses login-only files: fixed.
    • The child prints CGPROBE:<value>, and the test matches *CGPROBE:set* anywhere in the output.
    • The probe runs -lic, so .zprofile and .bash_profile count.
    • Tested with a profile that runs echo hello-from-profile and sets the variable: in .zprofile under zsh, and in .bash_profile under bash. Both now report "set in your shell profile but not in this session".

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 494fae44d91a approve

Verdict: approve

Findings

None. Both round-1 findings — mine and reviewer 2's, which were the same two — are fixed in 494fae44d91a, and I verified each fix with a local test.

  1. Round-1 finding 1 (Note fired on a clean round-2 resume): fixed.
    • run_reviewer now writes $skipdir/fellback-$r only inside the same if that prints the "Tried first" line (scripts/offload-review.sh:292-297), so the marker exists only when a fallback happened in this round and the line the Note points at was printed. The final loop reads the marker, not the backend names (scripts/offload-review.sh:352-356).
    • Proof: I ran the new logic. Case A, a round-2 resume that posts on its first try (tried empty): no marker, no Note. Case B, a real fallback (tried non-empty): the "Tried first" line and the Note are both printed. A resume of an earlier fallback backend no longer fires the Note.
  2. Round-1 finding 2 (profile probe reported the wrong reason): fixed.
    • The probe prints a CGPROBE: marker and the test matches *CGPROBE:set* anywhere in the captured output, so profile chatter cannot break it. It runs -lic, so .zprofile and .bash_profile count (scripts/offload-review/backends/glm.sh:68-72).
    • Proof: I ran the probe with GLM_KEY_FILE unset in the session and a .zprofile that both exports the variable and echoes a line: it reports "set in your shell profile". With a .zprofile that only echoes a line, it reports "not set". Both answers are right.

Non-blocking

  • SKILL.md's "Add a backend" section still does not list backend_ready or its contract: print the skip reason to stdout. From round 1, not addressed.
  • The probe still starts a full login shell once per attempt while GLM_KEY_FILE is unset, with side effects and no timeout. Reviewer 2 noted this in round 1; unchanged.
  • My round-1 note about the empty used array under set -u on old bash is resolved by side effect: the new loop iterates todo, which is never empty.

What I checked

  • Last review: round 1, aea32cb, 2026-10-23T11:40:08Z.
  • New commits read: 1 (494fae4 fix(review): flag only a fallback in this round, and make the profile probe robust).
  • 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 (11:41:37Z): the same two findings as mine. Both are fixed; I verified each fix myself (above), so I do not repeat them.
    • Author reply (11:43:43Z): says both findings are fixed in 494fae44d91a. I checked the claim against the code and by test; it holds.
    • New commit 494fae4: read the full diff and the code around both changes. The diff touches only the two hunks that fix the findings.
  • I checked the new commit for fresh defects: the marker file is written only after the parent's wait, so skipdir still exists; the two reviewers write fellback-1 and fellback-2, so they do not collide; the Note fires at most once; a reviewer that fails every backend sets no marker, and the round already reports that failure with exit 1.
  • No builds or tests were run; live tests are not approved. The proofs above are code traces and local shell tests only.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 494fae44d91a approve

Verdict: approve

Round-1 findings

  1. glm.sh probe reported the wrong reason (my finding 1, same as reviewer 1's finding 2): fixed.
    • The child now prints CGPROBE:<value> and the test matches *CGPROBE:set* anywhere, so profile output cannot break it. The shell runs -lic, so login-only files count too.
    • I verified myself, with a fake HOME and GLM_KEY_FILE unset: chatty .zshrc → match; .zprofile-only → match; .zlogin-only → match; .profile-only under bash → match; chatty .bash_profile under bash → match; no profile → no match. All six cases give the right answer.
  2. The Note: fired on a round-2 resume and pointed at lines that were not printed (my finding 2, same as reviewer 1's finding 1): fixed.
    • run_reviewer now writes $skipdir/fellback-<r> only when it printed a "Tried first" line, that is, when a backend was skipped or failed in this round. The final loop reads the marker, not the backend names.
    • I traced the cases: round-1 fallback → marker → Note, and the reason is in the printed line. Round-2 resume of an earlier fallback backend → first try posts, tried empty → no marker → no Note. A failed resume that then posts with the next backend → marker → Note, and the reason is printed. I also simulated the final loop with fresh markers per case: it fires once when any reviewer in todo has a marker, and not at all without one.
    • The author's reply describes the same tests. My runs agree.

Findings

None. The new commit introduces no defect I can show.

Non-blocking

  • glm.sh:68: the probe still misses one bash shape. With SHELL=/bin/bash, the variable only in .bashrc, and no .bash_profile/.profile that sources it, -lic answers "not set". On a Linux desktop whose terminals start non-login shells, a new session would see the variable, so the hint steers wrong. I verified the miss with a fake HOME. This machine runs zsh, where -lic reads .zshrc, so it cannot happen here. Fix if wanted: also probe a plain -ic shell and treat either match as "in your profile".
  • SKILL.md:29: "When a reviewer did not use the first backend, the script prints a Note: line" is now wider than the code. The Note fires only when a reviewer fell back in this round; a round-2 resume of another backend prints none. The success line still lists each reviewer's backend, so the case stays visible. Update the sentence when you touch the file next.
  • Reviewer 1's round-1 non-blocking item on SKILL.md's "Add a backend" section (no backend_ready stdout contract documented) is still open. Non-blocking; I agree it stays that way.
  • My round-1 note on probe cost stands: the probe runs the full login profile, twice per round, with no timeout.

What I checked

  • Last review: round 1, aea32cb, 2026-10-23T11:41:37Z.
  • New commits read: 1 (494fae44 fix(review): flag only a fallback in this round, and make the profile probe robust).
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files).
  • New items since my last review: the fix commit 494fae44 (full diff read, both hunks traced through the current files), and the author's reply comment at 2026-10-23T11:43:43Z (both fixes described; I verified each myself rather than trusting it). Reviewer 1's round-1 review predates my last review; I read it in full anyway. It found the same 2 defects, so there is nothing to cross-check that I did not already prove.
  • Checked the new marker write against the subshell model I tested in round 1: it happens in the background run_reviewer shell, before the main shell's wait returns, and the EXIT trap removes skipdir only at final exit. No ordering problem.
  • Checked the new code under set -euo pipefail: the inverted tried test, the : > marker write, and the for r in "${todo[@]}" loop (todo is never empty) are all safe. The rewrite also removes reviewer 1's empty-used-array concern, since the for u in "${used[@]}" loop is gone.
  • No Go code changed in this PR; I ran no builds or tests. My proofs are code traces and local shell probes only.

@amiddavid
amiddavid merged commit e57d422 into main Oct 23, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant