fix(db): extend the out-of-order webhook guard to labels (PRs + issues) and resync on label-only drift - #8812
Merged
Merged
Conversation
…s) and resync on label-only drift (#8804) Three compounding staleness gaps around the pending-closure two-pass machine: - pull_requests: the #webhook-reorder-clobber guard protected state/headSha/ mergedAt but labelsJson was written unconditionally — a reordered stale snapshot silently wiped a JUST-applied disposition label (pending-closure, manual-review) even while the protected trio stayed correct. labelsJson now joins the resolved set, and the returned record reflects it. - issues: upsertIssueFromGitHub had no reorder protection at all. New github_updated_at column (migration 0175, mirrors 0172) + the same JS-side stale resolution for state and labels, same fail-open contract (sparse payload / pre-migration row applies the write unchanged). - reReviewStoredPullRequest resynced the stored row only on HEAD drift, discarding the live fetch's labels on a label-only change — exactly what Pass 1 of flag-then-close produces — so Pass 2 could misread the stale stored label set and re-run Pass 1 (duplicate warning, delayed enforcement). The resync now also fires on a sorted-set label mismatch.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8812 +/- ##
=======================================
Coverage 93.81% 93.81%
=======================================
Files 797 797
Lines 79608 79619 +11
Branches 24127 24134 +7
=======================================
+ Hits 74686 74697 +11
Misses 3556 3556
Partials 1366 1366
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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
Round-2 audit fix (#8804): label staleness could break the flag-then-close two-pass state machine in three compounding ways — a reordered webhook wiping a just-applied
pending-closure/manual-reviewlabel (the reorder guard protected state/headSha/mergedAt but wrotelabelsJsonunconditionally), issues having no reorder protection at all, and the sweep's live resync discarding label-only drift.Changes
src/db/repositories.ts—labelsJsonjoins the stale-guarded resolved set inupsertPullRequestFromGitHub(return value reflects it, per the function's own persisted-state contract);upsertIssueFromGitHubgains the full guard (state + labels) with the identical fail-open contract — sparse payloads and pre-migration rows apply the write exactly as before. Dead??fallbacks avoided (the column is NOT NULL).migrations/0175_issues_github_updated_at.sql+ schema — the issues twin of 0172's column; NULL for existing rows, self-backfilling on next sync.src/queue/processors.ts—reReviewStoredPullRequestresyncs on a sorted-set label mismatch too, not just head drift, so the live labels the sweep already fetched are persisted instead of discarded (Pass 2 of the flag-then-close machine reads a current label set).Test plan
npm run typecheck— cleanCloses #8804