Skip to content

fix(scripts): release the PR operation lock when review-init metadata fails - #125547

Merged
steipete merged 1 commit into
mainfrom
steipete/pr-review-init-prefetch-metadata
Aug 18, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/pr-review-init-prefetch-metadata

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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:

Retaining the operation lock for PR #124995; detached child tools cannot be ruled out.

and has to run scripts/pr lock-recover <pr> <token> --confirmed-no-running-tools before
retrying. 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_init called mark_pr_operation_side_effects_started as its very first
statement, before enter_worktree, so a purely read-only metadata failure was classified as
post-mutation and the lock was held.

pr_meta_json performs no mutation, so it now runs before the marker. The fetch uses
json=$(cd "$root" && pr_meta_json "$pr"): command substitution is already a subshell, so
gh gets the repo context it needs to resolve repos/{owner}/{repo} without moving the
caller's working directory, and enter_worktree still reports the real invocation cwd. The
assignment also gained an explicit || return 1 — it had none, so if review_init were ever
called from an OR-list (which disables errexit) an empty payload would have flowed into
write_pr_meta_files. review.sh already documents that hazard in
review_validate_artifacts.

Deliberate non-goal: ensure_gh_api_auth is untouched. Hoisting it alongside the metadata
fetch 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-init in the
scenario being fixed. Lock lifecycle, the recover token, and the compare-and-swap owner OID
are also untouched.

User Impact

A review-init that fails because GitHub was briefly unavailable now releases its lock
automatically. 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 real
scripts/pr review-init CLI with a failing pr_meta_json fixture. It asserts the lock ref
is gone, the metadata error is surfaced, neither the retention warning nor the
lock-recover guidance is printed, and enter_worktree never ran.

Verified failing on pre-change code for the intended reason — the lock ref still existed:

expect(refExists(repoDir), result.stderr).toBe(false)
- Expected: false
+ Received: true

Full suite after the change:

node scripts/run-vitest.mjs test/scripts/pr-operation-lock.test.ts \
  test/scripts/pr-metadata.test.ts test/scripts/pr-worktree-containment.test.ts \
  test/scripts/pr-review-artifact-validation.test.ts test/scripts/pr-wrappers.test.ts \
  test/scripts/pr-merge.test.ts
Test Files  6 passed (6)
Tests       155 passed | 1 skipped (156)

node scripts/check-changed.mjs green (format, typecheck, lint, guards, Testbox lane).
Fresh Codex autoreview clean: no accepted/actionable findings.

Production LOC is net-neutral (a move plus one || return 1 guard); the test file also
absorbed three duplicated stub-installation blocks into one helper.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 18, 2026 03:05
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S maintainer Maintainer-authored PR labels Aug 18, 2026
… 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.
@steipete
steipete force-pushed the steipete/pr-review-init-prefetch-metadata branch from 643928b to bdb477f Compare August 18, 2026 03:16
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 11:23 PM ET / August 18, 2026, 03:23 UTC.

ClawSweeper review

What this changes

The PR fetches pull-request metadata before review-init enters its side-effect phase, so a metadata failure releases the per-PR operation lock.

Regression provenance

Possible regression — probable (reviewed change; reproduction). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep 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
Reviewed head: bdb477f8bf7c9c65458fde94acbc87638b985d2d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair is narrow and well-targeted, with the remaining merge gate being the unavailable structured autoreview tool.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored internal tooling PR has focused real-wrapper regression coverage; external contributor proof requirements do not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal tooling PR has focused real-wrapper regression coverage; external contributor proof requirements do not apply.
Evidence reviewed 6 items Current-main defect: Current main marks side effects before calling pr_meta_json, so metadata failure follows the sticky-lock path.
Proposed owner-boundary repair: The branch obtains metadata before the marker and returns on failure before worktree entry; the marker remains immediately before the first side-effecting step.
Lock-release contract: The supervisor releases only completed, drained failures while the phase is validation; side-effect and signal failures remain conservative.
Findings None None.
Security None None.

How this fits together

The scripts/pr review-init command serializes maintainer review work with a per-PR lock. Its supervisor releases drained validation-phase failures but retains locks after worktree or artifact side effects.

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

Before merge

  • Resolve merge risk (P1) - A fresh structured autoreview remains required before merge; it currently fails closed because TruffleHog is unavailable in this review environment.
  • Complete next step (P2) - Provide TruffleHog and rerun the required structured autoreview on the exact PR head before merge.
Agent review details

Security

None.

PR surface

Tests +23, Other +5. Total +28 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 33 10 +23
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 8 3 +5
Total 2 41 13 +28

Review metrics

Metric Value Why it matters
Production versus test delta production +8/-3; tests +33/-10 Production changes only reorder metadata collection and propagate failure; test growth adds the CLI regression case and consolidates repeated stubs.

Stored data model

Persistent data-model change detected: vector/embedding metadata: scripts/pr-lib/review.sh, vector/embedding metadata: test/scripts/pr-operation-lock.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete the structured review gate (recommended)
    Install or provide TruffleHog, then rerun the bundled autoreview helper against this exact head before merge.

Technical review

Best 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 pr_meta_json, so a failed metadata read retains the lock; the new fixture targets that exact CLI path.

Is this the best way to solve the issue?

Yes: pr_meta_json is read-only and precedes worktree creation, so moving only that call before the existing marker is the narrowest maintainable repair.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 974a52f64f53.

Labels

Label changes:

  • add P2: This repairs maintainer PR-review automation after transient GitHub metadata failures.
  • add merge-risk: 🚨 automation: The changed phase boundary determines whether a failed PR operation retains its serialization lock.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal tooling PR has focused real-wrapper regression coverage; external contributor proof requirements do not apply.

Label justifications:

  • P2: This repairs maintainer PR-review automation after transient GitHub metadata failures.
  • merge-risk: 🚨 automation: The changed phase boundary determines whether a failed PR operation retains its serialization lock.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal tooling PR has focused real-wrapper regression coverage; external contributor proof requirements do not apply.

Evidence

Acceptance criteria:

  • [P1] ./.agents/skills/autoreview/scripts/autoreview --mode branch --base 974a52f --stream-engine-output.

What I checked:

  • Current-main defect: Current main marks side effects before calling pr_meta_json, so metadata failure follows the sticky-lock path. (scripts/pr-lib/review.sh:316, 974a52f64f53)
  • Proposed owner-boundary repair: The branch obtains metadata before the marker and returns on failure before worktree entry; the marker remains immediately before the first side-effecting step. (scripts/pr-lib/review.sh:322, bdb477f8bf7c)
  • Lock-release contract: The supervisor releases only completed, drained failures while the phase is validation; side-effect and signal failures remain conservative. (scripts/pr-lib/process-group-runner.mjs:348, bdb477f8bf7c)
  • Regression coverage: The added fixture drives the real wrapper, forces metadata failure, and asserts lock removal, surfaced error, no recovery guidance, and no worktree entry. (test/scripts/pr-operation-lock.test.ts:939, bdb477f8bf7c)
  • History and adjacent ownership: History shows the same area’s metadata repair in merged commit 44b41d5 and prior lock-fixture work by the same primary contributor. (scripts/pr-lib/review.sh:314, 44b41d5686dc)
  • Structured-review blocker: The required bundled autoreview helper failed closed before review because TruffleHog is not installed.

Likely related people:

  • steipete: History shows sustained authorship of review-init, metadata-read handling, and PR operation-lock behavior. (role: feature owner; confidence: high; commits: bdb477f8bf7c, d1dea39bbb09, 9e3b87430988; files: scripts/pr-lib/review.sh, test/scripts/pr-operation-lock.test.ts)
  • Vincent Koc: History credits the validation-phase temporary-storage behavior covered by the same lock regression suite. (role: adjacent contributor; confidence: medium; commits: f73eb88eda21; files: test/scripts/pr-operation-lock.test.ts, scripts/pr-lib/common.sh)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rerun the bundled autoreview helper after TruffleHog is available.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit de41c7d into main Aug 18, 2026
148 checks passed
@steipete
steipete deleted the steipete/pr-review-init-prefetch-metadata branch August 18, 2026 03:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant