Skip to content

feat(github): Patch pull request merge state in delayed plugin tasks - #4208

Merged
BYK merged 15 commits into
mainfrom
byk/github-patch-tasks
Nov 24, 2026
Merged

BYK merged 15 commits into
mainfrom
byk/github-patch-tasks

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Follows up merged #4204.

GitHub computes a pull request's merge state shortly after a push, and check events carry no counts, so a webhook marks both pending and a patch reads them later. Until now the patch waited in a plugin-state list that the heartbeat drained about once a minute. This moves each patch to a delayed plugin task, so it runs about 5 s after its event instead of at the next heartbeat.

Core

  • ctx.tasks.start takes delaySeconds, which goes to the queue send. The queue holds the first delivery for that long.
  • PluginStartedTaskContext gets lastDelivery. Core sets it from the queue delivery count, so a plugin can write a fallback on the last try without knowing the maximum.
  • createApp({ pluginTaskQueue }) passes the send options and the delivery count through, so an in-process queue can honor them.
  • Both are documented in extend/build-a-plugin.md.

GitHub

  • pull_request, check_suite, and check_run webhooks start patchPullRequest with key <cache key>:<head SHA>:<floor(eventMs / 5000)> and delaySeconds: 5. Events for one head in one 5 s window share a task. A later event starts a new task with its own retries. The payload carries the cache key (pulls:owner/repo#N) and the head SHA.
  • The task reads by repository and number, as before, and writes with the same logic. While GitHub still computes mergeable, or a webhook came after the read, it throws GitHubPullRequestPatchPendingError and the queue retries it with core's 30/60/120/240 s backoff.
  • On the last delivery, an UNKNOWN merge state is written as pending with the 15 s TTL, as the heartbeat's last attempt did. A pull request missing from the answer, a read of another head, or a query that fails on the last delivery also leaves the pending fields fresh for only 15 s.
  • The pull-request-patches list, its lock, and its heartbeat drain are gone. An old list in plugin state expires on its own TTL.

Max wait and failed deliveries

  • The longest a merge state stays pending from a webhook is 5 s + 30 + 60 + 120 + 240 s = 455 s. The last delivery keeps it pending for at most 15 s more, then a card read asks GitHub.
  • Deliveries 1–4 that throw are not logged as exceptions. Their plugin.task span is marked as an error with error.type (GitHubPullRequestPatchPendingError for a merge state that is still computing) and app.plugin.task.attempt.
  • A last delivery that still finds UNKNOWN does not throw. A last delivery whose query fails throws, and core logs plugin.task.failed.

Also in this PR

  • A page that links one pull request twice, such as /pull/12 and /pull/12#discussion_r1, gives out_of_time to every link, so none of them asks GitHub after the page's budget ran out.
  • The snooze picker's highlight follows the first row that can be picked. Open pull request rows wait for their cards, so the highlight first sat on the top merged row and stayed there, and Enter picked it. It now moves up to the top result when the cards arrive, unless the viewer already moved it by key or pointer.
Desktop Mobile
Light Snooze picker after the cards settle, light, desktop Snooze picker after the cards settle, light, mobile
Dark Snooze picker after the cards settle, dark, desktop Snooze picker after the cards settle, dark, mobile

via @BYK.

--

View Session [Sentry]

sentry-junior Bot and others added 7 commits November 24, 2026 14:58
After a page's card queries ran out of time, a shared 30 s cache marker
made every read of those pull requests skip GitHub. An Attach of an
uncached pull request in that window then returned "Object not found".

`prefetch` can now return an outcome per URL, and core passes it to that
URL's `canView` and `resolve` on the same page as `ctx.prefetchOutcome`.
The GitHub plugin returns `out_of_time` for the pull requests that the
page ran out of time for, and only those reads show the cached entry. An
Attach and other single reads get no outcome, so they ask GitHub. The
shared marker is gone.

Co-Authored-By: BYK <[email protected]>
A failed patch query split in halves down to one pull request each,
inside one heartbeat and with no time limit. During a GitHub outage that
is a tree of queries before the daily reconcile runs.

A failed patch query now waits for the next heartbeat as a whole, so an
outage costs one query per chunk of 25. Only the page card read still
splits, inside its 20 s budget, so `loadInHalves` moves next to it.

Co-Authored-By: BYK <[email protected]>
When the patch read a head commit other than the cached one, it skipped
the write and counted as done. Its pending merge state and checks then
stayed fresh for the full hour.

That patch is now dropped like one that finds no pull request: its
pending fields stay fresh for 15 s, so the next card read asks GitHub.

Co-Authored-By: BYK <[email protected]>
The snooze picker read a found pull request's draft state from its live
card as soon as the row showed. Before the card arrived it said "not a
draft", so a fast pick watched an open draft as a ready pull request.

An open pull request row in the picker now waits for its card, as the
`#` menu does.

Co-Authored-By: BYK <[email protected]>
The live card now replaces a saved object's row, and it came with the
Attach slot. A saved object is already part of the Conversation, so the
slot only showed "Attached", or took up space empty for a viewer who is
not a participant, and moved the row's state chip.

A saved object's row now has no Attach slot, as before the live card.

Co-Authored-By: BYK <[email protected]>
The row of a saved object has no Attach slot, but a link that an Attach
saved has only its link. On `main` its row showed the live card with its
"Attached" chip, and it does again. Known objects again say which saved
links are only links.

The attach journeys move from the object link spec to their own spec, so
each stays under the file length limit.

Co-Authored-By: BYK <[email protected]>
Webhooks start one patchPullRequest task per pull request, head commit
and 5 s window, with a 5 s start delay. While GitHub still computes the
merge state, the task throws and the queue retries it. On the last
delivery, the task keeps merge state pending for 15 s, as the heartbeat
patch did. The patch list, its lock and its heartbeat drain go away.

Core adds delaySeconds to tasks.start and lastDelivery to the started
task context.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 24, 2026 15:45
@sentry-junior
sentry-junior Bot added this pull request to stack #4209 November 24, 2026 15:45
@vercel

vercel Bot commented Nov 24, 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 24, 2026 7:02pm UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 24, 2026
sentry-junior Bot and others added 2 commits November 24, 2026 15:49
Checks belong to the head commit. A base retarget, or a same-head
webhook with mergeable null while the merge state is unknown, now marks
only the merge state pending and patches it. Known check counts stay.

Co-Authored-By: BYK <[email protected]>
Co-Authored-By: BYK <[email protected]>

# Conflicts:
#	packages/junior/tests/integration/api/github-object-refresh.test.ts
Webhooks now start patch tasks, so the test needs the task queue adapter.
It also checks which pull requests get a patch.
Base automatically changed from byk/github-cards-follow-ups to main November 24, 2026 16:17
A page that linked one pull request twice, such as /pull/12 and
/pull/12#discussion_r1, gave out_of_time to the last link only. The other
link then asked GitHub after the page's budget ran out.

Co-Authored-By: BYK <[email protected]>
Co-Authored-By: BYK <[email protected]>

# Conflicts:
#	packages/junior-github/src/issue-links.ts
#	packages/junior-github/src/pull-request-patches.ts
#	packages/junior/tests/integration/api/github-object-refresh.test.ts
#	packages/junior/tests/integration/api/github-page-budget.test.ts
@blacksmith-sh

This comment has been minimized.

@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 using default effort 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 e9c6678. Configure here.

…quest once its card arrives

Open pull request rows wait for their cards, so the picker first
highlighted the top row that does not wait, often a merged one, and kept
it there. Enter then picked that row instead of the top result.

The highlight now follows the first row that can be picked, unless the
viewer moved it by key or pointer.

Co-Authored-By: BYK <[email protected]>
A patch task for an older head kept reading and writing the shared pull
request entry after a push. When its read failed or answered another
head, it cut the new head's pending fields to 15 s.

A delivery whose head is no longer the cached head now returns without
reading GitHub, writing, or expiring. The new push's task owns the entry.

Co-Authored-By: BYK <[email protected]>
@BYK
BYK merged commit 443a17c into main Nov 24, 2026
58 checks passed
@BYK
BYK deleted the byk/github-patch-tasks branch November 24, 2026 21:18

This branch was successfully deployed

1 active deployment
Preview – junior-docs — c83e2f54 Deployed Nov 24, 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