fix(queue): verify the latest reopen actor before re-closing a disallowed reopen - #2421
Merged
Conversation
…owed reopen Head/state freshness and a fresh re-check of the original reopener's own permission both miss a real race: a DIFFERENT person (e.g. an actual maintainer) can reopen the same PR again after the original disallowed reopen — a legitimate, authorized action. Since the PR was already open, that second reopen changes neither head SHA nor open/closed state, so neither existing live re-check can see it, and the handler would still wrongly undo the maintainer's reopen. Generalizes getLastCloserLogin's timeline-scanning pagination engine (src/github/pr-actions.ts) into a shared, event-type-parameterized helper, adds getLastReopenerLogin alongside it, and wires a third live re-check into maybeRecloseDisallowedReopen: deny the close unless the ORIGINAL disallowed reopener is still the most recent "reopened" actor on the PR's live timeline. Fails closed (denies) when the timeline scan can't prove that, mirroring the existing fail-closed precedent for an unresolvable freshness read.
…nches The audit-write catch on the new superseded-reopener denial path, the null-latest-reopener 'unknown' fallback in its detail message, and the lastPage<=1 single-page-with-Link-header branch in the generalized timeline scanner were all reachable but untested.
Contributor
|
Important 🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪 🔍 Gittensory is reviewing…AI analysis is in progress. This comment will update when the review is complete. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed · 🟪 Reviewing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2421 +/- ##
=======================================
Coverage 95.84% 95.84%
=======================================
Files 224 224
Lines 25048 25060 +12
Branches 9106 9112 +6
=======================================
+ Hits 24007 24020 +13
Misses 427 427
+ Partials 614 613 -1
🚀 New features to boost your workflow:
|
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
getLastCloserLogin's timeline-scanning pagination engine (src/github/pr-actions.ts) into a shared, event-type-parameterized helper, and addsgetLastReopenerLoginalongside it (same signature shape, same fail-conservative error handling).maybeRecloseDisallowedReopen: deny the close unless the original disallowed reopener is still the most recentreopenedactor on the PR's live timeline. Fails closed (denies) when the timeline scan can't prove that — mirroring the existing fail-closed precedent for an unresolvable freshness read — since wrongly re-closing a maintainer-authorized PR is worse than leaving a disallowed reopen open for one more tick.Test plan
npx vitest run test/unit/queue.test.ts test/unit/github-pr-actions.test.ts— all passing, including regressions for: a different (maintainer) reopener superseding the original disallowed one (deny), the happy path unaffected (same reopener still latest → still closes), a timeline-read error (fail-closed deny), the "genuinely no reopen event found" case (deny with an "unknown" detail), and an audit-write failure on the new denial path (swallowed, handler still completes)npm run test:coverage— full suite green, 100% patch coverage on changedsrc/**lines/branchesnpm run typecheck— cleangit diff --check— cleannpm run test:ci+npm audit --audit-level=moderate— clean