Skip to content

fix(pr): bind review artifacts to the PR being landed - #114897

Merged
steipete merged 1 commit into
mainfrom
fix/pr-review-artifact-identity
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/pr-review-artifact-identity

Conversation

@steipete

@steipete steipete commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The review gate could approve one PR's verdict for a different PR. That is the defect — not the artifact clutter that led me to it.

scripts/pr review-validate-artifacts had no way to tell whose review it was validating. review_guard compares the checked-out HEAD against PR_HEAD_SHA read from .local/pr-meta.env — but both live in the same .local directory, so a wholesale foreign artifact set is internally self-consistent and passes every check. validateReviewArtifacts read .local/pr-meta.json only to count runtime files for the behavioral-sweep rule; it never compared the review to the PR being landed, because there was nothing in the review to compare. Neither review.json nor review.md named a PR at all.

Proof, using two real artifact sets produced by the real flow on one machine — the READY FOR /prepare-pr verdict written while reviewing #114388, placed in the landing directory of #114897, whose pr-meta.json came from an actual scripts/pr review-init 114897:

PR being landed : #114897 at 537fa698569ba00eeea4efde2b349632752712e5
verdict on disk : READY FOR /prepare-pr
…which was written about: The PR body states the concrete ambient-misrouting problem and user impact…
…i.e. a different PR entirely. Nothing in the artifact names a PR.

=== BEFORE (origin/main gate) ===
exit=0   <-- the gate ACCEPTS another PR's READY verdict for #114897

=== AFTER (this PR's gate, byte-identical inputs) ===
Invalid PR identity in .local/review.json: pr.number must be an integer and pr.headSha must be a string; re-run scripts/pr review-artifacts-init
Review artifact identity mismatch in .local/review.md: first line must be "Review artifact for PR #114897 at 537fa698569ba00eeea4efde2b349632752712e5"; re-run scripts/pr review-artifacts-init
2 artifact violations
exit=1   <-- refused

Three agents hit this tonight, each finding artifacts pre-filled with another PR's review, and validation passing on that content. An agent trusting the flow rather than re-reading every field would submit someone else's verdict as its own and land on it.

Two contributing details, both verified against source rather than inherited:

  • Artifacts have always lived in the per-PR worktree. git show f3055f64f4a^:scripts/pr-lib/worktree.sh shows the pre-fix(pr): keep landing mutations inside the dedicated PR worktree #114723 enter_worktree already did cd .worktrees/pr-$pr and mkdir -p .local. fix(pr): keep landing mutations inside the dedicated PR worktree #114723 changed containment, not location. So "the artifacts moved" is not the explanation, and directory separation alone was never the fix.
  • review_claim was the one subcommand running in the shared canonical checkout (cd "$root"; mkdir -p .local), writing review-claim-*.log there. That is why the canonical root carries a script-owned-looking .local — on this machine it holds those logs beside a stray review.json/review.md for an unrelated PR. An author whose shell cwd is the canonical root writes artifacts there while the validator reads the worktree copy, producing exactly the "the values reported back aren't what I wrote" confusion.

Why This Change Was Made

Make cross-PR contamination structurally impossible rather than something a reviewer must notice.

  • Both artifacts are stamped. review.json gains pr: { number, headSha }; review.md is now generated by the same helper with a first-line identity header, which also removes a duplicated template heredoc from the shell. Binding only the JSON would let a foreign markdown verdict — the prose a human actually reads — ride along with a freshly stamped JSON.
  • The identity chain is anchored end to end. Validation rejects a stamp disagreeing with .local/pr-meta.json, and validate_review_artifact_data now ties pr-meta.json itself to pr-meta.env, which review_guard binds to the CLI argument and the checked-out head: CLI arg → pr-meta.env → HEAD, and pr-meta.env → pr-meta.json → review.json + review.md. Without that last link, the authority for the stamp was just another local file that travels with the artifacts. Both prepare-init and merge-run run this path.
  • Init no longer adopts artifacts it did not stamp. Mismatches are archived into a mktemp -d directory under .local/superseded/ — allocated atomically so a retry, a concurrent init, or a repeated clock second cannot overwrite an earlier preserved review — never deleted, because a mid-review head change is legitimate and the prose is worth salvaging.
  • review_claim moves into the PR worktree, so no scripts/pr subcommand writes review state to the shared canonical checkout. Claiming still works on a cold PR because enter_worktree provisions both the worktree and .local.

Head-SHA binding also mechanically enforces an existing repository rule: after a push and a fresh review-init, a review stamped against the superseded head fails instead of quietly gating the new one.

.worktrees/ residue — no new command, deliberately

scripts/pr gc [--dry-run] already exists, takes per-PR operation locks, and reclaims worktrees plus branches for MERGED/CLOSED PRs; merge_run already reclaims on success. scripts/pr ls on the canonical checkout shows the residue is exactly gc-eligible: 104923 CLOSED, 112542/112958/113076 MERGED, 114388 legitimately OPEN, plus an unparseable pr-wrapper-112442. So this is operator hygiene, not missing tooling.

Auto-running gc from enter_worktree would be actively wrong: gc walks other PRs and takes their operation locks, so one landing would contend with concurrent landings — the exact hazard this PR exists to remove. Post-#114723 enter_worktree already refuses or repairs a stale directory before any branch moves, so the residue is disk usage, not a correctness risk. No code change.

User Impact

Maintainer/agent tooling only; no runtime, product, config, or plugin surface. scripts/pr review-artifacts-init now requires .local/pr-meta.json (already written by review-init) and re-stamps artifacts it did not author, preserving the originals under .local/superseded/. In-progress reviews stamped for the current PR and head are untouched. This is a deliberate fail-closed change to a landing gate.

Evidence

Real behavior proof, after the fix, on real artifacts (no fixtures). Landing directory seeded with real pr-meta.json from scripts/pr review-init and the real review artifacts authored for a different PR:

=== review_artifacts_init on the contaminated set ===
moved aside .local/review.json -> .local/superseded/20260728T034302Z-yGLvnb/review.json (not authored for PR #114388 at ef661baa1d2e…)
moved aside .local/review.md   -> .local/superseded/20260728T034302Z-yGLvnb/review.md   (not authored for PR #114388 at ef661baa1d2e…)
review artifact templates are ready

foreign verdict preserved, not deleted: READY FOR /prepare-pr
fresh artifact is stamped for the landing PR: {"number":114388,"headSha":"ef661baa1d2ee2196d3dd72bb0794f6cb20fd699"}
fresh markdown identity line: Review artifact for PR #114388 at ef661baa1d2ee2196d3dd72bb0794f6cb20fd699

=== a matching in-progress review is preserved, not clobbered ===
review artifacts already stamped for PR #114388 at ef661baa1d2ee2196d3dd72bb0794f6cb20fd699
in-progress prose still there: A) half-written prose worth keeping
in-progress summary still there: Half-written review worth keeping.

The cross-PR rejection transcript is in What Problem This Solves above (exit=0 before, exit=1 after, byte-identical inputs).

This PR's own landing also exercised the real flow: review-init → review-checkout-pr → review-artifacts-init → review-validate-artifacts, all against the canonical wrapper. Worth recording: the freshly created .worktrees/pr-114897 produced clean, unfilled templates. Contamination is not automatic on a fresh worktree — it needs a reused artifact location, which is exactly what the stamp now catches.

Other proof:

  • node scripts/run-vitest.mjs test/scripts/pr-review-artifact-validation.test.ts test/scripts/pr-merge.test.ts test/scripts/pr-worktree-containment.test.ts — 45 passed. New coverage rejects a review stamped for another PR, a superseded head, an unstamped review, a foreign markdown header, and a self-consistent set whose pr-meta.json disagrees with the guarded PR; init archives foreign artifacts, preserves matching in-progress work, and re-stamps foreign markdown even when the JSON stamp matches; review_guard rejects mismatched pr-meta.env.
  • node scripts/check-changed.mjs — exit=0 (typecheck test root + scripts lint, Testbox tbx_01kykby60ma05tce43mzhkanvy).
  • CI green on exact head 537fa698569 — run 30325983523.
  • oxfmt on touched JS/TS; git diff --check clean.
  • Codex autoreview (gpt-5.6-sol, xhigh) three rounds. Round 1 accepted two findings: markdown not identity-bound, and a one-second-resolution archive name mv could overwrite. Round 2 accepted one: pr-meta.json was itself unanchored. All fixed. Round 3's only finding claimed review_claim breaks on a cold PR — rejected as factually incorrect, since enter_worktree provisions the worktree and .local; the reason is recorded inline.
  • git diff --numstat: review-artifacts.mjs +97/-11, review.sh +66/-28, test +203/-7. Non-test growth is a new integrity gate, not a refactor; the unconditional-adoption path and the duplicated markdown heredoc are deleted.

scripts/pr review artifacts carried no PR identity, so a review authored for
another PR validated clean and could gate someone else's landing. Stamp both
review.json and review.md with the reviewed PR number and head, anchor
pr-meta.json to the guarded pr-meta.env, and re-stamp foreign artifacts on init
instead of silently adopting them. review-claim now works in the PR worktree so
no subcommand writes review state to the shared canonical checkout.
@steipete
steipete marked this pull request as ready for review July 28, 2026 03:27
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: M maintainer Maintainer-authored PR labels Jul 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 11:49 PM ET / July 28, 2026, 03:49 UTC.

ClawSweeper review

What this changes

This PR stamps local JSON and Markdown review artifacts with the reviewed PR number and commit, validates them against PR metadata, archives mismatched artifacts, and keeps review-claim logs inside the dedicated PR worktree.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

The PR addresses a real landing-gate integrity gap: the current artifact validator checked review content and local metadata but did not bind either review artifact to the requested PR and head. The proposed JSON/Markdown identity chain, archival behavior, and worktree-scoped claim logs are a coherent fix; keep it open for the normal maintainer merge decision and a quick refresh against current main because the branch is behind.

Priority: P2
Reviewed head: 537fa698569ba00eeea4efde2b349632752712e5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong real-flow evidence and focused regression coverage support a coherent fix; the only material remaining step is a current-main merge refresh for an automation gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes after-fix terminal evidence from the real scripts/pr artifact flow: it rejects a foreign verdict, archives and re-stamps mismatched artifacts, and preserves matching in-progress artifacts. The transcript is appropriate for this non-visual internal automation change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes after-fix terminal evidence from the real scripts/pr artifact flow: it rejects a foreign verdict, archives and re-stamps mismatched artifacts, and preserves matching in-progress artifacts. The transcript is appropriate for this non-visual internal automation change.
Evidence reviewed 6 items Current validation gap: The current-main review_validate_artifacts validates artifact shape, recommendation fields, and review mode, while review_guard compares HEAD only with PR_HEAD_SHA from .local/pr-meta.env; neither current artifact format carries a PR number or head SHA.
End-to-end artifact binding: The proposed artifact helper adds pr.number and pr.headSha to the JSON template and a matching first-line identity header to the Markdown template, then validates them against PR metadata.
Guard and initialization coverage: The proposed shell changes reject a PR-number mismatch in .local/pr-meta.env, require .local/pr-meta.json before template setup, and archive mismatched artifacts instead of silently adopting them.
Findings None None.
Security None None.

How this fits together

The scripts/pr workflow creates metadata and review artifacts inside a dedicated worktree before allowing preparation or merge. Those artifacts form an automation gate, so the validator must establish that the written verdict belongs to the exact PR and commit being landed.

flowchart LR
  A[Landing command] --> B[Dedicated PR worktree]
  B --> C[PR metadata files]
  C --> D[JSON and Markdown review artifacts]
  D --> E[Identity-chain validation]
  E --> F[Prepare and merge gates]
  F --> G[Only matching verdict proceeds]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main; although GitHub reports it cleanly mergeable, the final merge result should receive a brief review/proof refresh because this is a fail-closed landing gate.
  • Complete next step (P1) - The patch has no concrete code defect to repair automatically; because it changes a fail-closed landing gate and carries the maintainer label, the remaining action is a maintainer merge decision after a current-main refresh.
Agent review details

Security

None.

PR surface

Tests +196, Other +124. Total +320 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 203 7 +196
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 162 38 +124
Total 3 365 45 +320

Review metrics

Metric Value Why it matters
Artifact identity chain 2 review artifacts bound; 3 metadata links checked Both the machine-readable verdict and the human-readable review are tied through PR metadata to the guarded PR and checked-out head.

Merge-risk options

Maintainer options:

  1. Refresh against current main before merge (recommended)
    Rebase or otherwise refresh the clean merge result, then confirm the focused artifact-validation path still rejects a foreign verdict and preserves a matching in-progress review.
  2. Accept the existing exact-head proof
    A maintainer may accept the supplied real-artifact transcript and successful exact-head checks if the clean three-way merge does not alter the reviewed scripts.

Technical review

Best possible solution:

Land a single authoritative review-artifact identity chain: PR metadata, JSON verdict, and human-readable Markdown verdict must all agree on the requested PR and exact head, while mismatched in-progress artifacts are preserved outside the active gate.

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

Yes, at source level: current validation accepts well-formed review artifacts without an artifact-level PR/head identity, while the supplied real-artifact transcript demonstrates the foreign-verdict scenario and the proposed rejection path.

Is this the best way to solve the issue?

Yes. Binding both review representations to PR metadata and the checked-out head is narrower and safer than relying on directory placement or reviewer vigilance; the preservation path avoids discarding legitimate in-progress review work.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal evidence from the real scripts/pr artifact flow: it rejects a foreign verdict, archives and re-stamps mismatched artifacts, and preserves matching in-progress artifacts. The transcript is appropriate for this non-visual internal automation change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal evidence from the real scripts/pr artifact flow: it rejects a foreign verdict, archives and re-stamps mismatched artifacts, and preserves matching in-progress artifacts. The transcript is appropriate for this non-visual internal automation change.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes a bounded but consequential integrity defect in maintainer PR landing automation.
  • merge-risk: 🚨 automation: The patch changes the validation gate that determines whether preparation and merge commands may use local review artifacts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal evidence from the real scripts/pr artifact flow: it rejects a foreign verdict, archives and re-stamps mismatched artifacts, and preserves matching in-progress artifacts. The transcript is appropriate for this non-visual internal automation change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal evidence from the real scripts/pr artifact flow: it rejects a foreign verdict, archives and re-stamps mismatched artifacts, and preserves matching in-progress artifacts. The transcript is appropriate for this non-visual internal automation change.

Evidence

What I checked:

  • Current validation gap: The current-main review_validate_artifacts validates artifact shape, recommendation fields, and review mode, while review_guard compares HEAD only with PR_HEAD_SHA from .local/pr-meta.env; neither current artifact format carries a PR number or head SHA. (scripts/pr-lib/review.sh:1, cf4cb0ac852a)
  • End-to-end artifact binding: The proposed artifact helper adds pr.number and pr.headSha to the JSON template and a matching first-line identity header to the Markdown template, then validates them against PR metadata. (scripts/pr-lib/review-artifacts.mjs:32, 537fa698569b)
  • Guard and initialization coverage: The proposed shell changes reject a PR-number mismatch in .local/pr-meta.env, require .local/pr-meta.json before template setup, and archive mismatched artifacts instead of silently adopting them. (scripts/pr-lib/review.sh:108, 537fa698569b)
  • Regression coverage: The focused script test changes cover foreign PR stamps, superseded heads, unstamped artifacts, a foreign Markdown header, mismatched PR metadata, archival of foreign artifacts, and preservation of matching in-progress reviews. (test/scripts/pr-review-artifact-validation.test.ts:12, 537fa698569b)
  • Adjacent worktree provenance: The related merged containment work established the dedicated-worktree funnel used here; this PR closes the separate gap that review artifacts themselves lacked identity binding. (scripts/pr-lib/worktree.sh:1, f3055f64f4a3)
  • Real-flow proof and CI: The PR body supplies an after-fix terminal transcript using real artifacts, showing rejection of a foreign verdict, archival/re-stamping of mismatched artifacts, and preservation of a matching in-progress review; the provided PR context also reports focused tests and successful checks on head 537fa698569. (537fa698569b)

Likely related people:

  • steipete: Introduced the merged dedicated-worktree containment path and authored the current identity-binding follow-up in the same scripts/pr landing subsystem. (role: recent area contributor; confidence: high; commits: f3055f64f4a3, 537fa698569b; files: scripts/pr-lib/worktree.sh, scripts/pr-lib/review-artifacts.mjs, scripts/pr-lib/review.sh)

Rank-up moves

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

  • Refresh the clean merge result against current main and confirm the focused review-artifact validation scenario on that final head.

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 (1 earlier review cycle)
  • reviewed 2026-07-28T03:31:53.906Z sha 537fa69 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Owner decision on the fail-closed artifact lifecycle

ClawSweeper's Decision needed item — "Should the landing-tool owners accept the new fail-closed artifact lifecycle?" — is answered: accepted, land as-is (fail closed).

Decision-maker: Peter Steinberger (repo owner/maintainer). He was presented with three options — land as-is fail-closed, warn instead of refuse, or hold for his own review — and chose to land as-is. The known one-time friction was put to him explicitly and accepted: any in-flight landing that is holding pre-existing unstamped artifacts must re-run scripts/pr review-artifacts-init <PR> before it can merge.

Provenance, stated honestly: this decision was relayed to me by the coordinating agent. I did not observe it first-hand, and I am recording it rather than attesting to it.

Marking the decision item satisfied, not skipped. The other two rank-up moves — "add real behavior proof" and the associated P1 merge risk — were addressed by the before/after transcripts now in the PR body, produced from two real artifact sets generated by the real scripts/pr flow rather than fixtures.

On the protected maintainer label: treated as a process gate requiring maintainer handling, which the owner decision above provides. I have not added, removed, or altered any protected label on my own authority.

One honest irony worth recording

This PR lands through the very gate it hardens, running the old, unstamped code path. Its own review artifacts were produced by review-artifacts-init on current main, so they carry no pr stamp and no markdown identity line — and the new validator would reject them, exactly as the transcript in the PR body shows for an unstamped review.json. That is expected rather than alarming: the stamp cannot exist on the code path that predates it. The practical consequence is the one-time friction the owner accepted — the next landing after this merges must run review-artifacts-init to obtain stamped artifacts, and a landing already holding unstamped ones will fail closed until it does.

@steipete
steipete merged commit cba26e3 into main Jul 28, 2026
163 of 179 checks passed
@steipete
steipete deleted the fix/pr-review-artifact-identity branch July 28, 2026 03:55
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 28, 2026
scripts/pr review artifacts carried no PR identity, so a review authored for
another PR validated clean and could gate someone else's landing. Stamp both
review.json and review.md with the reviewed PR number and head, anchor
pr-meta.json to the guarded pr-meta.env, and re-stamp foreign artifacts on init
instead of silently adopting them. review-claim now works in the PR worktree so
no subcommand writes review state to the shared canonical checkout.
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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