background-agents icon indicating copy to clipboard operation
background-agents copied to clipboard

Cancel the in-flight review session when a new review starts for the same PR

Open arodiss opened this issue 1 week ago • 1 comments

Problem

When a pull request gets a new review (an explicit review request, or the deprecated auto-review on opened) while an earlier review session for the same PR is still running, both sessions keep going and both can post a review. The second review usually exists because the first one is no longer wanted, so the duplicate costs compute and leaves conflicting reviews on the PR.

Proposed behaviour

Best-effort cancellation of the in-flight review session when a new review starts for the same PR, which is option (b) from the closing note on #1370:

  • After the github-bot creates a review session and before it prompts it, the bot asks the control plane (actorless, github-bot only) to record that session as the PR's current review.
  • The control plane cancels the review session it replaced. A failed cancel is persisted by session id and retried when the PR's next review starts. While it is pending, the control plane refuses the github-bot's prompts to that session, so a late or retried delivery cannot start a second review.
  • Cancellation never blocks the new review. If supersession is unavailable, the new review runs as it does today.
  • Mention sessions are untouched: they neither cancel reviews nor get cancelled.
  • Cost: one small D1 table and migration, one service route, and one extra call in the bot's review start.

Explicitly out of scope

  • Commit statuses (pending/success/error) and any close-out of them
  • A submission lease or any agent-side protocol; the prompt and submission script are unchanged
  • A reaper or any new scheduled job
  • New auto-review triggers (synchronize, reopened, ready_for_review); only the existing opened auto-review and review requests are covered
  • Reviewer-token route changes

Prior work

  • #1370 is the full supersession and close-out protocol, closed as too large for a deprecated path. This issue is the smaller option (b) proposed there.
  • #2628 is a closer, smaller attempt that was closed as stale. Its review findings are addressed: a failed cancel is persisted and retried by session id; the bot and route share one path constant; and the newly displaced session is cancelled before older pending ones.

I have an implementation ready and will link a PR here.

arodiss avatar Nov 24 '26 15:11 arodiss

Implementation: #2711

arodiss avatar Nov 24 '26 15:11 arodiss