Repository navigation
fix(pr): bind review artifacts to the PR being landed - #114897
Conversation
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.
|
Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 11:49 PM ET / July 28, 2026, 03:49 UTC. ClawSweeper reviewWhat this changesThis 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 readinessThe 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 Priority: P2 Review scores
Verification
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceTests +196, Other +124. Total +320 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat 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
HistoryReview history (1 earlier review cycle)
|
Owner decision on the fail-closed artifact lifecycleClawSweeper's 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 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 On the protected One honest irony worth recordingThis PR lands through the very gate it hardens, running the old, unstamped code path. Its own review artifacts were produced by |
|
Merged via squash.
|
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.
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-artifactshad no way to tell whose review it was validating.review_guardcompares the checked-out HEAD againstPR_HEAD_SHAread from.local/pr-meta.env— but both live in the same.localdirectory, so a wholesale foreign artifact set is internally self-consistent and passes every check.validateReviewArtifactsread.local/pr-meta.jsononly 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. Neitherreview.jsonnorreview.mdnamed a PR at all.Proof, using two real artifact sets produced by the real flow on one machine — the
READY FOR /prepare-prverdict written while reviewing #114388, placed in the landing directory of #114897, whosepr-meta.jsoncame from an actualscripts/pr review-init 114897: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:
git show f3055f64f4a^:scripts/pr-lib/worktree.shshows the pre-fix(pr): keep landing mutations inside the dedicated PR worktree #114723enter_worktreealready didcd .worktrees/pr-$prandmkdir -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_claimwas the one subcommand running in the shared canonical checkout (cd "$root"; mkdir -p .local), writingreview-claim-*.logthere. That is why the canonical root carries a script-owned-looking.local— on this machine it holds those logs beside a strayreview.json/review.mdfor 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.
review.jsongainspr: { number, headSha };review.mdis 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..local/pr-meta.json, andvalidate_review_artifact_datanow tiespr-meta.jsonitself topr-meta.env, whichreview_guardbinds to the CLI argument and the checked-out head: CLI arg →pr-meta.env→ HEAD, andpr-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. Bothprepare-initandmerge-runrun this path.mktemp -ddirectory 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_claimmoves into the PR worktree, so noscripts/prsubcommand writes review state to the shared canonical checkout. Claiming still works on a cold PR becauseenter_worktreeprovisions 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, deliberatelyscripts/pr gc [--dry-run]already exists, takes per-PR operation locks, and reclaims worktrees plus branches for MERGED/CLOSED PRs;merge_runalready reclaims on success.scripts/pr lson the canonical checkout shows the residue is exactly gc-eligible: 104923 CLOSED, 112542/112958/113076 MERGED, 114388 legitimately OPEN, plus an unparseablepr-wrapper-112442. So this is operator hygiene, not missing tooling.Auto-running
gcfromenter_worktreewould be actively wrong:gcwalks other PRs and takes their operation locks, so one landing would contend with concurrent landings — the exact hazard this PR exists to remove. Post-#114723enter_worktreealready 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-initnow requires.local/pr-meta.json(already written byreview-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.jsonfromscripts/pr review-initand the real review artifacts authored for a different PR:The cross-PR rejection transcript is in What Problem This Solves above (
exit=0before,exit=1after, 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-114897produced 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 whosepr-meta.jsondisagrees 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_guardrejects mismatchedpr-meta.env.node scripts/check-changed.mjs— exit=0 (typecheck test root + scripts lint, Testboxtbx_01kykby60ma05tce43mzhkanvy).537fa698569— run 30325983523.oxfmton touched JS/TS;git diff --checkclean.gpt-5.6-sol, xhigh) three rounds. Round 1 accepted two findings: markdown not identity-bound, and a one-second-resolution archive namemvcould overwrite. Round 2 accepted one:pr-meta.jsonwas itself unanchored. All fixed. Round 3's only finding claimedreview_claimbreaks on a cold PR — rejected as factually incorrect, sinceenter_worktreeprovisions 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.