Skip to content

feat(plugins): Retry failed plugin webhook writes with tasks - #4109

Merged
BYK merged 4 commits into
mainfrom
feat/plugin-task-start-retry
Nov 24, 2026
Merged

BYK merged 4 commits into
mainfrom
feat/plugin-task-start-retry

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

GitHub sends a webhook only once. When the pull request outcome write failed inside the webhook, the outcome was lost until the daily reconcile reached that repository. This adds a retried path for plugin writes that fail inside a route, and uses it for the GitHub pull request outcome.

Plugin tasks that a plugin starts

  • Plugin route contexts and the heartbeat context get ctx.tasks.start({ name, key, payload }).
  • A task in tasks that has a Zod payload schema runs only when the plugin starts it. Tasks without payload still run after each completed session, as before. Session scheduling skips tasks with a payload.
  • tasks.start sends a signed { plugin, name, payload } message on the existing junior_plugin_tasks topic. The payload travels as JSON in the message. It is checked against the task's schema before the send and parsed again before each run. Core stores nothing.
  • The queue idempotency key is a SHA-256 hash of the plugin, the task name, and the key. Vercel Queues accepts at most 256 characters, so the plugin's key is never sent as is. A second start with the same key does nothing while the queue keeps the first message.
  • A failed run is delivered again after 30, 60, 120, then 240 seconds. QueueRetryDirective now accepts { afterSeconds }, which maps to the Vercel Queues retry handler. The fifth delivery that fails logs plugin.task.failed and is acknowledged.
  • The run context has payload, state, annotations, codeChanges, and conversationChanges, like a plugin route. It has no session.

GitHub pull request outcomes

The webhook still applies the outcome inline. When applyGitHubPullRequestOutcome throws, it logs a warning, starts an applyPullRequestOutcome task with the outcome as payload and the key pull-request-outcome:<pull request id>:<state>:<updatedAt>, and returns 202. The task runs applyGitHubPullRequestOutcome again. That path is safe to repeat: the outcome row updates with lte(updatedAt), the code index record and chip annotations upsert, and Inbox closes are no-ops for closed items.

Scope choices

  • The backoff is set on the whole junior_plugin_tasks topic, so session tasks that fail now also wait before their next delivery instead of retrying at the visibility timeout.
  • If tasks.start cannot send the message, the error reaches the route. For GitHub, the daily reconcile still covers an outcome that never reached the queue.
  • After a failed inline write, the webhook skips merged-commit classification for that delivery. The task applies only the outcome.
  • tasks.start has no delay option yet.
  • sendPluginTask is now required where route and heartbeat contexts are built, so tests pass it explicitly.

Docs: extend/build-a-plugin.md documents tasks.start, the payload schema, the backoff, and the hashed key. TELEMETRY.md lists plugin.task.failed.

Closes #4104

via @BYK.

--

View Session [Sentry]

Plugin routes and heartbeats get tasks.start({ name, key, payload }).
Core stores the payload in junior_plugin_tasks, one row per plugin and
key, sends a small signed message on junior_plugin_tasks, and runs the
plugin's task with a payload schema. A failed run is delivered again
after 30, 60, 120, and 240 seconds, and the fifth failed run ends the
task as failed. The heartbeat sends again a task whose lease expired.

The GitHub webhook starts an applyPullRequestOutcome task when the
inline pull request outcome write fails.

Closes #4104

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 23, 2026 17:03
@vercel

vercel Bot commented Nov 23, 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 10:49am UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Nov 23, 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.

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 503a20e. Configure here.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

1 screenshot change — 1 changed · 0 added · 0 removed

Review screenshots in Frameshift

Person Profile · Desktop
Person Profile · Desktop
Changed

…t-retry

# Conflicts:
#	packages/junior/migrations/meta/0163_snapshot.json
#	packages/junior/migrations/meta/_journal.json
Drop the junior_plugin_tasks table, its migration, the row lease, and
the heartbeat recovery. tasks.start now sends the JSON payload in the
signed queue message, with an idempotency key that hashes the plugin,
task name, and key, so a long key fits the queue's limit. A failed run
retries after 30, 60, 120, then 240 seconds. The fifth failed delivery
logs plugin.task.failed and is acknowledged.

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

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

# Conflicts:
#	packages/junior/src/chat/plugins/task-queue.ts
@BYK
BYK merged commit ecea740 into main Nov 24, 2026
59 checks passed
@BYK
BYK deleted the feat/plugin-task-start-retry branch November 24, 2026 11:40
BYK added a commit that referenced this pull request Nov 24, 2026
…fill (#4192)

This repairs repository names that #4147's backfill left
stale.

GitHub migration 0020 from that PR added missing repositories to
Junior's code index with `ON CONFLICT DO NOTHING`. When the index
already had a repository under its name from before a rename, it kept
that name, and 0021 then dropped the newer copy in the plugin table. The
plugin finds pull requests by repository name for merge conflict checks,
next-action sync, preview images, and Resume. For a renamed repository,
those lookups miss until a lifecycle webhook records the new name.

**Repair.** The GitHub plugin reads the current `full_name` of each
repository in the code index from GitHub by its id, and records each
name that changed. The requests use one metadata-only installation token
and run four at a time. A 404 leaves the stored name as it is. Any other
error is logged for that repository, and the repair moves on to the
next.

**Runs once.** The heartbeat starts the `repairRepositoryNames` task
with a fixed key until a done mark is in plugin state. The task checks
the mark, repairs the names, and sets the mark. This uses the started
tasks from #4109, so the GitHub reads run outside the
heartbeat, a failed run retries, and two heartbeats cannot start two
repairs. After the mark is set, each heartbeat does one state read for
it.

**Plugin API.** `PluginCodeChanges.recordRepository({ name, providerId,
updatedAt })` is a new write. It is the repository upsert that
`record()` already runs, now a function of its own, so the same
`updatedAt` guard applies and an older name cannot replace a newer one.
The repair writes with the time of the run. To list the stored
repositories, the repair reads all of the plugin's code changes with
`codeChanges.list({})`, so it needs no new read. That is one query, run
once.

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

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

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A2e495f28ee4179158c8af1f4deeb197f)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2e495f28ee4179158c8af1f4deeb197f/?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 — 2536d84c 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.

Retry failed plugin webhook writes with backoff

1 participant