fix: clear stale pr refresh backoff entries (#4207)

This commit is contained in:
Neil
2026-05-31 08:17:54 -07:00
committed by GitHub
parent 0d1fdac094
commit 08ee240b7c
2 changed files with 37 additions and 0 deletions
@@ -427,6 +427,36 @@ describe('pr-refresh-coordinator', () => {
expect(getPRForBranchOutcomeMock).toHaveBeenCalledTimes(1)
})
it('clears visible retry backoff when a non-visible manual refresh steals the retry', async () => {
const {
_getPRRefreshErrorBackoffCountForTests,
refreshPRNow,
reportVisiblePRRefreshCandidates
} = await import('./pr-refresh-coordinator')
getPRForBranchOutcomeMock
.mockResolvedValueOnce({
kind: 'upstream-error',
errorType: 'network',
message: 'network down',
fetchedAt: Date.now()
})
.mockResolvedValueOnce({
kind: 'found',
pr: makePR({ checksStatus: 'success' }),
fetchedAt: Date.now()
})
const candidate = makeCandidate()
reportVisiblePRRefreshCandidates([candidate], 1, 1)
await vi.advanceTimersByTimeAsync(0)
expect(_getPRRefreshErrorBackoffCountForTests()).toBe(1)
getAllWebContentsMock.mockReturnValue([])
await refreshPRNow(candidate)
expect(_getPRRefreshErrorBackoffCountForTests()).toBe(0)
})
it('retries visible PRs with unknown mergeability before the success-check interval', async () => {
const { reportVisiblePRRefreshCandidates } = await import('./pr-refresh-coordinator')
getPRForBranchOutcomeMock
@@ -276,6 +276,9 @@ function scheduleVisibleFollowUp(
windowId?: number
): void {
if (!isVisibleKey(key)) {
// Why: manual/active refreshes can remove the queued visible retry after
// its owner window is gone, leaving the retry backoff without an owner.
errorBackoff.delete(key)
return
}
if (outcome.kind === 'upstream-error') {
@@ -582,6 +585,10 @@ export function _getVisiblePRRefreshWindowCountForTests(): number {
return visibleByWindow.size
}
export function _getPRRefreshErrorBackoffCountForTests(): number {
return errorBackoff.size
}
export async function refreshPRNow(candidate: GitHubPRRefreshCandidate): Promise<PRRefreshOutcome> {
const alias = aliasFromCandidate(candidate)
const key = refreshKey(candidate)