Recover transient Plane-API failures during batch-merge bursts - #1
Merged
Conversation
A rapid batch-merge fans out many concurrent GitHub webhooks, each driving a state PATCH plus module-reconciliation reads. That burst can push a self-hosted Plane CE into 429s/timeouts. Previously such a transient failure became permanent state drift: the per-ref try/except in handle_pull_request logged-and-swallowed the exception, the webhook still answered HTTP 200, and GitHub (which only retries on non-2xx / timeout) never re-delivered — so the merged→Done transition vanished silently. Defend at three layers: 1. PlaneClient retries 429/5xx/timeout responses with jittered exponential backoff, honouring Retry-After when present. 2. If a ref still fails, handle_pull_request re-raises (PullRequestHandlerError) and the GitHub webhook route returns 503, so GitHub's built-in delivery retry re-runs the event. The handler's mutations are idempotent on replay (state PATCH is set-to-target, link attach dedups). Module-reconciliation failures stay non-fatal — the ticket-state work that matters already landed. 3. Resolver guards cold-cache population with asyncio.Lock(s), so a concurrent first-hit burst collapses to one list_projects / list_states fetch instead of a self-inflicted herd on the same API the handler is trying not to overrun. Tests cover ref-failure propagation, the non-fatal module path, the 503-vs-200 webhook mapping, client retry/exhaustion/Retry-After, and concurrent cold-cache single-fetch. Full suite: 160 passed; ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A rapid batch-merge fans out many concurrent GitHub webhooks, each driving a state PATCH plus module-reconciliation reads. That burst can push a self-hosted Plane CE into 429s/timeouts.
Previously a transient failure became permanent state drift: the per-ref
try/exceptinhandle_pull_requestlogged-and-swallowed the exception, the webhook still answered HTTP 200, and GitHub (which only retries on non-2xx / timeout) never re-delivered — so themerged → Donetransition vanished silently. The interleaved-within-seconds merge timestamps (adjacent PRs ~5s apart getting opposite outcomes) point to concurrent processing, not a Plane outage.Fix — three defensive layers
PlaneClientretries 429/5xx/timeout responses with jittered exponential backoff, honouringRetry-Afterwhen present.handle_pull_requestre-raises (PullRequestHandlerError) and the webhook route returns 503, so GitHub's built-in delivery retry re-runs the event. Mutations are idempotent on replay (state PATCH is set-to-target, link attach dedups). Module-reconciliation failures stay non-fatal — the ticket-state work that matters already landed.Resolvercold-cache lock —asyncio.Lock(s) guard cache population so a concurrent first-hit burst collapses to onelist_projects/list_statesfetch instead of a self-inflicted herd on the same API the handler is trying not to overrun.Tests
New/updated coverage for: ref-failure propagation, the non-fatal module path, the 503-vs-200 webhook mapping (
test_main.py), client retry/exhaustion/Retry-After, and concurrent cold-cache single-fetch.Full suite: 160 passed;
ruff checkclean.Not included (separate feature)
Remediation #4 — a periodic merged-PR-vs-ticket-state reconciliation sweep for self-healing — is left out deliberately: it needs GitHub API access plus interval/scope design. These three layers prevent recurrence; #4 would be belt-and-suspenders.
🤖 Generated with Claude Code