Skip to content

bootstrap: handle fork shallow upstream detection#155717

Open
cypherair wants to merge 2 commits intorust-lang:mainfrom
cypherair:prep/upstream-ready-bootstrap-shallow-2026-04-24-u9836b06
Open

bootstrap: handle fork shallow upstream detection#155717
cypherair wants to merge 2 commits intorust-lang:mainfrom
cypherair:prep/upstream-ready-bootstrap-shallow-2026-04-24-u9836b06

Conversation

@cypherair
Copy link
Copy Markdown
Contributor

@cypherair cypherair commented Apr 24, 2026

Problem
Bootstrap's check_path_modifications selects an upstream commit and then checks whether selected paths changed since that commit to decide whether CI artifacts can be reused.

Before this change, the GitHub Actions path selected HEAD^1 as the upstream commit without checking what kind of commit it was.

That matches the expected rust-lang PR/try/auto CI shape, where HEAD is a generated merge commit and the first parent is the upstream side.

Fork push workflows can instead have shallow history for the triggering ref. In that shape, HEAD can be the branch tip and HEAD^1 can be an earlier commit from the same branch.

Using that branch commit as the base makes if-unchanged compare against the wrong commit.

What changed
The GitHub Actions path now only uses the merge-parent fast path after checking that HEAD is a merge commit and that HEAD^1 is authored by the configured upstream merge-bot account.

If that fast path is not valid, bootstrap falls back to the configured nightly branch ref, such as refs/remotes/origin/main, when that ref is present in the local checkout.

If no trusted upstream commit is available from those sources, bootstrap returns MissingUpstream instead of selecting an untrusted base.

Result
The rust-lang PR/try/auto CI shape continues to use the merge-parent fast path.

Fork push CI no longer treats an earlier contributor commit as the upstream base.

When the checkout contains the configured nightly branch ref, bootstrap can use that trusted ref for the comparison.

When the checkout does not contain a trusted upstream base, existing if-unchanged callers take the conservative path and avoid CI artifact downloads.

I used Codex to help draft the PR.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 24, 2026

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 24, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 24, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@cypherair
Copy link
Copy Markdown
Contributor Author

Thanks for the reminder.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

I do not think this PR needs a CONFIG_CHANGE_HISTORY entry. Although it touches src/bootstrap/src/core/config/tests.rs, that change is only adding coverage for the git freshness detection path used by bootstrap.

This PR does not add, remove, rename, or change defaults for any bootstrap configuration option, and it does not change bootstrap.toml semantics.

The functional change is limited to src/build_helper/src/git.rs: in GitHub Actions, keep trusting the HEAD^1 fast path only when HEAD is actually a merge commit and its first parent is an upstream merge-bot commit. For fork push workflows or shallow histories where that assumption is not valid, bootstrap falls back to the fetched nightly branch ref before using the normal upstream search path.

So the intent is to preserve the existing rust-lang/rust PR CI behavior while making fork/shallow CI detection more accurate.

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Apr 24, 2026

Noting that I'd like to take a look at this before it lands, though I don't have time at the moment.

Fork push workflows can run in GitHub Actions with only the triggering branch fetched. In that shape refs/remotes/origin/main may be absent, and a shallow feature branch may not contain any bors-authored upstream commit.

After the CI upstream detection stopped blindly trusting HEAD^1, that missing upstream case could fall through to searching HEAD and then panic when no upstream commit was found. Treat it as MissingUpstream instead, so download-rustc/download-ci-llvm if-unchanged conservatively disables CI downloads and builds locally.

Add a regression test for the shallow fork-push shape without an origin/main ref.
@jieyouxu
Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned clubby789 and unassigned jieyouxu Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants