From 19533d9f25227d0cce8efbe42590a93e35535dec Mon Sep 17 00:00:00 2001 From: Alex Ross <38270282+alexr00@users.noreply.github.com> Date: Tue, 9 Jun 2026 11:50:00 +0200 Subject: [PATCH 1/3] Do not poll when window is not focused --- src/view/reviewManager.ts | 46 ++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/view/reviewManager.ts b/src/view/reviewManager.ts index 38bc2b3341..b83efe695e 100644 --- a/src/view/reviewManager.ts +++ b/src/view/reviewManager.ts @@ -145,6 +145,13 @@ export class ReviewManager extends Disposable { this.updateState(true); } this.pollForStateChange(); + this._register(vscode.window.onDidChangeWindowState(state => { + if (state.focused && !this._pollHandle) { + // Polling was skipped because the window was not focused. + // Poll immediately now that focus has returned. + this.doPoll(); + } + })); this._register(toDisposable(() => { if (this._pollHandle) { clearTimeout(this._pollHandle); @@ -229,23 +236,32 @@ export class ReviewManager extends Disposable { } private pollForStateChange() { - this._pollHandle = setTimeout(async () => { - if (this.isDisposed) { - return; + this._pollHandle = setTimeout(() => this.doPoll(), 1000 * 60 * 5); + } + + private async doPoll() { + if (this.isDisposed) { + return; + } + this._pollHandle = undefined; + if (!vscode.window.state.focused) { + // Skip polling while the window is not focused. Polling will resume + // immediately when the window regains focus (see onDidChangeWindowState). + Logger.appendLine('Skipping poll: window is not focused', this.id); + return; + } + Logger.appendLine('Polling for state change...', this.id); + try { + if (!this._validateStatusInProgress && !this._folderRepoManager.activePullRequest) { + await this.updateState(); } - Logger.appendLine('Polling for state change...', this.id); - try { - if (!this._validateStatusInProgress && !this._folderRepoManager.activePullRequest) { - await this.updateState(); - } - } catch (e) { - Logger.warn(`Polling for state change failed: ${formatError(e)}`, this.id); - } finally { - if (!this.isDisposed) { - this.pollForStateChange(); - } + } catch (e) { + Logger.warn(`Polling for state change failed: ${formatError(e)}`, this.id); + } finally { + if (!this.isDisposed) { + this.pollForStateChange(); } - }, 1000 * 60 * 5); + } } private async updateBaseBranchMetadata(oldHead: Branch, newHead: Branch) { From f2f1fb3bf1c0bff9bc97211e0c8cefe2b4ed37c8 Mon Sep 17 00:00:00 2001 From: Alex Ross <38270282+alexr00@users.noreply.github.com> Date: Tue, 9 Jun 2026 12:33:03 +0200 Subject: [PATCH 2/3] CCR feedback --- src/view/reviewManager.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/view/reviewManager.ts b/src/view/reviewManager.ts index b83efe695e..474322aca5 100644 --- a/src/view/reviewManager.ts +++ b/src/view/reviewManager.ts @@ -236,6 +236,9 @@ export class ReviewManager extends Disposable { } private pollForStateChange() { + if (this._pollHandle) { + clearTimeout(this._pollHandle); + } this._pollHandle = setTimeout(() => this.doPoll(), 1000 * 60 * 5); } From 3677069b2b81003574c9699baf9bfa7f87f1292f Mon Sep 17 00:00:00 2001 From: Alex Ross <38270282+alexr00@users.noreply.github.com> Date: Tue, 9 Jun 2026 12:40:12 +0200 Subject: [PATCH 3/3] Add jitter --- src/view/reviewManager.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/view/reviewManager.ts b/src/view/reviewManager.ts index 474322aca5..c3ff30c921 100644 --- a/src/view/reviewManager.ts +++ b/src/view/reviewManager.ts @@ -148,8 +148,10 @@ export class ReviewManager extends Disposable { this._register(vscode.window.onDidChangeWindowState(state => { if (state.focused && !this._pollHandle) { // Polling was skipped because the window was not focused. - // Poll immediately now that focus has returned. - this.doPoll(); + // Schedule a poll with a randomized delay (jitter) so that in + // multi-repo setups all ReviewManagers don't poll at the same time. + const jitter = 15_000 + Math.floor(Math.random() * 45_000); // 15-60s + this._pollHandle = setTimeout(() => this.doPoll(), jitter); } })); this._register(toDisposable(() => {