Repository navigation
fix(scripts): release the PR operation lock when review-init metadata fails - #125547
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
… fails The lock auto-releases only while the pre-side-effect validation marker is active; review_init marked side effects before the read-only metadata fetch, so a transient GitHub failure retained the lock and forced a lock-recover loop. The read-only fetch now runs before the marker.
643928b to
bdb477f
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 11:23 PM ET / August 18, 2026, 03:23 UTC. ClawSweeper reviewWhat this changesThe PR fetches pull-request metadata before review-init enters its side-effect phase, so a metadata failure releases the per-PR operation lock. Regression provenancePossible regression — probable (reviewed change; reproduction). No predecessor PR is attributed. Merge readinessKeep open. The patch is a coherent, narrow repair for a current maintainer-tooling failure and has no blocking code finding; a fresh structured autoreview could not run because TruffleHog is unavailable. Priority: P2 Review scores
Verification
How this fits togetherThe flowchart LR
A[Run review-init] --> B[Acquire operation lock]
B --> C[Read GitHub metadata]
C --> D{Metadata succeeds?}
D -->|No| E[Release validation lock]
D -->|Yes| F[Start side-effect phase]
F --> G[Create worktree and artifacts]
Before merge
Agent review detailsSecurityNone. PR surfaceTests +23, Other +5. Total +28 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep metadata retrieval before the marker and retain the existing conservative lock behavior after worktree creation or later side effects. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main starts side effects before Is this the best way to solve the issue? Yes: AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 974a52f64f53. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
… fails (openclaw#125547) The lock auto-releases only while the pre-side-effect validation marker is active; review_init marked side effects before the read-only metadata fetch, so a transient GitHub failure retained the lock and forced a lock-recover loop. The read-only fetch now runs before the marker.
Follow-up to #125517, which named this as the remaining gap.
What Problem This Solves
Resolves a problem where a transient GitHub outage during
scripts/pr review-init <PR>leaves the per-PR operation lock behind. #125517 stopped the misleading
"PR head changed" diagnosis and added a bounded retry, but when all retries fail the
maintainer still gets:
and has to run
scripts/pr lock-recover <pr> <token> --confirmed-no-running-toolsbeforeretrying. The recover token changes on every attempt, so a flaky GitHub window turns into a
manual recover-and-retry loop.
Why This Change Was Made
The lock auto-releases on failure only while the pre-side-effect validation marker is still
active.
review_initcalledmark_pr_operation_side_effects_startedas its very firststatement, before
enter_worktree, so a purely read-only metadata failure was classified aspost-mutation and the lock was held.
pr_meta_jsonperforms no mutation, so it now runs before the marker. The fetch usesjson=$(cd "$root" && pr_meta_json "$pr"): command substitution is already a subshell, soghgets the repo context it needs to resolverepos/{owner}/{repo}without moving thecaller's working directory, and
enter_worktreestill reports the real invocation cwd. Theassignment also gained an explicit
|| return 1— it had none, so ifreview_initwere evercalled from an OR-list (which disables errexit) an empty payload would have flowed into
write_pr_meta_files.review.shalready documents that hazard inreview_validate_artifacts.Deliberate non-goal:
ensure_gh_api_authis untouched. Hoisting it alongside the metadatafetch looks tempting for its actionable "run gh auth login" hint, but it runs a GraphQL
viewer query and is intentionally non-fatal. During exactly the GraphQL degradation this work
targets it can fail spuriously, so hoisting or hardening it would block
review-initin thescenario being fixed. Lock lifecycle, the recover token, and the compare-and-swap owner OID
are also untouched.
User Impact
A
review-initthat fails because GitHub was briefly unavailable now releases its lockautomatically. Maintainers can simply re-run the command instead of copying a fresh recover
token out of the error and confirming no detached tools are running. Failures that occur
after real mutation still retain the lock, exactly as before. Maintainer tooling only; no
user-facing product behavior changes.
Evidence
New regression test in
test/scripts/pr-operation-lock.test.ts, driving the realscripts/pr review-initCLI with a failingpr_meta_jsonfixture. It asserts the lock refis gone, the metadata error is surfaced, neither the retention warning nor the
lock-recoverguidance is printed, andenter_worktreenever ran.Verified failing on pre-change code for the intended reason — the lock ref still existed:
Full suite after the change:
node scripts/check-changed.mjsgreen (format, typecheck, lint, guards, Testbox lane).Fresh Codex autoreview clean: no accepted/actionable findings.
Production LOC is net-neutral (a move plus one
|| return 1guard); the test file alsoabsorbed three duplicated stub-installation blocks into one helper.