Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/routed-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,28 @@ jobs:
# and may equal the group's base otherwise. Admission is per PR: the
# queued commit must be one squash commit of that PR directly on the
# group's base, so the workflow itself refuses a batch (fail closed)
# even if the ruleset group size is misconfigured.
# even if the ruleset group size is misconfigured. Its tree must be
# that head merged onto the base (checked below).
[[ "$GROUP_HEAD_REF" =~ /pr-([0-9]+)-([0-9a-f]{40})$ ]] || { echo "::error::merge group ref names no queued PR: $GROUP_HEAD_REF"; exit 1; }
pr="${BASH_REMATCH[1]}" ref_sha="${BASH_REMATCH[2]}"
current="$(gh api "repos/${REPOSITORY}/pulls/${pr}")"
head="$(jq -r '.head.sha' <<<"$current")"
{ [ "$ref_sha" = "$head" ] || [ "$ref_sha" = "$GROUP_BASE_SHA" ]; } || { echo "::error::queue ref sha $ref_sha is neither the live head $head of PR #${pr} (pushed after enqueue) nor the group base $GROUP_BASE_SHA"; exit 1; }
commit="$(gh api "repos/${REPOSITORY}/commits/${GROUP_HEAD_SHA}")"
if [ "$ref_sha" != "$head" ]; then
# The ref names the base, so it cannot prove the queued squash is of
# the live head. GitHub itself dequeues a PR whose head changes; this
# is defense in depth: a head committed no earlier than the queued
# squash is refused (a backdated push is not detected).
queued_at="$(jq -r '.commit.committer.date' <<<"$commit")"
pushed_at="$(gh api "repos/${REPOSITORY}/commits/${head}" --jq '.commit.committer.date')"
[[ "$pushed_at" < "$queued_at" ]] || { echo "::error::PR #${pr} head $head (committed $pushed_at) is newer than the queued commit (committed $queued_at)"; exit 1; }
fi
parents="$(jq -r '.parents | length' <<<"$commit")"
subject="$(jq -r '.commit.message | split("\n")[0]' <<<"$commit")"
parent="$(jq -r '.parents[0].sha // empty' <<<"$commit")"
# A group's base is the parent of its first commit, so a one-entry
# group has base == the queued commit's parent; a batch does not.
{ [ "$parents" = "1" ] && [ "$parent" = "$GROUP_BASE_SHA" ] && [[ "$subject" == *"(#${pr})" ]]; } || { echo "::error::queued commit is not a single squash commit of PR #${pr} ($parents parents, parent $parent, base $GROUP_BASE_SHA: $subject); candidate admission requires exactly one queued PR per group"; exit 1; }
# The ref sha and commit dates do not bind the live head to the queued
# commit, so bind by content: the queued tree must be exactly the live
# head merged onto the group base. The head comes from the PR's own
# ref and must still be the head read above; no match, merge conflict
# or missing history refuses (fail closed).
{ [ "$(git rev-parse --is-shallow-repository)" = false ] || git fetch --no-tags --unshallow origin; } || { echo "::error::cannot complete history to bind the queued commit to PR #${pr}"; exit 1; }
fetched="$(git fetch --no-tags origin "refs/pull/${pr}/head" && git rev-parse FETCH_HEAD)" && [ "$fetched" = "$head" ] || { echo "::error::refs/pull/${pr}/head (${fetched:-unfetched}) is not the live head $head of PR #${pr}"; exit 1; }
merged="$(git merge-tree --write-tree "$GROUP_BASE_SHA" "$head")" && [ "${merged%%$'\n'*}" = "$(git rev-parse "${GROUP_HEAD_SHA}^{tree}")" ] || { echo "::error::queued commit ${GROUP_HEAD_SHA} is not PR #${pr} head $head merged onto base $GROUP_BASE_SHA"; exit 1; }
queue=$(gh api graphql -f query='query($number:Int!){repository(owner:"EffortlessMetrics",name:"ripr-swarm"){pullRequest(number:$number){headRefOid mergeQueueEntry{id}}}}' -F number="$pr")
queue_entry=$(jq -er --arg head "$head" 'select(.errors == null) | .data.repository.pullRequest | select(.headRefOid == $head) | .mergeQueueEntry.id | select(type == "string" and length > 0)' <<<"$queue")
labels="$(jq -r '[.labels[].name] | join(",")' <<<"$current")"
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/4836-queued-commit-tree-binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- section: Internal / CI -->
- Routed admission binds a merge-queue commit to the live PR head by tree (head merged onto the group base) instead of a commit-date comparison, refusing a different head, extra content, a merge conflict or a moved PR ref (#4836).
16 changes: 11 additions & 5 deletions docs/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ number comes from the merge-group branch name
(`gh-readonly-queue/<base>/pr-<n>-<sha>`) and the PR's labels are forwarded to
the gate (`full-ci` still selects the advisory reports, `ripr-waive` still
reaches the PR-evidence step). The resolver accepts a head-suffixed ref or a
base-suffixed fallback; the latter does not authoritatively identify the queued
H. Admission is per PR, so the queue must use a group size of 1; the queued commit must be a single
base-suffixed fallback; neither ref spelling identifies the queued H, so the
queued commit's tree must also equal the live head merged onto the group base
(`git merge-tree --write-tree <base> <head>`, with the head fetched from the
PR's own `refs/pull/<n>/head` and required to match the head read from the API).
A different head, extra content, a merge conflict, a moved PR ref or missing
history refuses. Admission is per PR, so the queue must use a group size of 1; the queued commit must be a single
squash commit of the queued PR sitting directly on the group's `base_sha`, or
admission refuses it, so a batch fails closed even if the ruleset is misconfigured. Batching needs per-PR admission (#8082) and is a follow-up. The
`merge-ready` label request below still works until the label request is
Expand All @@ -72,9 +76,11 @@ review decision, and every page of review threads. Missing or malformed
evidence refuses the result; a Result-only retry cannot reuse admission from
an older attempt. Main/manual authorities and child-result checks remain.

This is a late eligibility check, not queue-cutover acceptance. The current
base-suffixed queue-ref fallback still uses a timestamp and does not establish
the reviewed/admitted H or its composed G tree. Candidate-local admission code
This is a late eligibility check, not queue-cutover acceptance. The tree match
binds the queued commit to the head GitHub reports live at admission; it does not
establish that this is the head a reviewer judged ready, and its premise (GitHub's
squash tree equals `merge-tree(base, head)`) is checked here only on past
squash merges and by local fixtures, not on a native queue entry. Candidate-local admission code
also remains a trusted-source prerequisite. Neither these API freshness reads
nor a tree match authenticates an arbitrary caller workflow or makes the final
read and protected merge atomic. Preserve the installed gates until the
Expand Down
2 changes: 2 additions & 0 deletions policy/process_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ xtask/tests/hard_cut_admission_selftest.rs|Command::new|5|hard-cut-admission-sel
xtask/tests/hard_cut_admission_selftest.rs|use std::process::Command|1|hard-cut-admission-selftest|#5391: imports Command only for the bounded self-test invocation described above.
xtask/tests/routed_dispatch_result.rs|Command::new|2|routed-dispatch-result|#5394: executes the checked-in Result and admission shells locally with fixture environments; no GitHub dispatch, credential or network operation.
xtask/tests/routed_dispatch_result.rs|use std::process::Command|1|routed-dispatch-result|#5394: imports Command only for the bounded workflow shell controls described above.
xtask/tests/routed_queue_resolution.rs|Command::new|2|routed-queue-resolution|#4836: builds throwaway local Git repositories (hermetic config, file:// remote) and executes the checked-in Resolve queued PR shell against a stubbed read-only gh in a temp dir; no GitHub dispatch, credential or network operation.
xtask/tests/routed_queue_resolution.rs|use std::process::Command|1|routed-queue-resolution|#4836: imports Command only for the bounded Git and workflow shell controls described above.
xtask/tests/windows_shard_summary.rs|Command::new|1|windows-shard-summary|#9272: runs the checked-in Summarize failures step through bash against a colored fixture log; no network, credential or GitHub operation.
xtask/tests/windows_shard_summary.rs|use std::process::Command|1|windows-shard-summary|#9272: imports Command only for the bounded summary-step control above.
crates/ripr/tests/call_budget_repo_exposure.rs|Command::new|1|call-budget-repo-exposure|#8600: runs the built ripr binary over a temp workspace with a distinct-callee test line to read the repo-exposure seam record; no network or credential operation.
Expand Down
8 changes: 4 additions & 4 deletions tools/repo-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,12 +1331,12 @@ pub fn routed_rust_ready_event_contract_violations(workflow: &str) -> Vec<String
"[ \"$ref_sha\" = \"$head\" ] || [ \"$ref_sha\" = \"$GROUP_BASE_SHA\" ]",
),
(
"check the live head is not newer than the queued commit",
"[ \"$ref_sha\" != \"$head\" ]",
"require the PR ref to still name the live head before binding the queued commit",
"[ \"$fetched\" = \"$head\" ]",
),
(
"refuse a live head not older than the queued commit",
"[[ \"$pushed_at\" < \"$queued_at\" ]] || { echo \"::error::PR #${pr} head",
"bind the queued commit's tree to the live head merged onto the group base",
"[ \"${merged%%$'\\n'*}\" = \"$(git rev-parse \"${GROUP_HEAD_SHA}^{tree}\")\" ]",
),
] {
if !workflow.contains(snippet) {
Expand Down
8 changes: 4 additions & 4 deletions tools/repo-policy/src/workflow_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,12 +1205,12 @@ fn routed_rust_ready_event_matrix_withholds_draft_and_label_context() {
"[ \"$ref_sha\" = \"$head\" ] || [ \"$ref_sha\" = \"$GROUP_BASE_SHA\" ]",
),
(
"check the live head is not newer",
"[ \"$ref_sha\" != \"$head\" ]",
"PR ref to still name the live head",
"[ \"$fetched\" = \"$head\" ]",
),
(
"not older than the queued commit",
"[[ \"$pushed_at\" < \"$queued_at\" ]] || { echo \"::error::PR #${pr} head",
"tree to the live head merged onto the group base",
"[ \"${merged%%$'\\n'*}\" = \"$(git rev-parse \"${GROUP_HEAD_SHA}^{tree}\")\" ]",
),
] {
let mutated = workflow.replace(snippet, "removed");
Expand Down
8 changes: 4 additions & 4 deletions xtask/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12086,12 +12086,12 @@ fn routed_rust_ready_event_matrix_withholds_draft_and_label_context() {
"[ \"$ref_sha\" = \"$head\" ] || [ \"$ref_sha\" = \"$GROUP_BASE_SHA\" ]",
),
(
"check the live head is not newer",
"[ \"$ref_sha\" != \"$head\" ]",
"PR ref to still name the live head",
"[ \"$fetched\" = \"$head\" ]",
),
(
"not older than the queued commit",
"[[ \"$pushed_at\" < \"$queued_at\" ]] || { echo \"::error::PR #${pr} head",
"tree to the live head merged onto the group base",
"[ \"${merged%%$'\\n'*}\" = \"$(git rev-parse \"${GROUP_HEAD_SHA}^{tree}\")\" ]",
),
] {
let mutated = workflow.replace(snippet, "removed");
Expand Down
Loading
Loading