Repository navigation
fix(review): close the 4 small lock gaps from #1434 - #1453
Conversation
- unlock removes the lock only when the pid file holds this process's pid. It replaces unlock_if_held. - An empty pid file in lock_take_stale means "not yet written", not "dead". The 60 s age rule applies. - The script refuses to run on bash older than 4, with a clear message. Bash 3.2 has no BASHPID, so a subshell cannot be told from the script. - Test (d) checks that --cleanup removes the scratch rules file. - SKILL.md names $OFFLOAD_RULES_DIR as the rules file folder. Refs #1436 Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5
|
Local tests: waived (owner rule) |
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.332 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 622074823a52 |
blocking |
Verdict: blocking
Findings
- scripts/offload-review_test.sh:127-133 — the put-back test does not run the new code, and passes on the old code too
- What fails: the new branch in
lib.sh:62(a renamed lock with an empty pid, on a failed put-back, is kept while young) has no test. The PR names this half of gap 2, and the test comment claims to cover it. It does not. - Proof: trace
lock_take_stale "999999"in that setup.$lockdirholds the live lock (pid$other). The empty-pid dir sits at$lockdir.stale.test.goneis"$lockdir.stale.<pid>.$RANDOM"(lib.sh:50) — a fresh name, not.stale.test.mv "$lockdir" "$gone"(lib.sh:51) renames the live lock, not the empty-pid one.now=$other(lib.sh:52) — non-empty, so theelifatlib.sh:62cannot run even if the block is reached.mv "$gone" "$lockdir"(lib.sh:60) succeeds: the first rename just vacated the path. So the whole|| { ... }block is skipped.- The assertion
[ -d "$lockdir.stale.test" ]is true because nothing in the function ever touches that directory. Delete the neweliffromlib.shand revert to the base put-back: the test still passes.
- Fix: make the branch reachable and deterministic. Factor the keep-or-remove decision into a helper that takes
<gone> <now>as arguments (for examplestale_putback <gone> <now>), and test that helper directly with an emptynow. Or force the put-back to fail: a background helper that re-creates$lockdirin the window between the twomvcalls.
- What fails: the new branch in
Non-blocking
lib.sh:59— the comment says an empty-pid renamed lock "stays until it is 60 s old". Nothing checks it again: each.stale.*name is unique, and no code sweeps them. A kept one stays forever, like the live-pid case above it. Say "stays" without the 60 s claim, or add a sweep. Also note the kept directory serves no holder: the lock it named was already moved away, so this half of gap 2 is garbage retention, not recovery..claude/skills/offload-review/SKILL.md:101,154— the example commands still hardcode/tmp/offload-review-pr<N>-rules.md. The parenthetical at line 95 covers it, but the examples could mislead whenOFFLOAD_RULES_DIRis set. Parameterize them.
What I checked
- Read the full diff (4 files) and the full text of
scripts/offload-review/lib.sh,scripts/offload-review.sh,scripts/offload-review_test.sh, and the changed parts ofSKILL.md. - Compared with the base (
3ef26ffd): theOFFLOAD_RULES_DIRheader line and the--cleanuprm -fwere already there; this PR adds only the doc catch-up and the assertion for them. - Grepped all callers of
unlock,unlock_if_held,self_pid,BASHPIDandOFFLOAD_RULES_DIR. No caller left that needs the old unconditionalunlock;unlock_if_heldhas no remaining reference. - Traced pid matching across subshells:
ensure_wtcallslockandunlockin the same subshell, soBASHPIDmatches. The top-level EXIT trap runs in the main shell, which never holds the lock, so it stays a no-op safety net. Same as the base design. - Traced
require_bash4placement: it runs before any repo, gh or network access, and no bash-4-only syntax is evaluated before it under bash 3.2 (sourcinglib.shonly defines functions). The refusal exits clean, with no EXIT trap set yet. - Traced the other new tests by hand: (g) both halves, (e), (h) first half, (i) all three parts, (d) rules-file assertion. Each runs the code it names.
- Checked data dependence, host boundary and client rules: tooling only (
scripts/, skill docs), no component or host package touched. No row update needed. The PR says so and the diff agrees. - Read the PR body and issue #1434. Read no PR comments or reviews (round 1).
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.332 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 622074823a52 |
blocking |
Verdict: blocking
Findings
- scripts/offload-review_test.sh:127-132 — the put-back test does not run the new code. It passes on the old
lib.shtoo.- What fails: the test claims to cover the new empty-pid branch of
lock_take_stale(lib.sh:60-63). That branch never runs. The new behavior ships with no effective test. - Proof: trace of
lock_take_stale "999999"on the state the test builds (a live lock at$lockdirwith pid$other, and a separate$lockdir.stale.testwith an empty pid):- The function makes its own
gonename,$lockdir.stale.$(self_pid).$RANDOM(lib.sh:50). It never sees$lockdir.stale.test. - Its first
mv "$lockdir" "$gone"(lib.sh:51) moves the live lock that line 130 created. nowreads$other, which is not empty.seenis999999. So the else branch runs (lib.sh:53).- The put-back
mv "$gone" "$lockdir"(lib.sh:60) succeeds, because the function itself removed$lockdirone line earlier. The newelifat lib.sh:62 never executes. - The assertion
[ -d "$lockdir.stale.test" ]passes because no code under test touches that directory. I checked the baselib.sh(3ef26ff): it produces the same result. The test cannot tell old code from new.
- The function makes its own
- Fix: make the branch reachable from a test. Extract the decision into a helper, for example
lock_orphan <dir> <pid>: remove the dir when the pid is dead, or when the pid is empty and the dir is over 60 s old; keep it otherwise.lock_take_stalecalls it when the put-back fails. Then test the helper directly: a young dir with an empty pid stays, an old one goes, a dead-pid one goes. The race itself (a new lock between the twomvcalls) is too narrow to drive from outside the function.
- What fails: the test claims to cover the new empty-pid branch of
Non-blocking
- .claude/skills/offload-review/SKILL.md:101 — the example still hardcodes
/tmp. Lines 95-96 say: use$OFFLOAD_RULES_DIRin every path below that names the rules file. Line 101 is below and names it:--live-tests /tmp/offload-review-pr<N>-rules.md. WhenOFFLOAD_RULES_DIRis set and the agent follows line 101, the file lands in/tmp, but--cleanupremoves it from$OFFLOAD_RULES_DIR(offload-review.sh:137). One leftover file. Update the example, or say the default in it. - PR body: the "Local tests: waived (owner rule)" line is not in it.
check-ready.shlooks for it in the body or a PR comment (interim rule). I did not read the PR comments, so it may be there. The PR-owning session should confirm before the hand-off.
What I checked
- The full diff (4 files) and the code around each change:
lib.shbefore and after,offload-review.sh,offload-review_test.shline by line, and the twoSKILL.mdhunks. - The lock state machine by hand, for each new branch: conditional
unlockfrom a holder, from a non-holder, and from the main shell's EXIT trap; the empty-pidelifin the failed put-back (young keeps, over 60 s goes,statfailure reads as age 0 and keeps);lock_agefallbacks on macOS and Linux;require_bash4with and without an argument. - Bash semantics, with small probes on this machine (not repo tests): a subshell and a backgrounded function get their own
BASHPIDwhile$$stays the script's pid (so on bash 3.2 the old code could not tell them apart — the gate is needed); subshells and background functions do not run the parent's EXIT trap (so the global trap cannot remove an attempt's lock or$skipdir). - The exit path of
offload-review.shunder bash 3.2: it stops at line 67, beforeghor any repo write. The/bin/bashprobe in test (i) is side-effect free. - That nothing else in the repo calls
unlock_if_held(deleted) or sourceslib.shoutsideoffload-review.shand its test. - Test (d)'s new assertion against
offload-review.sh:137, and test (g)/(e)/(i) against the new functions: each exercises the code it names. - The 4 gaps this PR closes against the #1434 round-2 review: 3 are closed and tested; the empty-pid put-back gap is closed in code but its test is finding 1.
- Repo rules: scripts and docs only, no library or host package, so no data-dependence row, no client rule and no behavior-change approval. Conventional title,
Signed-off-byandAssisted-Bypresent. - No tests were run (live tests not approved). The bash probes above check shell semantics only; they do not run this repo's test files.
amiddavid
left a comment
There was a problem hiding this comment.
| 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 | 622074823a52 |
blocking |
Verdict: blocking
Findings
-
PR description — Undocumented breaking change for bash 3.2 users
- What fails: Users on macOS with
/bin/bash(version 3.2) will get an error and the script will refuse to run. Before this PR, the script worked on bash 3.2. - Proof:
- Line 7 of
scripts/offload-review/lib.sh:require_bash4()checksBASH_VERSINFO[0]and returns 1 if less than 4 - Line 67 of
scripts/offload-review.sh:require_bash4 || exit 1stops the script - Line 16 of
scripts/offload-review/lib.sh:self_pid()now uses$BASHPIDwith no fallback. On bash 3.2,$BASHPIDis undefined, soself_pidreturns empty string - The old code at base commit used
${BASHPID:-$$}as fallback for bash 3.2 - Test at line 139-143 of
scripts/offload-review_test.shverifies the refusal message
- Line 7 of
- Fix: The PR description must state this behavior change at the top: "Breaking: offload-review now requires bash 4 or newer. Users on macOS with /bin/bash (3.2) must install bash 4+ with
brew install bashand put it first on PATH. The script will refuse to run on bash 3 with a clear error message." A human developer must approve this change before merge, per RELEASING.md "Behavior changes need a human's permission".
- What fails: Users on macOS with
-
scripts/offload-review/lib.sh:59-62 — Empty pid file logic may leave stale locks
- What fails: When
lock_take_staleputs back a renamed lock with an empty pid file, it checks the lock's age. But if the lock is exactly 60 seconds old or younger, it stays as.stale.*forever. The condition[ "$(lock_age "$gone")" -gt 60 ]only removes locks older than 60s, not equal to 60s. - Proof: Line 61:
elif [ "$(lock_age "$gone")" -gt 60 ]; then rm -rf -- "$gone"; fi. A lock at age 60 is not removed. The next waiter will see the main lock (put back by another process) and the.stale.*lock. The.stale.*lock blocks nobody, but it accumulates. - Fix: Change line 61 to
elif [ "$(lock_age "$gone")" -ge 60 ]; then rm -rf -- "$gone"; fito remove locks at 60s or older. Or document that locks younger than 60s are kept intentionally.
- What fails: When
Non-blocking
- The new
lock_age()helper at line 19-21 is a good refactoring. It removes code duplication and makes the age calculation consistent. - The test coverage for the new bash 4 requirement (lines 139-146 of
scripts/offload-review_test.sh) is thorough. It tests both the refusal message and the acceptance of bash 4. - The empty pid file handling (lines 123-135 of
scripts/offload-review_test.sh) adds a real edge case that was missing before. A lock with an empty pid file is now correctly treated as "not yet written" rather than "dead". - The function rename from
unlock_if_heldtounlockis clearer. The new name matches what the function does.
What I checked
- Read every changed line in the diff
- Compared the new
scripts/offload-review/lib.shwith the base version to understand what changed - Read the test file
scripts/offload-review_test.shto verify test coverage - Checked the skill documentation update in
.claude/skills/offload-review/SKILL.md - Verified against CLAUDE.md rules: no host boundary violations (these are shell scripts), no client-specific code (N/A), no data-dependence changes needed (N/A)
- Checked RELEASING.md for behavior change requirements
- Traced the bash 3.2 compatibility removal through
require_bash4(),self_pid()and the script's exit on failure - Verified the empty pid file logic in
lock_take_stale()against the test cases
- lock_orphan <dir> <pid> holds the keep-or-remove rule for a renamed lock that could not go back. lock_take_stale calls it. Tests call it directly. - The age rule is "60 s or older" in both places (waiter and orphan). - SKILL.md examples use $OFFLOAD_RULES_DIR. Refs #1436 Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5
|
Fixed in the new commit. The keep-or-remove rule is now |
|
Fixed: both places now use "60 s or older" ( |
|
Done: the PR body now starts with the behavior-change note, approved by the owner. |
|
Done: the SKILL.md examples now use |
amiddavid
left a comment
There was a problem hiding this comment.
| 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 | c78aeb4be87c |
approve |
Verdict: approve
Findings
None. Both findings from round 1 are fixed.
Status of round 1 findings
My findings (bob reviewer 1, round 1)
-
PR description — Undocumented breaking change: FIXED
- The PR body now starts with: "Behavior change, approved by the owner: offload-review.sh now needs bash 4 or newer..."
- The comment at 2026-11-26T11:24:36Z confirms the owner approved it
- Verified: the behavior change is documented and approved
-
scripts/offload-review/lib.sh:59-62 — Empty pid file logic may leave stale locks: FIXED
- Line 34 now uses
if [ "$age" -ge 60 ](was-gt 60) - Line 67 in
lock_orphan()useselif [ "$(lock_age "$1")" -ge 60 ] - Both places now use "60 s or older" consistently
- Test at line 138 verifies a lock at exactly 60s is removed:
touch -t "$(date -v-60S ..."thenlock_orphan "$d/o4" "" - Verified: the age check is correct and tested
- Line 34 now uses
Other reviewers' findings (glm reviewer 1 and 2, round 1)
Both glm reviewers raised the same core finding: the put-back test did not run the new code. The author fixed it by:
-
Extracting
lock_orphan()helper (lines 62-71 oflib.sh):- Takes
<dir> <pid>as parameters - Removes dir when pid is dead (line 64)
- Removes dir when pid is empty and dir is 60s or older (line 65-66)
- Keeps dir otherwise (live pid, or empty pid younger than 60s)
lock_take_stalecalls it at line 58 when the put-back fails
- Takes
-
Testing
lock_orphan()directly (lines 127-139 ofoffload-review_test.sh):- Young empty-pid: kept (line 128-129)
- Old empty-pid: removed (line 130-131)
- Dead pid: removed (line 132-133)
- Live pid: kept (line 134-136)
- Exactly 60s old: removed (line 138-139)
The test now exercises the actual code path. I verified by tracing each test case against the lock_orphan() implementation.
Non-blocking
- The SKILL.md examples now use
${OFFLOAD_RULES_DIR:-/tmp}(lines 101 and 154), addressing the non-blocking comment from glm reviewer 2. - The commit message follows conventions: conventional title,
Signed-off-by,Assisted-By, andRefs #1436.
What I checked
- Last review: round 1, 6220748, 2026-11-26T11:21:37Z
- New commits read: 1 commit (c78aeb4 "fix(review): test the empty-pid put-back rule through lock_orphan")
- Read in full: 4 reviews, 5 comments, 0 inline comments (from the three files)
- New items since my last review:
- Comment at 11:24:33Z: confirms
lock_orphan()extraction and test coverage - Comment at 11:24:34Z: confirms both age checks now use
-ge 60 - Comment at 11:24:36Z: confirms PR body updated with behavior change note
- Comment at 11:24:38Z: confirms SKILL.md examples updated
- Comment at 11:24:33Z: confirms
- Verified the new commit's diff line by line:
lib.shlines 24, 34, 58, 62-71: age check fixed,lock_orphan()addedoffload-review_test.shlines 127-139: direct tests oflock_orphan()SKILL.mdlines 101, 154: examples now use${OFFLOAD_RULES_DIR:-/tmp}
- Traced each test case in lines 127-139 against
lock_orphan()implementation to verify coverage - Checked that the PR body starts with the behavior change note and owner approval
- Verified no new host boundary violations, client rules, or data-dependence changes (still scripts only)
- Confirmed the "Local tests: waived (owner rule)" line is in the comments (2026-11-26T11:12:07Z)
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.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | c78aeb4be87c |
approve |
Verdict: approve
The new commit fixes my round-1 finding the right way. The keep-or-remove rule is now a
helper the tests can reach, and every case the rule names has a real test. I found no new
defect.
Earlier findings
- My finding 1 (the put-back test does not run the new code): fixed.
lock_orphan <dir> <pid>(lib.sh:65-72) holds the rule,lock_take_stalecalls it on a failed put-back
(lib.sh:58), and the tests call it directly. I traced each new test against the code:
young + empty pid kept, old + empty pid removed, dead pid removed, live pid kept, and the
exact age-60 boundary removed. Each one fails if the rule is inverted or dropped. The
author also verified this by scratch-editing the rule out and seeing test (h) fail. - Reviewer 1, finding 1 (same defect): fixed, agree. Same proof as above.
- Reviewer 1, non-blocking (the comment claimed a kept lock "stays until it is 60 s old",
but nothing re-checks it): fixed. Thelock_orphancomment says a kept one blocks
nobody and makes no 60 s claim. - Reviewer 1's and my non-blocking (
SKILL.mdexamples hardcoded/tmp): fixed. Both
examples now use${OFFLOAD_RULES_DIR:-/tmp}(SKILL.md:101, 154). - Reviewer 1 (bob), finding 1 (the bash 4 gate is a behavior change that needs a note and
the owner's yes): fixed. The PR body now starts with the note, and it names the owner's
approval. The note also states the old behavior correctly: bash 3.2 ran before, with a
weaker lock. - Reviewer 1 (bob), finding 2 (
-gt 60keeps an age-60 orphan): fixed. Both the waiter
andlock_orphanuse-ge 60now, the comments say "60 s or older" in both places, and a
test pins the boundary:touch -t <now minus 60 s>then remove. I checked the arithmetic:
the mtime is 60 s before the touch, andlock_orphanruns after the touch, so the age is
always 60 or more. The test is deterministic. - My non-blocking (the "Local tests: waived (owner rule)" line was not in the PR body):
resolved. It is on the PR as a comment from 2026-11-26T11:12:07Z.
Findings
None.
Non-blocking
- scripts/offload-review_test.sh — the put-back path of
lock_take_stalenow has no test.
The deleted vacuous test was the only one that ran the else branch (lib.sh:56-59): a
mismatched pid goes back to$lockdir. That branch is unchanged, pre-existing code, so
this does not block. One assertion would restore the coverage: create a lock with a live
pid, calllock_take_stale "999999", then check the lock is back at$lockdirwith the
same pid. The waiter's own age boundary (exactly 60 s inlock(), lib.sh:34) is also
untested, whilelock_orphan's is. The same scratch-edit method would cover both.
What I checked
- Last review: round 1, 6220748, 2026-11-26T11:20:40Z
- New commits read: 1 (c78aeb4 "fix(review): test the empty-pid put-back rule through
lock_orphan") - Read in full: 3 reviews, 5 comments, 0 inline comments (from the three files)
- New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (glm, 11:18): same finding as mine, plus two non-blocking
notes. Checked each against the fix commit; all fixed. - Reviewer 1's round-1 review (bob, 11:21): two findings. Checked both; both fixed.
- Author comments at 11:24: four replies, one per finding. Verified each claim against the
code and the PR body, not only the reply text. - Author comment at 11:12 ("Local tests: waived (owner rule)"): resolves my round-1 note.
- Reviewer 1's round-1 review (glm, 11:18): same finding as mine, plus two non-blocking
- The full diff of the new commit (3 files) and the final
lib.sh,offload-review_test.sh
andSKILL.mdaround each change. The diff from base to HEAD is the two commits together;
nothing else moved. lock_orphanby hand: dead pid removes, live pid keeps, empty pid removes at 60 s or
older and keeps below,statfailure reads as age 0 and keeps,return 0protects
set -ecallers.- The
lock_take_stalewiring:mv ... || lock_orphan "$gone" "$now"is the same logic as
the round-1 code, one line shorter. - The
-gtto-gechange: traced both places and the new boundary test for determinism
(see above). No test relied on the old boundary. - The new tests for pid fixtures: the dead pid is a reaped background subshell, the live pid
is asleep 30; both are sound. - The PR body: starts with the behavior-change note and the owner's approval, and the
"What changed" list matches the final code. - Repo rules: still scripts and docs only. No data-dependence row, no host package, no
client rule. The new commit has a conventional title,Signed-off-byandAssisted-By. - No tests were run (live tests not approved).
Behavior change, approved by the owner: offload-review.sh now needs bash 4 or newer. On macOS, /bin/bash is 3.2, so install bash with
brew install bashand put it first on PATH. On bash 3 the script stops with that message. Before, it ran on bash 3.2 with a weaker lock.Summary
Tooling only. No product behavior change. No data dependence change.
This closes the 4 small gaps in the offload-review lock code that #1434 left.
Refs #1436
What changed
unlockchecks the pid. It removes the lock only when the pid file holds this process's pid. It now replacesunlock_if_held, which did the same job.lock_take_staleno longer reads it as dead. The new helperlock_orphandecides for a renamed lock that cannot go back: remove it when the pid is dead, or empty and the dir is 60 s old or older; keep it otherwise. The waiter andlock_orphanboth use "60 s or older".#!/usr/bin/env bashfinds it when it comes first on PATH.--cleanupremoves the scratch rules file.$OFFLOAD_RULES_DIR(default/tmp).Why option (a) for bash 3.2
scripts/offload-review*needs bash 4. So this is a real choice.self_piduse$BASHPIDwith no fallback./bin/bash3.2 must install bash. The message says how.How it was tested
Tests ran on macOS, Go 1.27.4 (no Go code changed).
bash scripts/offload-review_test.sh(bash 5.2): all passed. New cases: (g) a stale holder'sunlockkeeps a new holder's lock, (h) a young lock with an empty pid is waited for and not taken, andlock_orphankeeps young+empty and live, removes old+empty, dead and age-60, (i) bash 3 is refused with a clear message./bin/bash scripts/offload-review_test.sh(bash 3.2): prints the refusal and stops./bin/bashand checks the refusal.bash -non the 3 scripts: ok.shellcheckis not installed.lock_orphanmade test (h) fail. A scratch edit from-geto-gtmade the age-60 case fail. Both were reverted.