Skip to content

feat: cancel in-progress reviewbot pushes before new ones are started - #3590

Merged
Archaeopteryx merged 1 commit into
mozilla:masterfrom
bhearsum:feat-cancel-in-progress-review
Sep 9, 2026
Merged

Archaeopteryx merged 1 commit into
mozilla:masterfrom
bhearsum:feat-cancel-in-progress-review

Conversation

@bhearsum

Copy link
Copy Markdown
Contributor

This was originally motivated by #3578, but it's valid and worthwhile on its own.

Aside from the very roundabout way we have to find task group ids, this is pretty straightforward: simply find and cancel all previous task groups for the revision. This avoids doing work for something that's already stale.

If someone knows of a way to find the task group id of the reviewbot push other than the roundabout way it's happening here, I'd be very happy to switch to it. I could not find any way to pull it (or even the treeherder link) through the API directly; the only thing that seems to available there is the task id of the initial code review task.

In addition to the unit tests, I managed to run code review bot locally as some sort of integration test. I didn't have it actually cancel any tasks, but I think I've done enough to make this landable. Ideally we can test in a non-prod environment before production.

@marco-c

marco-c commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

A downside of this is that the build on Phabricator would show up as pending, maybe there's some sort of "cancelled" result we could upload to Phab?

@marco-c

marco-c commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Regarding Ben's question, @La0 can you think of another way to retrieve the task group?

@bhearsum

Copy link
Copy Markdown
Contributor Author

A downside of this is that the build on Phabricator would show up as pending, maybe there's some sort of "cancelled" result we could upload to Phab?

It would, but only on the previous Build, which probably doesn't matter...?

In any case, I'll see if I can update the state in Phab, as it would be the Proper (tm) think to do.

@La0

La0 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Regarding Ben's question, @La0 can you think of another way to retrieve the task group?

Currently i think it's the only way.

But it would not be complicated to store the task group in the backend next to Diff.review_task_id

Then you could fetch that info through the revision_diffs_list endpoint

This was originally motivated by mozilla#3578, but it's valid and worthwhile on its own.

Aside from the very roundabout way we have to find task group ids, this is pretty straightforward: simply find and cancel all previous task groups for the revision. This avoids doing work for something that's already stale.

If someone knows of a way to find the task group id of the reviewbot push other than the roundabout way it's happening here, I'd be very happy to switch to it. I could not find any way to pull it (or even the treeherder link) through the API directly; the only thing that seems to available there is the task id of the initial code review task.

In addition to the unit tests, I managed to run code review bot locally as some sort of integration test. I didn't have it actually cancel any tasks, but I _think_ I've done enough to make this landable. Ideally we can test in a non-prod environment before production.
@bhearsum
bhearsum force-pushed the feat-cancel-in-progress-review branch from 581e8b8 to 7d8b26d Compare September 2, 2026 11:33
@bhearsum

bhearsum commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I managed to get a proper test done locally. I'm pretty darn confident this will work in production. You can see it in action in this revision: https://phabricator.services.mozilla.com/D320141. The previous diff had its buildable cancelled: https://phabricator.services.mozilla.com/D320141?id=1363741, and the try push for it was also cancelled: https://treeherder.mozilla.org/jobs?repo=try&revision=27b4f18dc9a63fa448de26b353d9ac1dbfb5b28c.

Latest update here contains a couple of notable changes:

  • Support for aborting previous buildables
  • Seal task groups prior to cancelling (otherwise cancelling doesn't work)

As part of testing I also discovered that there is a theoretical scenario where cancellation is missed when a second update is made to the revision in short order, and the previous try push doesn't have a decision task yet. I'm choosing not to care about this, because this scenario is very unlikely once try pushes fire off of github events in the not too distant future. It would be good to fix still, but in that world it's much less critical.

Regarding Ben's question, @La0 can you think of another way to retrieve the task group?

Currently i think it's the only way.

But it would not be complicated to store the task group in the backend next to Diff.review_task_id

Then you could fetch that info through the revision_diffs_list endpoint

I didn't implement this. I can as part of this if necessary, but I would prefer to do it in a follow-up later, if that's OK.

Comment on lines +494 to +496
# * Find the log for each Build Target, which will contain a taskId of Code Review task
# * Pull the Code Review task log to fetch the treeherder link with the revision pushed to Try in it
# * Look up the decision task id in the task index via the revision

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One way to at least cut this short would be to add the decision task ID to the publication task, so you could read the publication task definition instead of having to parse the logs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is the publication task the one that posts the results back to phab? If so, that means we'll be getting the information too late to matter? (If it's the one that runs to make the try push, that's too early...we don't have the decision task id yet.)

@marco-c marco-c left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, with the caveat that this only works with Phabricator and Mercurial, and doesn't with GitHub PRs and git or Phabricator and git (which is not supported yet but will soon).

@Archaeopteryx
Archaeopteryx merged commit feec731 into mozilla:master Sep 9, 2026
9 checks passed
bhearsum added a commit to mozilla-releng/fxci-config that referenced this pull request Sep 10, 2026
mozilla/code-review#3590 added support for cancelling previous reviewbot pushes when new ones are made. To do this, the tasks need to be able to cancel tasks from prior pushes; this requires both seal-task-group and cancel-task-group.

Related to https://bugzilla.mozilla.org/show_bug.cgi?id=2065267
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.

4 participants