Repository navigation
Keep an approval when the pushes after it only merge the base branch - #17037
codeconsole wants to merge 25 commits into
Conversation
GitHub moves an approval to the new head after a merge of the base branch that leaves the diff of the pull request as it was, but not after one that had conflicts, since resolving them changes that diff. The workflow then dismissed the approval, although the pull request got no change to review. The workflow now repeats each merge between the approved commit and the head with git merge-tree, in a bare repository holding only the trees of the merge's parents and of their merge base. The approval is kept when every commit on the way has two parents, the second one a commit of the base branch, and differs from git's own merge only in the conflicted files. A merge that changes another file by hand, or that merges another branch, dismisses the approval as before.
A fetch or a merge that hangs would end the job at its timeout, and with it the dismissals of every pull request listed after that one, on each run. Each git command now gets two minutes, after which the approval is dismissed like any other the workflow cannot verify.
jdaugherty
left a comment
There was a problem hiding this comment.
Thanks for this. Update merges with conflicts do dismiss approvals that had nothing new to review, and the approach of repeating the merge without checking anything out is sound: a failed request, a commit with one parent or more than two, a second parent that is not on the base branch, a timeout and too many merges all end in a dismissal.
One problem needs to be solved before this goes in, see the comment on the comparison of the changed files: a conflicted file is accepted with any content, which lets a change nobody reviewed keep an approval. The other two comments are small.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A push of only base merges still dismisses the approval once there are more than twenty of them.
A merge of the base branch kept an approval when the files it changed by hand were among the conflicted ones, whatever it changed in them, so a merge could add an unreviewed line anywhere in a conflicted file. The merged file git writes holds each conflict between markers labelled with the two parents; the pushed file now has to keep every line outside them, and its mode, as git wrote them. A conflict without markers, of a binary file or of a file deleted on one side, dismisses the approval when it was resolved by hand. A kept approval and the files whose conflicts were resolved now go to the step summary, and the pull request gets one comment per merge naming them, found again by a hidden marker so that the hourly run does not repeat it. The walk over the merges states why it gave up: more than 20 commits, or a request or git command that failed or ran out of the two minutes the walk now has as a whole, is dismissed as not checked rather than as a change of the pull request. Its answer is reused within a run for every approval given to the same commit.
AGENTS.md said that the workflow compares no diff and then described a rule that repeats merges and compares them. The update-merge rule now comes first, and "compares no diff" is said of any other push. Both guides describe the narrower rule: only the lines inside the conflicts may change, and the pull request is told which files were resolved.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A push of only base merges still dismisses the approval once there are more than twenty of them.
Every fetch of a merge adds a pack to merges.git, and after about fifty of them, across all the pull requests of one run, git starts gc --auto in the background. It holds the lock of the shallow commits, so the next fetch fails and the approval it was checking is dismissed as one whose commits could not be checked. A synthetic run over 61 merges hit it.
The walk stopped after 20 commits and dismissed the approval, although running out of commits to check is no sign of a change. It now goes back to the approved commit, bounded by time only: two minutes for one approval, as before, and seven for all the checks of a run, so that one pull request with a long run of merges, or several slow ones, cannot end the job at its ten-minute timeout before the dismissals after them.
Every merge after the head was fetched as the first parent of the merge before it, so its parents are in its commit object. Reading them there saves one of the three requests a merge cost, which matters now that the number of merges is bounded by time only.
jdaugherty
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround. The three points from my earlier review are addressed. I replayed the check at 65f9987 against #16877, #16726, #16871 and #16912 and got the results in the description, and ran resolved_within_conflicts against a scratch repository: an edit between two conflicts, an append at the end of the file, a deleted line next to a conflict, a mode change, a change of line endings and a dropped final newline all dismiss, while a resolution inside the conflict keeps the approval, also one that repeats the lines around it.
Two comments are left. The first is a small bug in the reason given for a dismissal, the second is not blocking.
| # The commit was fetched as the first parent of the merge before it, so its parents are read from it. | ||
| read -r first second other < <(bounded env GIT_NO_LAZY_FETCH=1 git -C merges.git cat-file commit "$commit" | sed -n '/^$/q; s/^parent //p' | tr '\n' ' ') | ||
| else | ||
| read -r first second other < <(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') |
There was a problem hiding this comment.
A failed request here is reported as a change of the pull request. The read takes its input from a process substitution, so the exit status of gh api is lost, and gh api --jq prints the error body on a failed request. For a 422 I get first=[{"message":"No], second=[commit] and the rest of the message in other, so the next line sets "the pull request changed after this approval" and the approval is dismissed with that message, not with "could not be checked". A rate limit or a server error with a JSON body does the same.
The two requests below check their exit status and are fine. Could this one do the same, for example by reading the output into a variable with || return 1 first and splitting it after?
Line 97 has the same mislabel in a smaller window: the step runs without pipefail, so when the deadline passes before git cat-file, awk reads nothing, regions is empty, and the answer is 1, a change, where it should be 2.
There was a problem hiding this comment.
Right on both, thanks for tracing them. Fixed in 58b1f38. The parents are now read into a variable with || return 1 before they are split, both for the head and for the later merges read with cat-file. The cat-file | awk pipeline runs with pipefail in its own subshell, so a timeout or a git failure there answers 2. Line 94 had the same problem: the mode of the pushed file came from a substitution inside the test, so its status was dropped and a timeout there also read as a change. It now fails like line 92. In the scratch repository, a 422 with a JSON body for the head's parents, and a cat-file or ls-tree that runs out of time, all dismiss with "the commits after this approval could not be checked". The earlier cases and the historical merges keep their verdicts.
| local base=$1 approved=$2 commit=$3 deadline=$(( SECONDS + 120 )) fork= first second other behind merged tree conflicts changed path | ||
| (( deadline <= checks_end )) || deadline=$checks_end | ||
| accepted= | ||
| reason="the commits after this approval could not be checked" |
There was a problem hiding this comment.
Not blocking, and fine as a follow-up. GitHub never moves an approval kept by this rule, so it has to be proved again on every hourly run, and anything that keeps one of those runs from finishing dismisses it: one failed request, or the seven minutes of the run being used up by the pull requests before it in the list. An approval that was kept for days can then be lost in an hour in which nothing was pushed, and the cost of one pull request with a long run of merges falls on the others. At today's numbers the seven minutes are far away (a merge took about 7 seconds when I replayed #16877 and #16726 from here).
The comment this workflow already writes could carry the answer: a hidden marker with the approved commit and the head it was kept for, read from the bot's comments like the merge markers. A later run that finds the marker for the same pair has nothing to walk, which ends both the hourly cost and the chance of losing the approval to a failed request.
There was a problem hiding this comment.
The problem holds. The part I could fix without stored state is in b467a46: a failed request of the check is asked once more after five seconds, within the check's deadline, so one passing API error no longer dismisses an approval that was kept for days. In the scratch repository, a 502 once for the head's parents or for a compare keeps the approval; a request that keeps failing still dismisses it as "could not be checked".
I haven't added the marker, because a marker in the bot's comments would decide whether an approval is kept, and a pull request can write those comments. vulnerability-scan.yml runs a labelled same-repo pull request's build, and its own postStickyComment.sh, with pull-requests: write, and a same-repo branch can add a workflow that comments as the bot. Today a forged kept-resolution marker only hides a notice; a forged "kept for A..H" marker would keep an approval over code nobody reviewed. The answer also depends on the base branch, so the key would need that too.
Saving the answer needs a place a pull request can't write to. The simplest is the cache of a default-branch run, but that means using actions/cache, and #17019 promised the workflow uses no action. Since that promise is yours, would you rather keep it, or have the answer cached? The shared seven minutes go away with it.
Three places lost the exit status of the command they read, so a failure there dismissed the approval as a change of the pull request instead of as commits that could not be checked: - The parents of a merge were read from a process substitution. gh prints the body of a failed request, and a 422 split into words looked like a commit with more than two parents. They are now read into a variable, with the status checked, before they are split. - The mode of the pushed file came from a substitution inside a test, so a git command that failed or ran out of time read as another mode. - The step runs without pipefail, so when cat-file failed or ran out of time awk read nothing and the file looked like one without conflicts. That pipeline, and the one reading the parents of a later merge, now set pipefail in their own subshell.
GitHub never moves an approval kept across update merges, so every hourly run checks it again, and one passing error of the API in any of those runs dismissed it although nothing was pushed. A failed request is now asked once more after five seconds, as long as the check has that time left. Only the answer of the request that succeeds is used, never the error body gh prints for the failed one.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. Twenty-one merges of the base no longer dismiss the approval. A line added just before a conflict marker still keeps it.
| /^@@ / { | ||
| split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; inside = 0 | ||
| for (i = 1; i < n; i += 2) | ||
| if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] - 1 <= at && at <= r[i + 1])) inside = 1 |
There was a problem hiding this comment.
A later push commits a file that still has its conflict markers, and adds a line immediately before the opening marker. This treats that line as part of the conflict and keeps the approval. A line outside the conflict is a change. Dismiss the approval.
There was a problem hiding this comment.
Right. For a line that was only inserted, the check also accepted the spot just before the opening marker and just after the closing one, so a file pushed with its markers still in place and a line added just outside them kept the approval. Fixed in c2b3345: an inserted line now has to land between the markers of a conflict. In the scratch repository your case, and the same with a line just after the closing marker, now dismiss; a line added between the markers still keeps the approval. Resolutions that remove the markers aren't affected, since git reports them as a change of the conflict's own lines. That holds even when they repeat the lines around the conflict, which I checked with four such resolutions. The earlier cases, the failure cases and the 13 historical merges keep their verdicts. One limit stays by design: once the markers are gone, a line written where a marker was is part of the resolution and can't be told apart from it. That is why the pull request gets a comment naming the files whose conflicts were resolved.
A hunk that only inserts lines passed when it sat next to a conflict, just before the opening marker or just after the closing one. A merge pushed with git's conflict markers still in place, and a line added just outside them, therefore kept the approval, although that line is outside the conflict. An inserted line now has to land between the markers. A resolution that removes the markers is not affected: git reports it as a change of the conflict's own lines, also when it repeats the lines around the conflict, so those hunks already had to lie within the markers.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A line added just before a conflict marker still keeps the old approval.
| BEGIN { n = split(regions, r, " ") } | ||
| /^@@ / { | ||
| split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; inside = 0 | ||
| for (i = 1; i < n; i += 2) |
There was a problem hiding this comment.
A later push adds a line immediately before the opening conflict marker, then keeps one side of the conflict. This treats the added line as part of the conflict and keeps the approval. A line outside the conflict is a change. Dismiss the approval.
There was a problem hiding this comment.
You're right, and my last reply called it a limit when it isn't one. Fixed in 9b4d48c: every line a merge writes inside a conflict now has to be a line of one of the conflict's two sides. Which lines it keeps, and in which order, is still up to the resolution. Your case, a line added before the opening marker and then one side kept, now dismisses. So do the same line after the side that is kept, a resolution written by hand, and a copy of a line from around the conflict. Keeping one side, both sides, or both in another order still keeps the approval. This rule costs something real: a line written by hand in a resolution is now a change like any other. Of the seven historical merges that kept their approval, four are now dismissed: #16877 and #16453 renumber a heading of the upgrade guide, #16726 merges a sentence of CONTRIBUTING.md by hand, and #16495 merges Java code by hand. #16958, #16838 and #16552 are still kept. CONTRIBUTING.md now says so.
A resolution could write any line between the markers of a conflict, so a line added just before the opening marker, followed by one side of the conflict, kept the approval: once the markers are gone, that line is part of the resolution and git cannot tell it from one. Every line a merge writes inside a conflict now has to be a line of one of its two sides; which lines it keeps, and in which order, is still up to the resolution. A line written by hand inside a conflict now dismisses the approval like any other change. Of the seven historical merges kept before, the ones of apache#16453, apache#16495, apache#16726 and apache#16877 are now dismissed: they renumber a heading of the upgrade guide, or merge a line of prose or code by hand.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An extra line that matches one side of a conflict still keeps the old approval.
| FNR == NR { merged[FNR] = $0; next } | ||
| /^@@ / { | ||
| split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; conflict = 0 | ||
| for (i = 1; i < n; i += 2) |
There was a problem hiding this comment.
A later push adds a second increment immediately before the opening conflict marker, then keeps the original increment. The file increments twice. This treats the extra line as part of the conflict and keeps the approval. A line outside the conflict is a change. Dismiss the approval.
There was a problem hiding this comment.
Right again, and it showed that checking each line against the sides can't be enough: a line of a side can be repeated, as in your case, or dropped, reordered, or combined with lines of the other side. Fixed in 0b57e0b: each conflict now has to be resolved as a whole, the way git offers to. That means the pull request's side, the base branch's side, or both one after the other, in either order. Your case, the increment made twice, now dismisses. So do part of a side dropped, a side's lines reordered, and a line of a side added between markers that were kept. One side, the other, or both still keep the approval, also when two conflicts in one file are resolved differently. The rule costs more now. Of the seven historical merges that kept their approval before last round, only #16958 and #16552 still do. #16838 is now dismissed as well, since it kept the method signature of one side and the body of the other. A resolution git couldn't have made by itself needs a new review.
Checking each line of a resolution against the lines of the two sides still let a resolution change the code: a line of a side could be repeated, so an increment added before the conflict and the side's own increment made the file increment twice, and lines could be dropped, reordered or combined from both sides. Each conflict is now resolved as a whole, as git offers to: the pull request's side, the base branch's side, or both one after the other, in either order. A conflict left as git wrote it, markers and all, is no change either. Of the historical merges, apache#16838 is now dismissed too: it kept the method signature of one side and the body of the other. apache#16958 and apache#16552 keep their approvals.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A merge with more than one common ancestor can keep an approval for a change outside the conflict.
| [[ -n "$second" && -z "$other" ]] || { reason="the pull request changed after this approval"; return 1; } | ||
| behind=$(requested "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by') || return 1 | ||
| [[ "$behind" == 0 ]] || { reason="the pull request changed after this approval"; return 1; } | ||
| fork=$(requested "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 |
There was a problem hiding this comment.
The two sides have more than one common ancestor. An extra edit outside the conflict is accepted, and a resolution that keeps one whole side is rejected. Use the same base a normal merge would, and dismiss the approval for the extra edit.
There was a problem hiding this comment.
Right, and it reproduced. With the PR and the base branch having merged each other, so that the next merge has two merge bases, and one of them made the merge from a single base differ from git's, an extra edit outside the conflict kept the approval, and a resolution that keeps one whole side dismissed it. Fixed in 2324403: the head and the base branch are now fetched with their history, commits only, without trees or file contents, and git merge-tree runs without --merge-base, so git finds the merge bases itself and builds the same base git merge would. That history also answers whether the second parent is on the base branch, and gives the parents of each merge, so the walk no longer asks the API for anything. In the scratch repository both of your cases now come out right: the extra edit dismisses, the whole side keeps the approval. The other synthetic and failure cases and the 13 historical merges keep their verdicts. The history of a release branch is about 70,000 commits and 25 MB, fetched in two seconds.
The check took one merge base of each merge from the compare API and merged from it alone. When the two sides have more than one, as after the pull request and the base branch merged each other, git builds the base from all of them, and the merge from one of them can differ from git's: an edit outside the conflict then matched the merge and kept the approval, and a resolution that keeps one whole side differed from it and dismissed it. The head of the pull request and the base branch are now fetched with their history, commits only, without trees or file contents, which git fetches when a merge needs them. git merges each merge's parents as a merge of its own would, finding the merge bases itself, and answers from the history whether the second parent is on the base branch and what the parents of each merge are. The walk asks the API for nothing any more; a failed fetch is tried once more after a pause, as a failed request was. The history of a release branch is about 70,000 commits, 25 MB, fetched in two seconds.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A merge with more than one common ancestor can still keep an approval for a change outside the conflict.
| $pull.baseRef.target.oid // "-"] | @tsv' > stale.tsv | ||
| while IFS=$'\t' read -r number head review login commit tree base; do | ||
| reason="the pull request changed after this approval" accepted= | ||
| if [[ "$tree" == same ]]; then |
There was a problem hiding this comment.
The two sides have more than one common ancestor. One side also changes a file outside the conflict, and the recorded merge undoes that change. The approval is kept. Dismiss it for a change outside the conflict.
There was a problem hiding this comment.
Right: line 277 kept the approval before any merge was checked, because the head had the very tree of the approved commit, and the merge that recorded that tree undid the base branch's change outside the conflict. The same happened with a rebase onto the newer base that keeps the old files. Fixed in 4b8b0fa: an approval with the same files is now kept only when the approved commit and the head have the same merge bases with the base branch, as after a reworded commit or a rebase onto the same commit. Otherwise it goes through the check of the merges, which dismisses the undoing merge. In the scratch repository your case, the same with two merge bases, and the rebase now dismiss; a reworded commit with the same files is still kept. The other cases and the 13 historical merges keep their verdicts.
…e branch An approval whose commit has the very tree of the head was kept before the merges after it were checked at all. When the head has taken in commits of the base branch that the approved commit had not, through a merge that records the approved files or a rebase that keeps them, those same files undo what the base branch changed, outside any conflict, and the approval was kept over that change. Such an approval is now kept only when the approved commit and the head have the same merge bases with the base branch, as after a reworded commit or a rebase onto the same commit; otherwise it goes through the check of the merges like any other, which dismisses the undoing merge.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A resolution that keeps one whole side is dismissed when that side has a line of equal signs.
| conflict = ""; ours = ""; theirs = ""; separators = 0 | ||
| for (j = r[i]; j <= r[i + 1]; j++) conflict = conflict merged[j] "\n" | ||
| for (j = r[i] + 1; j < r[i + 1]; j++) | ||
| if (merged[j] ~ /^=======\r?$/) separators++ |
There was a problem hiding this comment.
One side replaces a heading with a heading and a line of equal signs, which is how a heading is underlined. The recorded merge keeps that whole side and changes nothing else. The approval is dismissed, because that line is counted as a conflict separator. Keep the approval.
There was a problem hiding this comment.
Right: a line of seven equal signs in a side was counted as the separator between the sides, so a resolution that keeps the whole side was dismissed. Fixed in b25aaa2: for each merge, the conflict markers are made one character longer than the longest run of <, = or > that starts a line of either side, so no line of a side can be taken for a marker. Two later commits keep that fix sound. 37ece6a reads the sides from the stages git merged, so the rename of a file is covered too. It gives the longer markers to that merge alone, through core.attributesFile, and builds them inside awk, so a very long run of equal signs still works. cecabc7, f93d205 and cba3fba add the rest of a review of the step and a test of it, dismiss-stale-reviews-test.yml. That test has your case, with the pull request's side and with the base branch's, runs of nine and seven, a 200,000-character run, a renamed file, and a side kept only in part, which still dismisses.
git's conflict markers are seven characters, and a side can hold a line just like one: seven equal signs underline a heading in Markdown and AsciiDoc. The check took such a line for the separator between the two sides, found two separators, and dismissed an approval whose resolution kept a whole side. For each merge, the markers are now one character longer than the longest run of <, = or > that starts a line of either side of a conflicted file, set through the conflict-marker-size attribute for the merge alone, so that no line of a side can be taken for a marker. A resolution that keeps only part of a side is still dismissed.
The longest marker-like line was looked for only in the sides git could confirm had the file, and a git command that failed or ran out of time was taken for a side without it. The markers could then be too short for what that side holds, and the check went on as if it had been done. The side's entry is now read with ls-tree, whose failure answers as a failure; only a side whose tree has no such file is skipped.
The check of a conflicted file depended on several things that could give a wrong answer: - It took the files and sides of a conflict from the names git prints, which are quoted for unusual characters, and from the parents' trees, which miss the side of a renamed file. It now reads merge-tree -z, which gives the raw names and, for each conflicted file, the two sides git merged (stages 2 and 3); the marker-like lines are looked for in those, and diff -z gives the changed files. - The longer markers were given in the repository's info/attributes and reset afterwards, unchecked, and passed to awk as strings that a very long run of equal signs could make too long to start awk at all. They are now given to the one merge that needs them, through core.attributesFile, and built inside awk from their size. - Where the resolution of each conflict lay was worked out from the hunks of a diff, so it depended on how git lined the two files up. The pushed file is now matched from its first line against the lines outside the conflicts and, for each conflict, the pull request's side, the base branch's side or both in either order, keeping every way the match can go. - Lines were compared without their final newline, so dropping it, or adding one a side did not have, kept the approval. The file now has to end with a newline exactly when the side that ends it does. - A conflict left with its markers was accepted, but only when the markers were labelled with the parents' ids as merge-tree writes them, never as git merge does; markers left in a file are no resolution, so such a file is now dismissed, also when the merge left it unchanged. - The parsers ran outside the time limit; they now run within it, and a timeout or an error of theirs answers "could not be checked".
- Every fetch named raw commits and kept no ref, so the next one could not tell the server what was already here and got the whole history again, 25 MB for each pull request of a release branch. Fetched commits are now kept under refs/fetched/, and a fetch gets only the new history. - When the history of a same-files approval could not be fetched or read, that was taken for another place on the base branch, and the check of the merges then called the reworded head a change; merge-base's status was also lost in a pipe. Such an approval is now dismissed as one whose commits could not be checked. - A dismissal acted on what the run read at its start, minutes before. The review and the head are now read again first, and an approval that moved while it was checked is left to the next run. - The comments on the pull requests were written between the dismissals, with a minute each, outside every time limit, and could keep the job from reaching the later ones. They are now written after the dismissals, and every request after the checks has until a minute before the job's timeout. - Two runs at once could both find a merge without a comment and both write one. Each merge now gets a comment of its own, and a run that finds another comment for the same merge deletes all but the oldest. - The step summary split each resolved file at its first space, so a name with a space was cut short. It now splits off the merge only. - A merge that needed longer markers and failed left their attributes file behind; it is now removed then too.
dismiss-stale-reviews.yml runs only from the default branch, on events a pull request cannot start, so nothing tested its checks before a change of them was merged. dismiss-stale-reviews-test.yml runs a test on every change of the workflow or of the test: it takes the step's script from the workflow file as it is and runs it against small repositories it builds, with a stand-in for gh that answers from files. The test covers the resolutions that keep an approval and those that do not, the end of the file, lines like conflict markers, unusual file names, a renamed file, long runs of merges, ordinary commits and merges of other branches, fetches and git commands that fail or run out of time, merges with two merge bases, heads with the very files of the approved commit, and, through the whole step, dismissals, a review that moves while it is checked, and the comments two runs write at once. Run against the step as it was before the fixes of this round, 11 of its 54 checks fail.
merge-tree answers 1 for conflicts, and so does a redirection of its output that fails, which runs no merge at all. The file an earlier merge wrote would then be read as this merge's. It is now removed before each merge, so that such a failure leaves nothing to read and answers as a check that could not finish.
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A change outside the conflict keeps the approval when the changed line looks like a number.
| # Whether the pushed lines from p on are the merged lines from a to b. | ||
| function same(p, a, b, j) { | ||
| if (p - 1 + (b - a + 1) > lines) return 0 | ||
| for (j = a; j <= b; j++) if (resolved[p + j - a] != merged[j]) return 0 |
There was a problem hiding this comment.
A file outside the conflict changes from 42 to 042. The approval is kept, because those lines are compared as numbers and come out equal. Compare them as text, and dismiss the approval.
There was a problem hiding this comment.
Right: the lines were compared with awk's !=, and awk takes two lines read from files that look like numbers for numbers, so 42 and 042 compared equal, as did 1e2 and 100 or 4.20 and 4.2. Fixed in d7ce071: the lines are compared as strings, and the step runs with LC_ALL=C, so every awk compares bytes whatever the runner has. The test, dismiss-stale-reviews-test.yml, has your case, the same inside a conflict's side, and the other number forms; all of them dismiss now, and keeping the side as it is still keeps the approval. I ran it with mawk and with gawk; both had the bug before the fix.
awk takes two lines read from files that look like numbers for numbers, and compares their values, so a line changed from 42 to 042, from 1e2 to 100 or from 4.20 to 4.2, outside a conflict or in a side, kept the approval. The lines are now compared as strings, and the step runs with LC_ALL=C, so that every awk compares and counts bytes whatever the runner has, mawk or gawk, and in whatever locale.
- The merge was repeated without the repository's attributes, which a bare repository without a HEAD does not read, so a file marked merge=binary was merged by its lines. It is now repeated with the attributes of the pull request's side, as in its checkout, and the marker size, also git's own seven, is given in the repository's own attributes, which no attribute of a commit overrides. - A conflict git writes without markers (a binary file, a file deleted on one side, a submodule) is now kept only when the pushed entry is one side's exactly, mode and content, or absent where that side has none, and the file is named in the summary and the comment like any other. The marker-like lines are looked for only in regular files, so a submodule's commit is no longer read as a blob. - A merge git reports as conflicted without naming a file, as for a directory split in two, was taken for a clean one; it now answers that the commits could not be checked. - The changed files were looked up with grep, which splits a name with a newline in two; they are now kept in an associative array. - When one side of a conflict at the end of the file had no lines, both sides one after the other took the newline at the end from it. It is now taken from the side that ends the file. A failed read of the last byte answers as a failure, not as "no newline". - The checks of all approvals now come first, each approval with one deadline for its checks, then the dismissals, then the comments, and the GraphQL query is bounded. Before a dismissal the review, the head and the base branch are read again; an approval whose commit GraphQL did not know was never matched by that check and was left on every run. A comment is written only while the head and base branch are still the ones checked. - The marker of a comment is now its last line, so that the name of a file in a comment cannot pass for one. Every run that comments on a pull request takes away all comments of a merge but its oldest, also when it writes none. Names are written as Markdown code whatever backticks and spaces they hold, and split from their merge at the first space only.
dismiss-stale-reviews-test.yml now calls ci-policy.yml as its first job and runs the test only when the policy says the tests run, like every other test of the repository. The test gets a case for each fix of the second review: one per spelling of a number, an empty side of a conflict at the end of the file, a file marked merge=binary, a marker size set by the pull request's attributes, a directory split in two, a submodule kept with one side and with another commit, a failed read of the last byte, names with a backtick, spaces at both ends and text like a marker, an approval whose commit GraphQL does not know, a comment left over by a stopped run, and a retargeted pull request. A step that fails now fails the test, and the second run is checked to have read the review again.
🔎 No tests executed 🔎🏷️ Commit: 6d23a24 Learn more about TestLens at testlens.app/docs. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A resolution that keeps one whole side is still dismissed when that side has no final newline.
| # numbers and compares their values. | ||
| function same(p, a, b, j) { | ||
| if (p - 1 + (b - a + 1) > lines) return 0 | ||
| for (j = a; j <= b; j++) if ((resolved[p + j - a] "") != (merged[j] "")) return 0 |
There was a problem hiding this comment.
A file ends in a conflict. One side has no final newline. The recorded merge keeps that side byte for byte. The approval is dismissed, because a newline is added before the sides are compared. Keep the approval.
Follow-up to #17019.
Why
dismiss-stale-reviews.ymlrelies on GitHub moving an approval to the new head when a push leaves the diff of the pull request as it was. GitHub does that for a clean merge of the base branch, but not for one that had conflicts: resolving them changes the diff. Such an update merge would dismiss the approval, although the pull request got no change to review, only the base branch's.This is common here. Among the pull requests updated recently, 12 approvals on 9 pull requests (#16453, #16495, #16552, #16726, #16838, #16871, #16877, #16912, #16958) were left at an earlier commit by pushes that contained nothing but merges of the base branch. Every one of those merges had conflicts, typically in
dependencies.gradleor in the numbered sections of the upgrade guide. The approvals kept by this pull request are those whose conflicts were resolved by keeping whole sides, as on #16552 and #16958; the other merges wrote resolutions of their own, which still need a new review.What changes
An approval that GitHub has not moved is now also kept when only update merges separate it from the head. Every commit after the approved one has to
So a resolution git could have made by itself is accepted, and nothing else is. Any other resolution is a change like any other: a renumbered heading, lines picked from both sides, a line repeated, dropped, reordered or written by hand. Once the markers are gone, a resolution like that can't be told from a change next to the conflict. A merge that resolves a conflict that way, that leaves conflict markers in a file, that changes any other line, that leaves a conflict git writes without markers (a binary file, a file deleted on one side, a submodule) as anything but one side's exactly, mode and content, that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it as before. So does a check that cannot finish, because a fetch still fails when tried a second time, a git command fails, the check runs out of time, or git reports a conflict without naming a file, as it can for a directory split in two. Such a dismissal says the commits could not be checked, not that the pull request changed.
The approvals #17019 keeps because their commit has the very tree of the head are now kept only when the approved commit and the head also have the same merge bases with the base branch, as after a reworded commit or a rebase onto the same commit. When the head has taken in newer commits of the base branch, by a merge that records the approved files or a rebase that keeps them, the same files undo what those commits changed, so such an approval goes through the check of the merges like any other.
Nobody has reviewed the resolution, so a kept approval goes to the step summary with the files whose conflicts were resolved, and the pull request gets one comment per merge naming them.
The checks of all approvals come first, each approval with one deadline for them, then the dismissals, then the comments. Before dismissing an approval, the workflow reads the review, the head and the base branch of the pull request again, and before commenting the head and the base branch; a pull request that moved while it was checked is left to the next run.
How
The workflow fetches the head of the pull request and the base branch into a bare repository with their history, but only the commits, without trees or file contents (
--filter=tree:0); git fetches the trees and files a merge needs when it merges. The history of a release branch is about 70,000 commits, 25 MB, fetched in two seconds, and each fetched commit is kept under a ref, so that the next pull request's fetch gets only the history that is new. From that history git reads the parents of each merge and whether the second one is on the base branch, and repeats the merge withgit merge-tree --write-tree, which prints the merged tree and the conflicted files. git finds the merge bases itself, as a merge of its own would, so a merge whose sides have more than one common ancestor is repeated from the same basegit mergewould build from all of them. The merge is repeated with the attributes of the pull request's side (--attr-source), as in its checkout, so that a file markedmerge=binaryis not merged by its lines; no merge driver is configured, so none runs.merge-tree -zgives the names of the conflicted files as they are, unquoted, and the two sides git merged for each (stages 2 and 3, mode and object). The marker size is given in the repository's own attributes, which no attribute of a commit overrides; when a regular file of a side has a line that starts with seven or more<,=or>, the merge is repeated with markers one character longer than the longest such run, so that a line like seven equal signs under a heading is never taken for a marker; the first and last markers are also matched with their labels, the full ids of the two parents. The pushed file is then matched from its first line against the lines of git's merge outside the conflicts and, for each conflict, the pull request's side, the base branch's side, or both in either order, so the answer does not depend on how a diff would line the files up. Lines are compared as text, with their line ends, so that a line like 42 and one like 042 differ, and the file has to end with a newline exactly when the side that ends it does.The number of merges is not limited, only the time: each approval's check gets two minutes, and all the checks of a run together get seven, so the job always reaches the dismissals after them. Within a run the answer is reused for every approval given to the same commit. The last line of the comment on the pull request is a hidden marker with the merge, read only from this workflow's bot and only as a last line, so that a file name cannot pass for one, and the hourly run does not repeat it; two runs at once, or a run stopped after writing, can leave two, so every run that comments on a pull request takes away the comments of a merge but its oldest. Names are written as Markdown code whatever backticks and spaces they hold. The comments are written after the dismissals, and every request after the checks has until a minute before the job's timeout, so they cannot take the time the dismissals need. Auto-gc is off in the bare repository, since a background gc after many fetches would hold the lock the next fetch needs.
Nothing of the pull request is checked out or run:
git merge-treeworks on objects and runs no hook and no filter. The token keepscontents: readandpull-requests: write.An approval kept this way stays at its commit, so the hourly run checks it again: no request of the API, one fetch of what is new in the history, and about five seconds a merge when measured from a workstation.
Testing
The check was run against earlier pushes of this repository:
dismiss-stale-reviews-test.ymlruns.github/scripts/test-dismiss-stale-reviews.shon a change of the workflow or of the test, under the CI policy like every test, so on a pull request into 7.0.x only with therun cilabel. The script takes the step's script from the workflow file and runs it against small repositories it builds, with a stand-in forghthat answers from files, in 81 checks, passing with both mawk and gawk:merge=binarykept as one side, with a submodule kept at one side's commit, with a marker size the pull request's attributes set, with a side holding a line like a conflict marker (a heading underlined with seven equal signs, runs of nine and seven, a line of 200,000 equal signs, a line starting with<<<<<<<), with a renamed file, with a file whose name has a space or a non-ASCII letter, over 26 merges in a row, over a merge with two merge bases, and for a reworded commit with the same files.42,+42,1e2,4.20,0x10and1.0to its value, one at a time), a newline added after a side that has none, the lines of both sides of a file markedmerge=binary, a submodule at a third commit, conflict markers left in the file, a newline dropped or added at the end, line ends changed, an ordinary commit followed by merges, a merge of another branch, an edit that only a merge from one of two merge bases would make, and a merge or a rebase whose head has the very files of the approved commit.merge-base,merge-tree(also the one with longer markers),cat-file,ls-treeorawkthat runs out of time, a read of the last byte of a file that fails, and a directory split in two, a conflict git names no file for. A fetch that fails once is tried again and keeps the approval.Against the step as it was at 0594dd1, before the two reviews of the step, 25 of the 81 checks fail.
The step's script was also run as it is in the workflow file, in dry-run mode, against this repository. Earlier it kept the approval on #16958 and would have dismissed 19 others, each followed by ordinary commits. On the last run no open pull request had an approval at another commit than its head, so there was nothing to judge.
As with #17019, the workflow itself only runs from the default branch, so it could not be run from this pull request.
AGENTS.mdandCONTRIBUTING.mddescribe the rule; the latter says that a resolution keeps the approval only when it keeps one side, the other, or both, and that any other resolution, like any other change, dismisses it.