Skip to content

ref(github): Derive one next action per pull request - #3395

Merged
BYK merged 5 commits into
mainfrom
fix/ready-to-merge-replaces-review-ask
Nov 13, 2026
Merged

BYK merged 5 commits into
mainfrom
fix/ready-to-merge-replaces-review-ask

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

The review desk showed both "Review requested · #N" and "Ready to merge · #N" for the same pull request. They came from two separate syncs, each with its own state and its own review item. The requester merges or reviews, not both.

Now one next action is derived per pull request:

  • Each webhook that can change the action reads the pull request from GitHub. That includes review request changes, reviews, pushes, check suites, auto-merge, draft, close, and reopen. A pure function derives merge (open, not a draft, approved, auto-merge off, mergeable_state is clean), else review (GitHub still requests the requester's review, even before GitHub computes the merge state), else none. An unknown merge state keeps a saved merge, so a push doesn't flip it.
  • At most one review item per pull request (pull-request-action:<repo>#<n>). Its title is "Ready to merge · #N" or "Review requested · #N". It changes only when the derived action changes, so repeat events add nothing, and an item that a person closed stays closed until the action changes.
  • junior_github_pull_requests.next_action caches the derived action and replaces ready_to_merge_at. Checks still run one at a time per pull request under the existing claim.
  • pull-request-review-request.ts, the webhook-payload ask sync, is gone. It was the second state machine.

Rollout:

  • Migration 0012 adds next_action, empty for every row. Each pull request's next check derives its action and adds the item under the new key. ready_to_merge_at stays in the table for one release for workers from before 0012. A later migration drops it.
  • Every check closes open items under the old keys (pull-request-ready:, pull-request-review-requested:), so they go away on the pull request's next webhook. A "Ready to merge" notice that someone dismissed on a pull request that is still ready comes back once under the new key.

Only the derived action is cached, not the raw facts (requested reviewers, approval, merge state). Every check reads them fresh from GitHub, and nothing reads them from the row yet. The follow-up after #3035 is for the Inbox and the Pull requests view to read next_action straight from the projection, so pull requests need no review items. It reuses nextAction.

via @BYK.

--

View Session [Sentry]

…erge

The requester merges or reviews a pull request, not both. The review desk
showed both "Review requested" and "Ready to merge" for the same pull
request. The ready notice now closes the review ask, and a review request
for a pull request that is ready to merge adds no ask.

Co-Authored-By: Burak Yigit Kaya <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 13, 2026 21:25
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 13, 2026 9:55pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 13, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

A review request can read the ready state before a ready check saves it,
and add the ask after the check closed it. The ready check now closes the
ask after it saves the ready state, and the review request reads the state
again after its upsert, so one of them always closes the ask.

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the main issue here is we are trying to keep a separate state from GitHub and then also adding more state with review cards etc.

I think this state should be derived possibly with a cache: check the PRs, if they need action, determine what it is and show in the review queue or whatever. The vision in #3035 (and its discussion in Junior) should be doing it this way already. If not we should make it so.

@sentry-junior

sentry-junior Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Agreed. This PR patches two state machines that have to stay in sync: the review-request ask, driven only by webhook payloads, and the ready notice, driven by readyToMergeAt and the ready-sync claim. Each has its own review item, and that is how they collided.

I checked #3035: it doesn't derive this. Its Pull requests view builds "Waiting on you" from open "Review requested" and "Ready to merge" review items, so it still depends on these stored cards.

There are two ways to derive it instead:

A. One derived action per PR, in the GitHub plugin. junior_github_pull_requests is already a projection of each PR. We'd cache the facts that decide the next action there: requested reviewer logins, approved, mergeable_state, auto-merge. They refresh on each relevant webhook with one GitHub read, under the existing ready-sync claim. Then a pure function gives the requester's next action: merge, review, or nothing. The review desk gets at most one item per PR, keyed by the PR, and it changes only when that action changes. This removes pull-request-review-request.ts's separate sync, and collisions become impossible by construction. It still uses a review item as the output.

B. No stored cards for PR actions. Same cached facts and derive function, but the Inbox and #3035's Pull requests view read the derived action from the projection, for example through the code overview the PR view already pages. Nothing upserts or closes review items for PRs. This needs a core contract for plugin-derived "needs action" rows, and it touches #3035, so it'd be its own PR stacked on #3035.

My pick: A here, with B as the follow-up once #3035 lands. A's derive function is what B reads, so A's work isn't thrown away. I've asked which one you want in Slack.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

The "Review requested" ask and the "Ready to merge" notice were two
review items with their own state, and they could both be open for one
pull request. The requester merges or reviews, not both.

Each webhook that can change the action now reads the pull request from
GitHub, derives one next action (merge, review, or none), and keeps one
review item per pull request. junior_github_pull_requests caches the
derived action in next_action, and the item changes only when it
changes. The review-request webhook sync is gone. Items under the two old
keys close when the action changes or the pull request closes.

Co-Authored-By: BYK <[email protected]>
@sentry-junior sentry-junior Bot changed the title fix(github): Close the review ask when the pull request is ready to merge ref(github): Derive one next action per pull request Nov 13, 2026
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: medium PR risk score: medium labels Nov 13, 2026
@sentry-junior

sentry-junior Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Reworked to option A in cda7a56b2. There is now one derived next action per PR (merge, review, or none), cached in junior_github_pull_requests.next_action. There is at most one review item per PR, and it changes only when the derived action changes. The separate review-request sync is gone, so the two items can't collide anymore.

One deviation from the plan: I cache only the derived action, not the raw facts. Every check already reads the PR fresh from GitHub under the existing claim, and nothing would read the raw facts from the row. For B, the Inbox can read next_action directly.

ready_to_merge_at stays in the table for one release, and old-key items close when the action changes or the PR closes. Details are in the description.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

A new pull request often has no merge state on review_requested, and
the check left the ask out until a later event. Now the ask shows when
the merge state is unknown, unless the saved action is merge, which
waits for GitHub to decide.

Each check also closes the items under the two old keys. Before, a
migrated pull request that stayed ready kept them open until its action
changed.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 02513ad. Configure here.

Migration 0012 set next_action to merge for ready pull requests. Each
check closes the old-key items, so the next webhook closed the old ready
notice, and the saved merge kept the new one from being added. With
next_action empty, the next check derives merge, adds the item under
the new key, and closes the old one.
* What waits on the requester of a Junior pull request: merge it, or review
* it. They take one, not both.
*/
export type GitHubPullRequestAction = "merge" | "review";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the PR is draft and CI passed, it may also wait? I guess this still falls under "review" bucket but may also fall under "mark as ready"? Thoughts?

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.

I don't think it fits under review. review means GitHub asks you for a review. For a draft with green CI, nobody has asked you anything, so it's a third action: "mark ready" (taking it out of draft).

The catch is who acts. For Junior's drafts, the PR watch already marks the draft ready itself once required checks pass, unless there's an open decision, code owners, or AGENTS.md say to keep it a draft. In those cases it tells you why in the thread. If we derive mark_ready from GitHub state alone (draft && required checks pass), it fires on every Junior draft. Most of those would flash on the desk and then close a minute later, when the watch marks them ready. That's the same kind of noise this PR removes.

My suggestion is a follow-up PR, not this one:

  • Add mark_ready to nextAction: open draft, required checks pass, and Junior left it a draft on purpose.
  • That last fact needs to be saved when the watch decides not to mark the draft ready, for example a kept_draft_reason on the PR row. The derive function then reads it as one more input.

If you'd rather show it for every green draft and accept the flash, it's a small change to nextAction. Your call.

@BYK
BYK enabled auto-merge (squash) November 13, 2026 22:02
@BYK
BYK merged commit 408067d into main Nov 13, 2026
45 checks passed
@BYK
BYK deleted the fix/ready-to-merge-replaces-review-ask branch November 13, 2026 22:05
BYK added a commit that referenced this pull request Nov 13, 2026
An Event Turn on #3395 called `noReply` with a note.
Then Junior posted this to Slack:

> Nothing was posted to Slack this turn; the outcome is saved as a
conversation note.

The Turn had run for about 3 minutes, so a soft yield was due. The step
listener checked for a yield before it checked whether the run had
ended. So it parked the Turn at the `noReply` tool result. The resumed
slice called the model again, and the model wrote that text.
`buildTurnResult` reads `noReply` only from the new messages of the
slice, so the text became the reply.

Now the `turn_end` listener checks run-ended first. A reply, `noReply`,
or blocked report has no next step, so nothing is left to resume.

Behavior change: a dispatch Turn that ends with `reply` while a yield is
due now finishes in one slice. Before, it parked and resumed into the
gated answer guard. That guard stays for crash recovery.

The fake agent in `agent-run-provider-retry.test.ts` yielded at a
`turn_end` with no tool results. Real Pi emits that only after the final
response, so the fake now yields after a tool batch.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A22ee8ffd3d20fc5c02b510ca -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A22ee8ffd3d20fc5c02b510ca)
[[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A22ee8ffd3d20fc5c02b510ca/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
BYK added a commit that referenced this pull request Nov 25, 2026
… in limbo (#4310)

The next action of a Junior pull request ("Review requested", "Ready to
merge", or the held-draft ask from #4306) is derived
only when a webhook that can change it arrives. Two groups of open PRs
have no item:

- Quiet PRs that went silent before a rule shipped. Example:
#2382, where GitHub asked for the requester's review on
11-12, before #3395, and no webhook has come since.
About 14 of BYK's PRs are `clean` and not approved. With
#4304 they derive `merge`, but no webhook will come to
derive it.
- **PRs in limbo:** ready PRs that ask nothing of their requester,
because no one ever asked for the requester's review. They were opened
ready, or became ready, before #3250, or the requester
linked GitHub later.

**This is a one-off run with a done key, not a recurring poll.** A new
started task, `backfillPullRequestActions`, does the run. It follows the
`repository-name-repair` one-off (#4192):

- After deploy, the GitHub heartbeat starts one page per tick: 50 open
Junior PRs, in GitHub id order. Each page has its own task key.
- Each page goes through the webhook sync path,
`syncGitHubPullRequestActions`, with the same claim and the same
concurrency limit of 5. A PR that no person asked for returns before any
GitHub read.
- After the last page, the task sets
`pull-request-action-backfill:v1:done` in plugin state, and the
heartbeat never starts it again. To run it again after a later rule
ships, bump `VERSION` in `pull-request-action-backfill.ts`.

## Limbo

`inLimbo` in `pull-request-action.ts` uses only what `nextAction`
already reads, plus the head commit time. An open Junior PR is in limbo
when all of these are true:

- The derived action is none.
- It is not a draft, and auto-merge is off.
- It has a stored requester with a linked GitHub login.
- GitHub has no pending user review request for the requester. A pending
request for another person or a team does not count, because it asks the
requester for nothing.
- The requester has not reviewed or commented since the last push (the
head commit's `committedDate`).
- No reviewer approved it. Such a PR waits only on others.
- No reviewer, the requester included, requests changes. On such a PR,
Junior acts next.

For each PR in limbo, the backfill asks for the requester's review on
GitHub. It uses `requestPullRequestReviewers`, the same call that
#3250 makes on `ready_for_review`. It asks only the
requester, and never code owners or teams. The next read then derives
the normal "Review requested" item. To show approval on a PR that is not
`clean`, the merge-state read now computes `reviewOutcome` for every
open PR. `nextAction` still reads it only for `clean` PRs.

**Side effect:** after deploy, the backfill sends one GitHub review
request to the requester on each PR in limbo, for all users. GitHub data
from 11-25: 98 open, ready Junior PRs, from 21 requesters, have an
assignee that GitHub does not ask for a review, are not approved, have
no change request, and have auto-merge off. This is an upper bound. PRs
that derive `merge`, PRs where the requester commented after the last
push, and PRs with no stored requester or linked login are not asked.
BYK has 34 of these PRs. About 14 of them derive "Ready to merge" under
#4304, so BYK gets about 20 review requests.

Dismissed items stay dismissed. The sync changes an item only when the
derived action is different from the saved one.
getsentry/sentry-rust#1400 has `merge` saved, so its dismissed "Ready to
merge" item does not come back. A PR in limbo has no saved action, so
asking for its review cannot bring back a dismissed item.

Started plugin tasks now get `inboxItems` and `users.readIdentity`, as
plugin routes do. The task needs them to show items and to map the
requester's linked GitHub login.

PRs that go into limbo after this one-off are handled by the PR stacked
on this one.

## Proposed design/github.md rule (not edited here)

> A ready Junior PR always has an Inbox ask or a pending GitHub review
request for its requester. When it asks nothing of the requester, Junior
asks for the requester's review on GitHub once the required checks pass,
but not after a push when the requester has already reviewed or
commented.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A6eedb91e2d3dfa1fd070e65575e7799d -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A6eedb91e2d3dfa1fd070e65575e7799d)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A6eedb91e2d3dfa1fd070e65575e7799d/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 64dbe369 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant