Skip to content

fix(ci): bind pull_request_target safety runs to the PR head, not GITHUB_SHA - #2275

Merged
abrichr merged 1 commit into
mainfrom
claude/safety-review-prt-sha
Nov 19, 2026
Merged

abrichr merged 1 commit into
mainfrom
claude/safety-review-prt-sha

Conversation

@abrichr

@abrichr abrichr commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Problem

The "Evaluate protected-path evidence" job has failed on every pull_request_target run since the gate landed in #1992 on 2026-11-10 (none of the 192 runs since then succeeded). Every log sampled, from the first failure on 2026-11-11 to today, contains:

protected-safety-review: failure
- workflow run SHA does not match the triggering event SHA

_workflow_provenance_errors compares GITHUB_SHA with the head_sha that the Actions API records for the run. On pull_request_target these are different commits by design: GITHUB_SHA is a base-branch commit and the run's head_sha is the pull request head. Run 44456030871 (#2270) shows it: the API reports head_sha 6cbbf43c8, the PR head, which is not on main. The comparison holds for issue_comment and merge_group, which is why comment-triggered runs pass.

Fix

For pull_request_target the run is bound to the pull request head in the event payload. issue_comment and merge_group keep the GITHUB_SHA binding. A missing or malformed SHA on either side is now its own error, so the check cannot be skipped by an empty value. Nothing else in the gate changes: the manifest, the review rules and the exact-base check are untouched.

The old comparison was also wrong in the other direction. A pull_request_target run whose recorded head_sha equalled GITHUB_SHA (a commit other than the PR head) was accepted. The new test test_pull_request_target_run_for_another_commit_fails covers that case.

Evidence

Unit tests (tests/test_protected_safety_review.py, 291 pass). The fixture uses three distinct SHAs for the PR head, the PR base and the tip of main. Three of the new tests fail against the script on main.

  • a PR touching no protected path passes on pull_request_target
  • a PR touching a protected path with no review fails, and the failure is published on the PR head
  • a run recorded for any commit other than the PR head fails
  • an event with a missing or malformed head never passes
  • a comment-triggered run is still bound to GITHUB_SHA

Replay against live data. The script ran locally with the real run IDs and PR metadata through a wrapper that only allows GET, so no check run was published.

PR Run Script on main This branch
#2270, no protected path 44456030871 failure: workflow run SHA does not match the triggering event SHA success
#2275 (this PR), protected path, no review yet 44544908371 failure: SHA mismatch, and expected exactly one current exact-head independent review failure: expected exactly one current exact-head independent review
#2269, #2267, #2259, #2258, #2256 latest failed run on each head not run success on all five

Notes for the reviewer

  • This PR's own pull_request_target job fails with the old error. The workflow runs the script from the PR base, so the fix takes effect for a PR once its branch is updated from a main that includes it. Re-running an old job replays the old base and stays red.
  • This PR changes a path in the safety manifest, so it needs one current-head review from a vendor other than Claude. The review comment triggers the issue_comment path, which publishes the verdict.
  • protected-safety-review and this job are not in the required status checks for main.
  • Not changed here: _passed_pr_head_verdict checks that a verdict run's head_sha is an ancestor of main. For a verdict produced by pull_request_target that is the PR head, so the merge-group path will refuse such verdicts. It fails closed and the merge queue ruleset is disabled.

…HUB_SHA

The protected safety review compared GITHUB_SHA with the head_sha GitHub
records for the workflow run. On pull_request_target GITHUB_SHA is a
base-branch commit and the run's head_sha is the pull request head, so the
comparison could not hold and every pull_request_target run since #1992
failed with 'workflow run SHA does not match the triggering event SHA'.

For pull_request_target the run is now bound to the event's pull request
head. issue_comment and merge_group keep the GITHUB_SHA binding. A missing
or malformed SHA is an error.
@abrichr

abrichr commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 4bdd389

Verdict: APPROVE. The fix matches the observed failure. On pull_request_target, the run record's head_sha is the PR head, while GITHUB_SHA is a base-branch commit. Every pull_request_target run in the last 200 runs of this workflow failed or was cancelled (84 failed, 23 cancelled). Comment-triggered runs mostly succeeded (83 of 93). The new binding fixes that, and the gate still fails closed.

What I checked (exact head 4bdd389, rebased on main 108ee9b)

  • tests/test_protected_safety_review.py: 292 passed, and ruff check is clean on both changed files.
  • Unreviewed protected change: the new test confirms a pull_request_target run on a protected path still publishes failure on the PR head for lack of review, with no SHA-mismatch error hiding the real reason.
  • A head the event doesn't name: a run record whose head_sha is the base, main's tip or another commit is rejected with "workflow run SHA does not match the triggering event SHA". An event head that is missing, empty, 39 characters or uppercase never passes; it either raises before publishing or publishes failure. issue_comment is still bound to GITHUB_SHA, and workflow_sha is still validated separately.
  • The diff names no specific application and adds no special case for one.

P2: the published head can differ from the head that was evaluated (recommend a one-line guard). For pull_request_target, the check is published on the event's pull_request.head.sha. The evidence (files, review comments, _head_identity) comes from the live /pulls/{n} head. Nothing requires the two to match. I tested this with the PR's own fake: event head and run head both d*40, live PR head HEAD, unprotected files. The result was success with no errors, published on d*40. A stale run can therefore put a success on commit X that was computed from commit Y's files and reviews. Re-running an old run from the Actions UI is one way; a publish that slips in before cancel-in-progress lands is another. If the branch is later reset to X, that stale success counts until the new synchronize run publishes, which takes about 17 seconds. Suggested fix: inside the per-PR loop, when event_name == "pull_request_target" and head_sha != pr_head, append "event head is not the current PR head; rerun on current head". Before this PR the gap couldn't be reached, because every pull_request_target run failed the SHA check.

P3 (latent, no merge-group runs in recent history):

  • In _passed_pr_head_verdict, run_head_sha and workflow_sha are both the run's own head_sha, so that comparison always passes. For a pull_request_target verdict, that SHA is now the PR head. _trusted_workflow_source_errors then requires it to be an ancestor of main, which an unmerged PR head never is. A merge queue would accept only comment-triggered verdicts.
  • run_head_sha falls back to workflow_sha for every event other than pull_request_target. That is correct today, but if a new event type is added to the workflow, it will silently get GITHUB_SHA binding.

Limits and CI: I did not run this on live GitHub. The checks here are unit tests and fakes. This PR's own protected-safety-review / Evaluate protected-path evidence failed with the old SHA error and "expected exactly one current exact-head independent review". That is expected: pull_request_target runs the base's verifier, so this fix cannot pass its own PR-triggered run until it merges. The comment-triggered run on this review should evaluate it. The other 13 checks pass and 35 are skipped.

@abrichr
abrichr merged commit 9c675cb into main Nov 19, 2026
49 of 52 checks passed
@abrichr
abrichr deleted the claude/safety-review-prt-sha branch November 19, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant