Skip to content

fix(scripts): PR preparation fails when GitHub serves a stale head ref - #146950

Merged
steipete merged 3 commits into
mainfrom
codex/pr-exact-head-acquisition
Sep 13, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/pr-exact-head-acquisition

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #140897.

What Problem This Solves

PR review and preparation can fetch an older commit when GitHub's pull-head ref lags the current PR branch and metadata.

User Impact

Maintainers can prepare and land the verified PR commit despite a delayed GitHub ref. This changes maintainer tooling only; Gateway behavior is unchanged.

Why This Change Was Made

One shared acquisition operation fetches the full commit SHA verified by live PR metadata from the canonical origin. It verifies the fetched commit and rejects changes to the PR head, branch, or repository across the fetch. Review, preparation, publication verification, and merge checks all use this operation. Existing review, CI, ancestry, merge, and source-identity gates remain in place; PR acquisition preserves the private main checkpoint and shared tracking refs.

Evidence

The issue was observed on #140897: PR metadata and the named branch pointed to d49a43e, while GitHub's read-only pull-head ref still returned 81c77fe, including after one close/reopen.

The stale-ref and identity-drift regressions failed before the repair and pass afterward. The native workflow suite passed 165 tests across four files, including preparation, publication races, retained merge receipts, and cross-checkout ownership. The final two-case origin/refmap and main-checkpoint proof passed, as did changed-file checks, test types, and lint. Independent P0–P2 review found no actionable defects.

The first CI run exposed six missed fixture updates across operation-lock, merge-bypass, and review-artifact tests. Those failures reproduced locally; the related containment fixture was repaired as well. The follow-up changes only four test files and passes 46 focused contract cases, types, lint, and fresh independent P0–P2 review. Production code is unchanged. That CI run confirmed the original six failures were repaired, then exposed two literal-transition cases lacking review initialization. A one-line fixture correction passes the entire unfiltered 67-case containment suite, types, lint, and fresh P0–P2 review. All production bytes remain unchanged. CI34754466324 passed on final head ad5eca282d996d937ebc0a73594903c9f7882013; all 98 current checks pass and 28 are skipped by their owning workflows. The current ClawSweeper review has no remaining blocker.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: M maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 10:55
@steipete steipete self-assigned this Sep 13, 2026
@clawsweeper clawsweeper Bot added 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 Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 7:33 AM ET / 11:33 UTC (Revision 3).

ClawSweeper review

What this changes

The PR makes maintainer tooling fetch the commit identified by live GitHub metadata, reject identity changes during acquisition, and preserve the main-branch checkpoint.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main. No blocking defect was found, and the previously failing containment-test shard now passes on the reviewed head.

Priority: P2
Reviewed head: ad5eca282d996d937ebc0a73594903c9f7882013

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and the prior fixture failure addressed.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate; its native Git fixtures cover the changed acquisition owner with synthetic GitHub metadata, and the linked incident establishes the original failure.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate; its native Git fixtures cover the changed acquisition owner with synthetic GitHub metadata, and the linked incident establishes the original failure.
Evidence reviewed 7 items Current main still contains the defect: Preparation fetches pull/<PR>/head and rejects it when that projection differs from the reviewed SHA, matching the reported stale-ref failure.
Latest release comparison: The same pull-head fetch and mismatch rejection are present in v2026.9.4; the requested repair is not already supplied by that release.
Shared acquisition owner: The introduced helper validates the full SHA and destination, fetches through the canonical origin without writing FETCH_HEAD, verifies the fetched commit, and compares metadata before and after acquisition. All six production acquisition call sites use it.
Findings None None.
Security None None.

How this fits together

OpenClaw’s PR tooling acquires contributor source for review, preparation, publication verification, and merge checks. GitHub metadata identifies the expected commit, while Git supplies its contents for the existing review and landing gates.

flowchart TD
  A[PR operation] --> B[Live GitHub metadata]
  B --> C[Validate expected commit]
  C --> D[Fetch commit from canonical origin]
  D --> E[Verify commit and reread identity]
  E --> F[Continue review and landing gates]
  E --> G[Stop on identity drift]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +118, Docs +1, Other +36. Total +155 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 7 153 35 +118
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 5 63 27 +36
Total 13 217 62 +155

Review metrics

Metric Value Why it matters
Production versus test growth production +36 net lines; tests and fixtures +118 net lines Production growth centralizes commit acquisition and identity validation; test growth covers stale projections and checkpoint preservation.

Technical review

Best possible solution:

Use one metadata-validated acquisition owner throughout the native PR workflow while retaining existing review, publication-lease, and final merge checks.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: stale pull-head refs cause current preparation to reject the reviewed commit, and the added native-workflow fixtures model that exact disagreement. No tests or live workflow were executed during this read-only review.

Is this the best way to solve the issue?

Yes. Fetching the metadata-pinned commit through the existing canonical-origin owner removes the stale projection dependency without bypassing downstream identity or landing checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6f27bf18da4e.

Labels

Label justifications:

  • P2: This repairs a concrete maintainer preparation failure with a limited tooling-only blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate; its native Git fixtures cover the changed acquisition owner with synthetic GitHub metadata, and the linked incident establishes the original failure.

Evidence

What I checked:

  • Current main still contains the defect: Preparation fetches pull/<PR>/head and rejects it when that projection differs from the reviewed SHA, matching the reported stale-ref failure. (scripts/pr-lib/prepare-core.sh:223, 6f27bf18da4e)
  • Latest release comparison: The same pull-head fetch and mismatch rejection are present in v2026.9.4; the requested repair is not already supplied by that release. (scripts/pr-lib/prepare-core.sh:223, 3a9d69db306c)
  • Shared acquisition owner: The introduced helper validates the full SHA and destination, fetches through the canonical origin without writing FETCH_HEAD, verifies the fetched commit, and compares metadata before and after acquisition. All six production acquisition call sites use it. (scripts/pr-lib/worktree.sh:238, ad5eca282d99)
  • Regression coverage and incident context: The tests exercise six native commands against a stale pull ref, reject SHA/branch/repository drift, and preserve private and shared checkpoints. The captured PR body connects this to the observed metadata-versus-pull-ref disagreement on perf(sessions): keep cleanup responsive and reuse workers #140897. GitHub responses in the fixture are synthetic; these tests were inspected, not executed during this review. (test/scripts/pr-main-refresh.test.ts:39, ad5eca282d99)
  • Prior review follow-up resolved: GitHub’s commit endpoint confirms that the latest commit changes only the literal-transition fixture setup from review-checkout-main to review-init, providing the metadata now required before PR checkout. (test/scripts/pr-worktree-containment.test.ts:937, ad5eca282d99)
  • Previously failing shard passes: The current-head checks-node-compact-small-31 job completed successfully. The bounded response covered 100 of 131 check runs, so this does not claim that all CI has completed. (ad5eca282d99)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-13T11:03:03.807Z sha 42644d8 :: blocked before merge. :: none
  • reviewed 2026-09-13T11:20:56.262Z sha fd0d245 :: blocked before merge. :: none

@steipete
steipete merged commit 8d04044 into main Sep 13, 2026
137 of 138 checks passed
@steipete
steipete deleted the codex/pr-exact-head-acquisition branch September 13, 2026 11:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
openclaw#146950)

* fix(scripts): prepare PRs despite stale GitHub head refs

* test(scripts): migrate remaining PR acquisition fixtures

* test(scripts): initialize literal transition review fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M 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