Repository navigation
Conversation
PushBuildStatusToGithub posts the tree status to every open PR, and records
in Firestore what it posted so that later runs only post to PRs whose status
has to change. The records were written in one batch at the end of the run.
A run that failed before that had posted to GitHub but recorded nothing. Once
the tree went back to its previous status, the stale records matched it
again, and the PRs kept the wrong status ("Tree is currently broken" on a
green tree) until the tree next changed or the PR got a new commit.
That has happened when a run was cut short, and when GitHub listed a PR
twice, which made Firestore reject the batch write for having the same
document in it twice.
PRs are now handled in batches of 20. For each batch:
1. The records are read from Firestore.
2. The records of the PRs that need a new status are set to "unknown".
3. The status is posted to those PRs.
4. The status is recorded for the PRs that GitHub accepted it for.
A run that fails partway leaves records that say "unknown", which matches no
tree status, so the next run posts to those PRs again. At worst that repeats
one batch of statuses that GitHub already had.
A failed Firestore write no longer fails the run. It is logged per PR, also
when Firestore reports it in the response rather than as an error, which was
ignored before. A PR whose record could not be set to "unknown" is skipped
until the next run, and one whose new status could not be recorded is posted
to again.
The list of open PRs is de-duplicated. GitHub lists a PR twice when another
PR is opened while the list is fetched, a page at a time.
Also:
- The records of a batch are read by name in one request, instead of with
one query per PR. They have been named <head sha>_<PR number> since they
were first written (flutter#3540). queryLastBuildStatus has no other callers and
is removed.
- GithubBuildStatus.documentIdFor returned the head SHA alone, which is not
how the records are named. It was only used to name records in tests, and
now returns the real name.
- PRs are posted to in descending order of PR number, so that the newest
get a new status first.
A change of tree status now takes up to two Firestore writes per batch of
PRs that need it, instead of one per run. A run in which nothing changes
makes one read per batch and no writes.
There was a problem hiding this comment.
Code Review
This pull request refactors the PushBuildStatusToGithub handler to process pull request status updates in batches, prioritizing newer PRs and introducing a two-phase update mechanism (marking status as unknown in Firestore before posting to GitHub) to prevent out-of-sync states during failures. It also replaces individual Firestore queries with batch operations. The review feedback suggests wrapping the execution of each batch in a try-catch block to prevent a failure in one batch from halting the processing of subsequent batches.
| for (final batch in prList.slices(batchSize)) { | ||
| await _updateBatch(github, slug, realStatus, batch, firestoreService); | ||
| } |
There was a problem hiding this comment.
To make the background sync process more resilient, we should wrap the execution of each batch in a try-catch block. This ensures that if a transient error or unhandled exception occurs while processing one batch, it does not prevent other batches of pull requests from being updated.
for (final batch in prList.slices(batchSize)) {
try {
await _updateBatch(github, slug, realStatus, batch, firestoreService);
} catch (e, s) {
log.error('Failed to update batch of PRs: ${batch.map((pr) => pr.number).join(', ')}', e, s);
}
}
PushBuildStatusToGithub posts the tree status to every open PR, and records in Firestore what it posted so that later runs only post to PRs whose status has to change. The records were written in one batch at the end of the run. A run that failed before that had posted to GitHub but recorded nothing. Once the tree went back to its previous status, the stale records matched it again, and the PRs kept the wrong status ("Tree is currently broken" on a green tree) until the tree next changed or the PR got a new commit.
That has happened when a run was cut short, and when GitHub listed a PR twice, which made Firestore reject the batch write for having the same document in it twice.
PRs are now handled in batches of 20. For each batch:
A run that fails partway leaves records that say "unknown", which matches no tree status, so the next run posts to those PRs again. At worst that repeats one batch of statuses that GitHub already had.
A failed Firestore write no longer fails the run. It is logged per PR, also when Firestore reports it in the response rather than as an error, which was ignored before. A PR whose record could not be set to "unknown" is skipped until the next run, and one whose new status could not be recorded is posted to again.
The list of open PRs is de-duplicated. GitHub lists a PR twice when another PR is opened while the list is fetched, a page at a time.
Also:
A change of tree status now takes up to two Firestore writes per batch of PRs that need it, instead of one per run. A run in which nothing changes makes one read per batch and no writes.
Fixes flutter/flutter#197968
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.