ci: let compiled-product reuse hit on pull requests

Merged
TE
2mo ago
+127-1

Compiled-product reuse could never hit on a pull request. load_consumer() required the checked-out revision to equal the workflow run's head_sha, but the macOS compile admission job checks out with no ref:, so actions/checkout takes github.sha โ€” on a pull_request event the ephemeral merge of the head into the base, never the head itself. Every pull request run reported REUSE_MISS_REASONS: consumer_revision_mismatch before any producer was considered. macOS compile admission ran 402 times in the 24h ending 2026-09-22T16:10Z at a 20.73 min median, roughly 5,500 macOS runner minutes a day that reuse exists to avoid. Fixes #13709.

A pull request consumer now also passes when its checkout is a two-parent merge whose second parent is the run's attested head_sha. That is what makes the local tree the tested form of that head rather than an unrelated revision. push, merge_group and workflow_dispatch consumers keep requiring the attested revision exactly, and every consumer still has to match the product-input fingerprint recomputed from GitHub's copy of head_sha, so a checkout carrying different compiled-product inputs cannot adopt that head's products.

The parent comes from git cat-file commit, not git rev-parse HEAD^2. The job checks out at the default fetch depth of one, and a shallow repository grafts its boundary commit as parentless: in a depth-1 clone of a merge commit, git rev-parse HEAD^2 fails and git rev-list --parents -n 1 HEAD prints no parents, while the commit object still names both. A fix written against HEAD^2 would have changed nothing in CI. Reading GitHub's API for the merge commit's parents instead is not an option either โ€” the ephemeral merge object is not durably resolvable there (git/commits/a78b75b3 for the run cited in #13709 returns 404 today).

This is downstream of #13676 and #13681, which fixed the producer lookup; the miss reason only moved to consumer_revision_mismatch once a producer was found at all.

Validation

tests/test_reuse_app_host_products.py builds a real git repository and shallow-clones it the way actions/checkout does, so the merge-commit shape and the shallow graft are both real rather than mocked. Per the repo's regression convention the test lands in its own commit first: against unmodified main it fails with the diagnosed reason, and passes with the fix.

$ RUNNER_TEMP=/tmp/rt python3 tests/test_reuse_app_host_products.py   # test only, before fix
FAIL: test_pull_request_merge_checkout_is_bound_to_the_attested_head
AssertionError: False is not true
Compiled-product reuse miss: consumer_revision_mismatch.
Ran 52 tests in 0.646s
FAILED (failures=1)

$ RUNNER_TEMP=/tmp/rt python3 tests/test_reuse_app_host_products.py   # with fix
Ran 52 tests in 0.609s
OK

$ RUNNER_TEMP=/tmp/rt python3 tests/test_ci_change_areas.py
PASS: CI change area filter

Both exit 0 with the fix. test_checkout_outside_the_attested_head_stays_a_miss covers the trust property and passes before and after: a merge that does not have the attested head as a parent, a merge with the attested head in the first-parent position, and a non-merge checkout that is not the attested commit all stay consumer_revision_mismatch. test_merge_group_checkout_still_requires_an_exact_revision holds merge queue runs to exact match. An unreadable commit object is a bounded consumer_provenance_unavailable miss, verified directly against load_consumer. test_ci_linux_guard_routing.py, test_ci_guard_workflow_structure.py, test_app_host_test_products.py, test_ci_product_publication.py and test_ci_reusable_workflow_permissions.py also pass.

Remaining gap: a two-parent merge commit naming head_sha is weaker than sha equality, because the merge commit's own sha is not itself GitHub-attested โ€” the product-input fingerprint check against head_sha is what bounds the tree. Local evidence is unverified: these are Linux runs of the Python guards, and the end-to-end effect is a reuse hit on macOS CI, which only this PR's own macOS compile admission run can show.

๐Ÿค– Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes compiled-product reuse never hitting on pull requests. load_consumer() required the checked-out revision to equal the run's head_sha, but a pull_request run checks out the ephemeral merge of the head into the base, so every PR reported consumer_revision_mismatch โ€” roughly 5,500 macOS runner minutes a day that reuse exists to avoid.

A pull request consumer now also passes when its checkout is a two-parent merge whose second parent is the attested head_sha. push, merge_group, and workflow_dispatch consumers still require the exact revision, and every consumer must still match the product-input fingerprint recomputed from GitHub's copy of head_sha. Parents are read with git cat-file commit rather than git rev-parse HEAD^2, because the job's depth-1 shallow clone grafts boundary commits as parentless, which would silently break a HEAD^2-based fix. The regression test builds a real shallow clone the way actions/checkout does; negative tests keep non-merge checkouts, a merge with the head in the first-parent position, and merge queue runs as misses. Fixes #13709.