CI: silent merge check#33145
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33145. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsNo conflicts as of last run. |
| previous-releases: | ||
| name: 'Previous releases, depends DEBUG' | ||
| if: contains(github.event.label.name, 'PeriodicMergeCICheck') |
There was a problem hiding this comment.
Seems fine, but currently a vector of task names is accepted, see --task in https://github.com/maflcko/DrahtBot/blob/2038d4d541b89bf2601614b5656d7d30d73e17be/rerun_ci/src/main.rs#L7-L23
It would be good to allow the same somehow?
There was a problem hiding this comment.
Can you elaborate a little more on what this would look like? Would this be different labels for different jobs? As in a label that runs the Previous Releases job and a different label that would run a different job?
There was a problem hiding this comment.
I don't know. Not sure if we want to see pull requests spammed with "added and removed" label events (testing-cirrus-runners#19 (comment)).
GitHub doesn't make this easy and I wonder if we may want to just spin our own CI to detect silent merge conflicts.
There was a problem hiding this comment.
To give some more context: We are now trying to add 200+ lines of code to this repo which have to be maintained, but they cause label spam, and likely aren't sufficient to achieve the goal, because the ci-failed notification will go to the one adding the label and triggering the workflow?
If so, we'd have to create a comment (or other notification) anyway. So if additional glue code is needed, we might as well handle all code externally.
There was a problem hiding this comment.
It's a fair comment. I'll see what the ci-failed notification could look like but you could be right that this approach is less than ideal. @0xB10C has suggested perhaps merging this into the main CI file but might come with a verbose predicate before each job.
There was a problem hiding this comment.
Yeah, merging this with the main CI file is certainly better, if possible. However, it still leaves the issue of label spam. Also, it needs to be confirmed to be working correctly (to send the failed-notification to the right person)
|
Nice work on this! The label-based trigger for PeriodicMergeCICheck is a clean approach. One thought though since this is driven by label events, do we need to consider cases where multiple labels are applied at once? Would the condition still behave as expected? Also agree with the suggestion from @maflcko having a vector of task names could as well improve flexibility |
|
Other stuff to check would be that this works at all and doesn't just re-run an ancient commit, like #32989 (comment) |
Just ran a test to specifically test for this by updating the default (master) branch and adding and removing the label and it correctly picked an updated merge commit based on the PR merged into the updated master. |
There was a problem hiding this comment.
Have you considered doing something like the following in .github/workflows/ci.yml to avoid having to maintain separate files?
name: CI
on:
push:
pull_request:
types: [opened, reopened, synchronize, labeled]
jobs:
conditional-job:
if: >
github.event_name == 'push' ||
(
github.event_name == 'pull_request' &&
(
github.event.action == 'opened' ||
github.event.action == 'reopened' ||
github.event.action == 'synchronize' ||
(
github.event.action == 'labeled' &&
contains(github.event.label.name, 'PeriodicMergeCICheck')
)
)
)
runs-on: ubuntu-latest
steps:
- run: echo "Running CI job"
Could be a good shout, seems a bit of a verbose check if that has to be included in each job. I'll have a think about it. This is exactly the type of feedback that's good to consider. |
|
concept ack, but I don't have the slightest idea if this is even possible (or how) with GHA |
|
Currently working on an alternative approach of one job that loops through PRs, might close this PR in favour of the other one based on feedback. |
|
Any updates here? Just asking, because it is a bit tedious to manually search for all silent merge conflicts. Example ref: #29136 (comment) |
|
Concept ACK |
|
I think what could work (hacky, untested):
|
|
@m3dwards are you still working on something here? My understanding is that this is still an issue. |
|
I haven't been working on it but happy to pick this back up |
1b57472 to
358e4a6
Compare
|
I wanted to share my current direction and thinking on this and have pushed some example code and can show some test runs on my fork. I think it's a good point to get some feedback if we think this is a good general direction. In this design there is a new GHA job merged into the main repo that adds check runs to each PR on whether they have a silent merge conflict or not. The idea is that we have a job that pretty much runs 24/7 triggered every 6 hours or so and set to run for 5.5 hours, it could be set to run on a GHA runner rather than a Cirrus runner. Obviously running on a Cirrus runner (or even multiple runners) would dramatically speed up how many PRs can be checked for silent merge conflicts. The job uses the Github checks API to add a passing or failing test run to each PR directly. The silent merge check job itself should always pass, it writes pass or fail checks to the PRs. It will look through all open PRs and discard anything that has a git merge failure or a failing test with the thinking that there is no point checking something that can't be merged anyway. Then it will select PRs that have not had a silent merge check and one by one pull the merge branch of the PR and the full CI job "Previous releases" on that branch. When all PRs have been checked it will then re-check a PR that was checked the longest time ago. Things that can be tweaked:
Some back of the envelope maths with the "Previous Releases" job taking 10/15 minutes with a primed cache on a Cirrus runner and 300 open mergeable PRs (probably overestimate) the job would be checking each PR roughly every 4 days. Please see a run of the job on my fork here: https://github.com/m3dwards/bitcoin/actions/runs/22670080789 This is what a failing check would look like in the PR:
@willcl-ark @maflcko interested in your opinion on this design and if it's worth pursuing further and polishing up. |
358e4a6 to
996bd18
Compare
996bd18 to
ef3ea76
Compare
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 0 * * 0" # Sunday 00:00 UTC |
There was a problem hiding this comment.
should this not be - cron: "0 */6 * * *"?
There was a problem hiding this comment.
Most likely, definitely the intention was to run every 6 hours for 5.5 hours.
There was a problem hiding this comment.
Actually, an odd minute may be better to avoid the peak time around minute 0:
- cron: "37 */6 * * *"
There was a problem hiding this comment.
| repo_root = Path(__file__).resolve().parent.parent | ||
| os.chdir(repo_root) | ||
| start_time = time.monotonic() | ||
| max_runtime_seconds = int(timedelta(hours=5, minutes=30).total_seconds()) |
There was a problem hiding this comment.
nit: I think this could even be 3 hours (with a timeout and cron of 6 hours), to get a pull re-run every week, which should be enough?
|
are you still working on this? |
yep, was waiting until the new CI provider was picked and merged but I guess there isn't any dependency there. |
|
Yeah, this |
|
More concerned with the cache actions changing but can deal with that if and when it happens. |
d1ac08f to
0165078
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
willcl-ark
left a comment
There was a problem hiding this comment.
I feel like I've forgotten context here (sorry), but why can this job not just do something like:
- check out bitcoin/bitcoin:master
- fetch PR head
- attempt the merge locally
- run a fixed build command, something like:
rm -Rf build
cmake -B build --parallel
cmake --build build
# optionally
ctest --test-dir build- publish the result?
this could probably be done on a bare runner host too, negating need for docker et al. I think it would probably be faster as well...
| needs: [runners] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| checks: write |
There was a problem hiding this comment.
I think running the entire job with this permission would let a PR do some annoying things on GH as they have an authenticated write token to play with in run_all.sh?
Probably should just have this token in a seperate step or job where it's needed
There was a problem hiding this comment.
I'll have a think about this as you are right, the PR authors code will have access to the checks write token.
| from datetime import datetime, timedelta | ||
| from pathlib import Path | ||
|
|
||
| MAX_RUNTIME = timedelta() |
There was a problem hiding this comment.
Is this intentional? surely we'd want here
timedelta(hours=5, minutes=30)
or read from an env var (from the main workflow)
There was a problem hiding this comment.
Yup, refactor / copy paste error.
Yeah, if that is less code, that works, too. For reference, except for |
I'm open to changing it to this but this is more code than it currently is which is simply calling |
|
I'm not really understanding the advantages of this over |
|
The benefit would be that it doesn't require docker, so I think the three But either way is fine. It should be trivial to adjust later, if needed. |
This was fixed in #35348 |
0165078 to
393dc8a
Compare
|
Pushed latest changes to show direction. Running a bunch of tests on my fork. Will switch this PR to ready to review when the local testing is complete. It's just a bit time consuming as you have to do multiple full CI runs on a bunch of fake PRs. |
Adds a periodic CI workflow that runs every 6 hours to detect silent merge failures across all open PRs. For each PR, it fetches the pre-built merge commit (pull/<n>/merge), runs a build and the tests, and posts the result as a check run against the PR's head SHA. PRs that have never been checked are prioritised (oldest first),followed by those with the oldest existing check result.
393dc8a to
532b083
Compare
maflcko
left a comment
There was a problem hiding this comment.
This is still in Draft. What is the status here?
| print(f"PR #{pr['number']} has merge conflicts against current master, skipping.") | ||
| continue | ||
|
|
||
| ci_result = run([".github/ci-test-each-commit-exec.py"], check=False, |
There was a problem hiding this comment.
Just checked my rerun_ci.sh script, and realized I was also running --task 'lint'. lint should be fast, so it could also be run here?
There was a problem hiding this comment.
Do you have a link to that script? To run lint as it is in ci.yml would require pulling docker in right and all the docker caches etc etc.
There was a problem hiding this comment.
Well the script is https://github.com/maflcko/DrahtBot/blob/2038d4d541b89bf2601614b5656d7d30d73e17be/rerun_ci/src/main.rs#L15
I think you can just call ci/lint.py, because docker is already installed and docker has a built-in cache that works out of the box without having to pull anything?
There was a problem hiding this comment.
I've run experiments today adding lint and it dramatically slowed down how long per PR it takes to process. Right now it's shockingly fast at about 5-7 minutes per PR with a warm ccache. Adding lint took this to 35 minutes per PR. I did expect the first one to be slower but expected the second PR checked to be faster as the image would already have been built?
I think I'm of the mind to just leave lint out as I wouldn't expect a silent merge issue to be often caught by the lint checker and it just slows things down and adds more complexity.
That said, if you are keen to have it, I can keep working to try and figure out why it's so slow and if we can do better caching etc.
Just for reference here is a 2 PR run that was done with lint (1 hour 16 minutes): https://github.com/m3dwards/bitcoin/actions/runs/27784000378
And one done without lint (23 minutes): https://github.com/m3dwards/bitcoin/actions/runs/27787578648
I think pretty much ready for review. I'm still running some tests in the background and I can add the lint job you mentioned. |

In this design there is a new GHA job merged into the main repo that adds check runs to each PR on whether they have a silent merge conflict or not.
The idea is that we have a job that pretty much runs 24/7 triggered every 6 hours or so and set to run for 5.5 hours, it could be set to run on a GHA runner rather than a Cirrus runner. Obviously running on a Cirrus runner (or even multiple runners) would dramatically speed up how many PRs can be checked for silent merge conflicts.
The job uses the Github checks API to add a passing or failing test run to each PR directly. The silent merge check job itself should always pass, it writes pass or fail checks to the PRs.
It will look through all open PRs and discard anything that has a git merge failure or a failing test with the thinking that there is no point checking something that can't be merged anyway. Then it will select PRs that have not had a silent merge check and one by one pull the merge branch of the PR and the full CI job "Previous releases" on that branch.
When all PRs have been checked it will then re-check a PR that was checked the longest time ago.