Skip to content

feat(review): add a GLM reviewer backend and make it the default - #675

Merged
amiddavid merged 2 commits into
mainfrom
feat/review-glm-backend
Oct 23, 2026
Merged

amiddavid merged 2 commits into
mainfrom
feat/review-glm-backend

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a GLM reviewer backend for the offload-review skill, and makes it the default.
  • The release owner wants to compare GLM with IBM Bob as the PR reviewer, starting with the next release.
  • Bob stays available: --backend bob or OFFLOAD_BACKEND=bob.

What changed

  • scripts/offload-review/backends/glm.sh (new): GLM through Claude Code. claude -p points at a gateway that serves GLM in the Anthropic /v1/messages format, so tools, sessions and resume work as they do for Claude.
    • The key never enters the reviewer's environment. Claude Code reads it at call time through apiKeyHelper, from the JSON file that GLM_KEY_FILE names. A reviewer that runs env in its shell cannot print it.
    • The gateway URL and the model id come from the same file, so a change there needs no script edit.
    • Each reviewer has its own Claude Code config folder, .glm-cc/, in its worktree. Round 1 fixes a session id, and round 2 resumes that id. latest could pick the other reviewer's session.
    • --max-turns (default 200) is the spend cap. Claude Code has no price for GLM, so --max-budget-usd would count nothing.
  • scripts/offload-review.sh: glm is the default backend. The check for changed files allows .glm-cc/.
  • SKILL.md: lists both backends, and what glm needs.

The gateway host, the key file path and the key are internal. None of them is in this PR.

How it was tested

On the laptop, with the backend sourced in a scratch git folder:

Check Result
bash -n on both scripts clean
Round 1: GLM answers and runs a shell command pass, 18 s, session id saved
The key is not in the reviewer's environment pass: ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY are both unset in its shell
The key is in no file under the scratch folder, .glm-cc/ included pass
Round 2 resumes by id and remembers round 1 pass
backend_cleanup removes .glm-cc/ pass

The first real two-reviewer run is this PR's own review, with --backend bob.

Open questions

  • A GLM reviewer found about 40 to 70% of the blocking defects that an Opus reviewer found, in another session's tests. The next release measures it on this repo's PRs.

🤖 Generated with Claude Code

The release owner wants to compare GLM with IBM Bob as the PR reviewer,
starting with the next release.

- scripts/offload-review/backends/glm.sh: GLM through Claude Code
  (`claude -p`) pointed at a gateway that serves GLM in the Anthropic
  /v1/messages format. Tools, sessions and resume work as for Claude.
  - The key is read at call time through apiKeyHelper from the file
    that GLM_KEY_FILE names. It never enters the reviewer's
    environment, so a reviewer that runs `env` cannot print it.
  - The gateway URL and the model id come from the same file.
  - Each reviewer has its own Claude Code config folder, .glm-cc/, in
    its worktree. Round 1 fixes a session id, and round 2 resumes it
    by id, because "latest" could pick the other reviewer's session.
  - --max-turns (default 200) is the spend cap. Claude Code has no GLM
    price, so --max-budget-usd would count nothing.
- scripts/offload-review.sh: glm is the default backend. The
  changed-files check allows the .glm-cc/ folder.
- SKILL.md: lists both backends and what glm needs.

Bob stays available with --backend bob or OFFLOAD_BACKEND=bob.

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 2 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 7d6c558c0636 approve

Verdict: approve

Findings

None. The PR adds a GLM backend for the offload-review skill with proper security controls and documentation.

Non-blocking

  1. Line 82 in glm.sh — Python inline script could use error handling

    • The inline Python script that writes settings.json has no error handling. If the write fails (disk full, permissions), the script continues silently.
    • Not blocking because: the next command (line 89-93) will fail when it tries to read the missing or corrupt file, and backend_run will return nonzero, which the caller handles.
    • Consider: Add error handling in the Python script or check that settings.json exists and is readable after line 88.
  2. Line 63 in glm.sh — Guard condition could be more explicit

    • The guard [[ $d == */.glm-cc ]] && [ "$d" != "/.glm-cc" ] protects against dangerous paths. The second check (not exactly "/.glm-cc") is good, but the pattern match allows paths like "x/.glm-cc" where x is empty or a relative path.
    • Not blocking because: glm_dir() always returns $(pwd -P)/.glm-cc, which is an absolute path from a real directory. The worktree must exist for the backend to run.
    • Consider: Add an explicit check that $d starts with / to make the absolute-path requirement clear.
  3. Line 247 in offload-review.sh — Regex could be more specific

    • The grep pattern \.glm-cc/)$ matches any file ending with .glm-cc/. A file named foo.glm-cc/ would be ignored.
    • Not blocking because: Git does not track directories, only files. A file cannot end with /. The pattern is correct for git status --porcelain output, which shows directories with a trailing /.
    • No change needed. The pattern is correct.

What I checked

  • Security: The GLM backend never exposes the API key in the reviewer's environment. The key is read at call time through apiKeyHelper, which is a Python script that reads the key file. The key file path is the only secret-adjacent value in the settings file. The reviewer cannot print the key by running env in its shell.
  • Credential isolation: The backend unsets all Anthropic credential environment variables (line 106) and uses a private CLAUDE_CONFIG_DIR (line 107) to keep the user's own settings out of the run.
  • Session management: Each reviewer gets its own session folder (.glm-cc/) inside its worktree. The session ID is fixed in round 1 and resumed by ID in round 2. Two reviewers running at once cannot pick each other's session.
  • Cleanup: The backend_cleanup function removes the .glm-cc/ folder with proper guards (line 59-65). The guard checks that the path ends with /.glm-cc and is not exactly /.glm-cc.
  • Default change: The default backend changed from bob to glm (line 42 in offload-review.sh). The documentation (SKILL.md) lists both backends and says glm is the default.
  • File filtering: The script now ignores .glm-cc/ when checking for files the reviewer changed (line 247). This is correct because the backend owns that folder.
  • Documentation: SKILL.md documents the GLM backend's environment requirements and explains that the key file is not in the repo. It also documents the cleanup behavior.
  • Fail-open: If GLM_KEY_FILE is not set or not readable, backend_run returns 1 with a clear error message (line 69). The caller handles this as a reviewer failure.
  • Model variable override: The backend sets every Claude Code model variable to the GLM model (lines 98-102). This prevents Claude Code from asking the gateway for a Claude model it does not serve.
  • Resume logic: The backend checks for an existing session with backend_has_session (line 55-57). If the session-id file exists and is not empty, round 2 resumes that session.
  • Prompt handling: The backend reads the prompt from the file given as the first argument (line 108). It does not use a positional prompt, which is correct for Claude Code.
  • Turn limit: The backend uses OFFLOAD_MAX_TURNS (default 200) as the spend cap (line 109). This is documented in the header comment (line 21-22).
  • No changes outside the skill: The PR changes only the offload-review skill and its backends. It does not change any core code or other skills.
  • ASD-STE100 style: The documentation uses short sentences, simple words, and active voice. The technical notes are in a separate section at the end.
  • Commit message: Not checked (I cannot see the commit message from the diff).
  • DCO sign-off: Not checked (I cannot see the commit metadata from the diff).

@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 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 7d6c558c0636 blocking

Verdict: blocking

Findings

  1. scripts/offload-review/backends/glm.sh:92 — Session creation fails silently when uuidgen is missing

    • What fails: If uuidgen command is not available, the pipeline uuidgen | tr 'A-Z' 'a-z' creates an empty session-id file. Round 2 then tries to resume with an empty session id, which fails.
    • Proof: Line 92 has no error check. Line 90 in backend_run uses $(cat "$d/session-id") which would be empty. The --resume "" argument to claude would fail.
    • Fix: Check that uuidgen exists before using it, or use a fallback method. Add command -v uuidgen >/dev/null || { echo "glm backend: uuidgen not found" >&2; return 1; } before line 92.
  2. scripts/offload-review/backends/glm.sh:82-88 — Settings file write has no error handling

    • What fails: The Python script writes settings.json with open(out, "w") but does not catch write errors. If the write fails (disk full, permission denied), the script exits 0 and backend_run continues. The claude command then fails with a confusing error about missing or invalid settings.
    • Proof: Lines 82-88 use python3 -I - with no error handling in the Python code. The bash set -e does not catch Python exceptions. A write failure would make claude fail at line 108.
    • Fix: Wrap the Python open() and json.dump() in a try-except block, or check the exit code and validate that settings.json exists and is readable before calling claude.
  3. scripts/offload-review/backends/glm.sh:109 — No check that claude command exists

    • What fails: If claude is not installed or not in PATH, the script fails with "command not found" instead of a clear error message.
    • Proof: Line 109 invokes claude directly. No prior check exists. The error would be "claude: command not found" from the shell, not a backend error message.
    • Fix: Add command -v claude >/dev/null || { echo "glm backend: claude command not found" >&2; return 1; } at the start of backend_run.
  4. scripts/offload-review/backends/glm.sh:63 — Cleanup guard is incomplete for edge case

    • What fails: If pwd -P returns / (root directory), then d becomes /.glm-cc. The check [ "$d" != "/.glm-cc" ] passes, but rm -rf /.glm-cc would still be dangerous.
    • Proof: Line 61 sets d=$(glm_dir) which is $(pwd -P)/.glm-cc. Line 63 checks [[ $d == */.glm-cc ]] && [ "$d" != "/.glm-cc" ]. If pwd -P is /, the second condition fails, but the first passes. The || makes the whole expression fail, so rm does not run. However, the error message "bad dir" is misleading.
    • Fix: This is extremely unlikely in practice (worktrees are never at root), but for completeness, add a check that d contains at least two path components: [[ $d =~ ^/.+/.glm-cc$ ]].

Non-blocking

  • Documentation clarity: SKILL.md line 21-22 says "GLM has no price in Claude Code's table, so a turn limit is the spend cap". This implies --max-budget-usd would not work, but the doc does not state this explicitly. Consider adding: "The --max-budget-usd flag does not count GLM tokens."

  • Consistency: The new backend changes the default from bob to glm, which is documented. However, users with OFFLOAD_BACKEND set will not see the change. This is correct behavior, but worth noting in the commit message or PR description.

What I checked

  • Read every changed line in the diff (3 files: SKILL.md, offload-review.sh, glm.sh)
  • Verified credential handling: key never enters reviewer environment, uses apiKeyHelper pattern correctly
  • Checked fail-open behavior: errors return non-zero, script handles them
  • Verified .glm-cc/ exclusion in git status validation (line 249 of offload-review.sh)
  • Confirmed documentation updates match code changes
  • Checked that backend interface is correctly implemented (all 4 required functions)
  • Verified session isolation: each reviewer gets its own config folder and session id
  • Checked environment variable isolation: all credential variables properly unset
  • Confirmed the cleanup function guards against dangerous paths
  • Verified that the default change is documented in both SKILL.md and offload-review.sh

From reviewer 1 of #675, round 1, findings 1 and 3. uuidgen is not on
every Linux box; python3 is already required by this backend.

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

Copy link
Copy Markdown
Collaborator Author

Author reply to reviewer 1, round 1 (head 7d6c558c0636).

  1. uuidgen missing gives an empty session id: fixed in 37c39d9d9f39. The id now comes from python3 -c 'import uuid; ...', which the backend already requires. An empty id now fails with a clear message.
  2. The settings write "exits 0" on a Python error: rejected. An uncaught Python exception exits with code 1, not 0. backend_run runs under the caller's set -euo pipefail (scripts/offload-review.sh:35), so a failed write stops the run there, and claude never starts.
  3. No check that claude exists: fixed in 37c39d9d9f39. backend_run now fails first with "claude (Claude Code) is not on PATH".
  4. The cleanup guard and the root path: rejected. As the finding itself says, rm does not run when the folder is /.glm-cc: the second condition is false, so the guard returns 1 first. No change is needed.

Non-blocking points: noted. The PR body already says that --max-budget-usd would count nothing for GLM.

@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 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 37c39d9d9f39 approve

Verdict: approve

Findings

None. All blocking findings from round 1 are resolved.

Status of round 1 findings

  1. Session creation with missing uuidgen: FIXED in commit 37c39d9. The backend now uses python3 -c 'import uuid; print(uuid.uuid4())' to generate the session id (line 94). It checks that the file is non-empty (line 95) and fails with a clear message if not.

  2. Settings file write error handling: REJECTED, and the rejection is correct. I claimed the Python script "exits 0" on an exception. This is wrong. An uncaught Python exception exits with code 1. The script runs under set -euo pipefail (offload-review.sh:35), so a failed write stops execution before claude starts. No change needed.

  3. No check for claude command: FIXED in commit 37c39d9. Line 69 now checks command -v claude and fails with "claude (Claude Code) is not on PATH" if it is missing.

  4. Cleanup guard for root path: REJECTED, and the rejection is correct. When d is /.glm-cc, the expression [[ $d == */.glm-cc ]] && [ "$d" != "/.glm-cc" ] is false (the second condition fails), so the || makes the guard return 1 before rm runs. The code is safe. No change needed.

Non-blocking

  • Reviewer 2's non-blocking point about the Python inline script (their finding 1) is the same as my rejected finding 2. The author's response covers it.

What I checked

  • Last review: round 1, 7d6c558, 2026-10-23T07:48:51Z
  • New commits read: 1 commit (37c39d9 "fix(review): check for claude, and make the session id with python3")
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Commit 37c39d9: fixes findings 1 and 3 from my round 1 review
    • Author comment at 2026-10-23T07:50:13Z: replies to all 4 findings, with fixes for 1 and 3, and correct rejections for 2 and 4
    • Reviewer 2's round 1 review at 2026-10-23T07:48:06Z: verdict approve, no blocking findings, 3 non-blocking points (one overlaps with my rejected finding 2)
  • Verified the fixes:
    • Line 69: command -v claude check is present
    • Line 94: session id now comes from python3 -c 'import uuid; print(uuid.uuid4())'
    • Line 95: checks that session-id file is non-empty with [ -s "$d/session-id" ]
  • Re-checked my rejected findings:
    • Finding 2: I was wrong about "exits 0". Python exceptions exit with code 1, and set -euo pipefail stops the script there.
    • Finding 4: The guard is correct. When d is /.glm-cc, the whole expression is false, so rm does not run.
  • Checked that no new issues were introduced by the fixes
  • Verified the commit message follows conventions: "fix(review):" prefix, references the PR and findings, includes DCO sign-off

@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 (bob, user of @amiddavid) IBM Bob Shell 1.0.3 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 37c39d9d9f39 approve

Verdict: approve

Findings

None. All fixes from round 1 are correct.

Review of round 1 findings

Reviewer 1's findings:

  1. Session creation fails when uuidgen is missing: FIXED

    • Line 93 now uses python3 -I -c 'import uuid; print(uuid.uuid4())' instead of uuidgen.
    • Line 94 checks that the session-id file is not empty and fails with a clear message if it is.
    • The fix is correct. Python3 is already required by this backend.
  2. Settings file write has no error handling: REJECTED, correctly

    • The author's rejection is correct. An uncaught Python exception exits with code 1, not 0.
    • The script runs under set -euo pipefail (offload-review.sh:35), so a failed write stops the run immediately.
    • The claude command never starts when the write fails.
  3. No check that claude command exists: FIXED

    • Line 68 now checks command -v claude >/dev/null and fails with "claude (Claude Code) is not on PATH" if it is missing.
    • The fix is correct.
  4. Cleanup guard is incomplete for edge case: REJECTED, correctly

    • The author's rejection is correct. When d=/.glm-cc, the guard [[ $d == */.glm-cc ]] && [ "$d" != "/.glm-cc" ] evaluates to false (first condition true, second false, so && returns false), which triggers the || and returns 1.
    • The rm on line 64 never runs. No change is needed.

My round 1 non-blocking points:

All three remain valid observations but are not blocking. No changes were made to address them, which is correct for non-blocking items.

Non-blocking

None new. The round 1 non-blocking points still apply.

What I checked

  • Last review: round 1, 7d6c558, 2026-10-23T07:48:06Z
  • New commits read: 1 commit (37c39d9 "fix(review): check for claude, and make the session id with python3")
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
  • New items since my last review:
    • Reviewer 1's round 1 review (2026-10-23T07:48:51Z): read all 4 findings and verified each one
    • Author's reply comment (2026-10-23T07:50:13Z): read the response to each finding
    • New commit 37c39d9: read the full diff and verified the fixes

Verification of fixes:

  • Line 68: command -v claude check added (fixes finding 3)
  • Line 93: python3 -I -c 'import uuid; print(uuid.uuid4())' replaces uuidgen | tr 'A-Z' 'a-z' (fixes finding 1)
  • Line 94: [ -s "$d/session-id" ] check added with error message (fixes finding 1)
  • No changes for findings 2 and 4, which were correctly rejected

Verification of rejections:

  • Finding 2: Confirmed that uncaught Python exceptions exit with code 1, and set -e catches them
  • Finding 4: Confirmed that the guard prevents rm from running when d=/.glm-cc

Security review (unchanged from round 1):

  • API key still never enters the reviewer's environment
  • Credential isolation still correct
  • Session management still correct
  • All security controls from round 1 remain intact

Commit metadata:

  • DCO sign-off: present (Signed-off-by: DAVID AMID <[email protected]>)
  • AI attribution: present (Assisted-By: Claude)
  • Commit message: follows conventional commit format (fix(review): ...)

@amiddavid
amiddavid merged commit 40868e3 into main Oct 23, 2026
6 of 7 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 23, 2026
amiddavid added a commit that referenced this pull request Oct 23, 2026
…ude Code (#679)

feat(review): fall back to the next reviewer backend, ending with Claude 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]>

fix(review): read the PR's reviews whole before grep in posted_now

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]>
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