From 08ee240b7c0858c470d332e49191115674c08b33 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 08:17:54 -0700 Subject: [PATCH] fix: clear stale pr refresh backoff entries (#4207) --- .../github/pr-refresh-coordinator.test.ts | 30 +++++++++++++++++++ src/main/github/pr-refresh-coordinator.ts | 7 +++++ 2 files changed, 37 insertions(+) diff --git a/src/main/github/pr-refresh-coordinator.test.ts b/src/main/github/pr-refresh-coordinator.test.ts index 61af70a7d..ce924f29e 100644 --- a/src/main/github/pr-refresh-coordinator.test.ts +++ b/src/main/github/pr-refresh-coordinator.test.ts @@ -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 diff --git a/src/main/github/pr-refresh-coordinator.ts b/src/main/github/pr-refresh-coordinator.ts index 0c293cf4a..c35baa9b2 100644 --- a/src/main/github/pr-refresh-coordinator.ts +++ b/src/main/github/pr-refresh-coordinator.ts @@ -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 { const alias = aliasFromCandidate(candidate) const key = refreshKey(candidate)