Fail closed when delayed contributor observations target a stale PR head
Description
The independent-human-approval adapter can associate a live contributor snapshot with the wrong PR head when a pull_request_target event is processed after the branch has advanced.
In recordObservation(), fetchCurrentContributors() returns contributors for the PR's current live head. The resulting observation is labeled with the event-provided expectedHeadSha, but the adapter does not verify that the fetched snapshot.headSha matches that event head before posting the ledger comment.
This was identified while reviewing the draft implementation in #6233 for #6222.
Security impact
A delayed synchronize run can record contributors from a newer head as though they belonged to an older event head. A human who contributed only to the transient older head can therefore be omitted from the append-only contributor set after a force-push removes that commit. That person could later be treated as an independent reviewer even though they contributed code to the PR.
Reproduction sequence
- A
synchronizeevent is emitted for PR headA. - Before the event's contributor-recording job fetches the PR, the branch is force-pushed to head
B. - The job retains
expectedHeadSha=A, whilefetchCurrentContributors()returns the contributor snapshot forB. recordObservation()posts a ledger entry labeled with headAbut populated with contributors from headB.- A contributor present only on head
Ais missing from the append-only contributor ledger and can incorrectly remain eligible to approve.
Relevant code: tools/independent-approval/github.mts, in recordObservation().
Expected behavior
Contributor evidence must never be attributed to a head other than the one from which it was collected. When the live snapshot head and event-provided expected head differ, recording must fail closed before posting a ledger observation.
Acceptance criteria
- [ ]
recordObservation()comparessnapshot.headShawithexpectedHeadShabefore constructing or posting an observation. - [ ] A mismatch fails closed and does not post a contributor-ledger comment.
- [ ] The event's human push actor remains separate event evidence; contributors fetched from the live head are not relabeled as contributors to the stale event head.
- [ ] A later reconciliation can record the current live head without weakening the append-only contributor invariant.
- [ ] Add a named adapter test where the fetched snapshot is for head
B, the expected event head isA, and no comment POST occurs. - [ ] Preserve coverage for stable-head recording, shared-head PRs, head changes during evaluation, edited ledger evidence, and delayed event handling.
Related work
- Parent policy issue: #6222
- Draft implementation where the issue was identified: #6233
Checklist
- [x] The failure was investigated against the current draft implementation.
- [x] Existing issues were searched and no duplicate was found.
Closing as no longer applicable after the scope reduction in PR #6233. The affected contributor-ledger adapter existed only in the early draft commit f7510b6. Commit cc4f0d41 then removed the entire adapter, ledger, reconciliation workflows, policy configuration, and tests following the maintainer scope decision; neither current PR #6233 nor main contains recordObservation(), fetchCurrentContributors(), or an equivalent event-recording path. Reintroducing that machinery solely to add this guard would restore the broader architecture that was deliberately removed. If an event-backed contributor ledger is proposed again, it must preserve this issue's invariant: never attribute a live contributor snapshot to a different expected head, and account for contributors unique to a superseded head rather than merely dropping the mismatched event.