Skip to content

Batch mergeability checks on base branch pushes#744

Open
kyokuping wants to merge 2 commits into
rust-lang:mainfrom
kyokuping:issue/707
Open

Batch mergeability checks on base branch pushes#744
kyokuping wants to merge 2 commits into
rust-lang:mainfrom
kyokuping:issue/707

Conversation

@kyokuping

Copy link
Copy Markdown

Closes #707

@kyokuping kyokuping marked this pull request as ready for review April 23, 2026 14:56

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really sorry that it took me so long to take a look at this, I didn't have much time for reviews in the past 2-3 months.

The implementation looks great! I tested it on a live repository and it seems to work as expected, it would be cool to get rid of the thousands useless GH API requests to reload the mergeability of all open PRs.

I left some comments regarding the implementation. I haven't looked at the failing tests yet.

View changes since this review


let mut after = None;
loop {
let (fetched_prs, cursor) = repo_state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually abstract paging within the client calls that deal with the GH API, so let's:

  • Rename get_pull_requests_batch to get_pull_requests_by_base_branch
  • Handle paging inside get_pull_requests_by_base_branch

The most performant way would be to overlap loading the PR pages from GitHub and then querying our database, but I'd leave that for a separate PR, as this change is already complicated enough :)

PullRequestStatus::Open | PullRequestStatus::Draft => {
tracing::info!("Mergeability status unknown, scheduling retry.");
mq_tx.enqueue_retry(mq_item);
return Ok(());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we hit a single PR that is in the unknown state, we would stop the whole check, but that is unnecessary. Let's store the PRs that were unknown in a Vec, and then after we go through the whole batch, decide whether we then retry the whole batch (if there are, say, more than 20 such PRs) or if we enqueue the individual PRs one-by-one (to avoid downloading 1000 PRs again if only a few of them are left with unknown mergeability).

.get_pull_request(repo_state.repository(), pr.number)
.await?
{
update_pr_with_known_mergeability(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please wrap this in a span that mentions the PR number? Because currently in the log we only have this:

TRACE Mergeability check{item=Batch(PullRequestBatchToCheck { repo: kobzol/bors-kindergarten2, base_branch: "main", attempt: 2, conflict_source: ... })}

So it's not really possible to see from the log which PR is getting updated.

tracing::warn!("Cannot find DB pull request for {fetched_pr:?}");
}
}) => {
if *attempt >= BATCH_MAX_RETRIES {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add logging at the start and end of the batch check? And record the time it took. So that we can easily see in logs how fast it is.

) -> anyhow::Result<()> {
let affected_prs = db
.set_stale_mergeability_status_by_base_branch(repo_state.repository(), &payload.branch)
db.set_stale_mergeability_status_by_base_branch(repo_state.repository(), &payload.branch)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's re-add the previous functionality, where we check the affected_prs, and only schedule the batch check if at least one PR was affected.

Comment thread src/github/mod.rs
}

#[derive(Debug)]
pub struct PullRequestSummary {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct PullRequestSummary {
/// Basic information about a PR needed to handle mergeability checks and label changes.
pub struct PullRequestInfo {

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.

Use GraphQL to load mergeability status from GitHub

2 participants