fix(fetch): stop repository conflicts from failing whole PR batches - #62
Merged
Conversation
A same-repository fanout could livelock: when concurrent batches raced the incidental parent-repository apply, the losing batch's observation conflict failed every prepared PR from that repository, and the handler's immediate retries kept competing workers phase-locked while River re-ran the larger jobs (issue #60). The repository upsert is already monotonic by GitHub's update clock, so a superseded snapshot only proves interleaving, never staleness. The coordinator now retries the incidental repository apply against a fresh observation without refetching, treats an exhausted conflict as non-fatal for the independently fenced PR observations, and no longer fails branch-page items that skipped the parent observation. The handler-level superseded retry gains full jitter so competing refetches desynchronize. Fixes #60 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Silently skipping the incidental parent apply after exhausted snapshot retries could drop a webhook observation's repository domain changes, letting a later reconcile-source refresh claim them (and their provenance) — observed as an order-independence divergence in CI. In-place retries still absorb each competing commit without refetching, so the issue #60 livelock stays fixed; only sustained churn now escalates to the handler's jittered refetch, which guarantees the parent representation eventually lands with its original provenance. Co-Authored-By: Claude Fable 5 <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.
Summary
Fixes #60.
A same-repository PR fanout could livelock: concurrent batches raced the incidental parent-repository apply, the losing batch's
ErrObservationSupersededfailed every prepared PR from that repository, andretrySupersededObservation's immediate retries kept competing workers phase-locked while River re-ran the larger jobs.Approach
The key observation is that
UpsertRepositoryWriteIfNeweralready keeps the repository row monotonic by GitHub's ownupdated_atclock, so a superseded observation snapshot only proves local interleaving — never that the fetched repository representation is stale. That makes a conflict on the incidental parent write recoverable without refetching:TestOrderIndependenceFinalCacheStatein CI on an earlier revision of this branch that skipped the apply entirely).ErrRefreshGenerationSuperseded) is unchanged.retrySupersededObservationnow applies full jitter between attempts so competing same-repository workers desynchronize instead of re-conflicting in lockstep.Acceptance criteria from #60
TestCoordinatorRepositoryConflictDoesNotFailBatchPRs, asserts zero extra GraphQL fetches and both PR writes landing).TestCoordinatorSameRepositoryFanoutConvergesWithoutRefetch).Both tests reproduce the reported failure (
apply repository: observation superseded+ refetch amplification) when run against the previous coordinator behavior.Testing
go test ./internal/fetch/(full package, local Postgres), plus 5× stress of the new tests together withTestOrderIndependenceFinalCacheStatego test ./...exceptcmd/loadgen, matching CI's splitmake lintclean🤖 Generated with Claude Code