Skip to content

Commit 8052cbe

Browse files
Copilotalexr00
andauthored
Implement exponential backoff for Copilot refresh after commenting on Padawan PRs (#7288)
* Initial plan * Initial analysis of exponential backoff implementation plan Co-authored-by: alexr00 <[email protected]> * Implement exponential backoff for Copilot refresh after commenting Co-authored-by: alexr00 <[email protected]> * Add unit tests for Copilot refresh exponential backoff logic Co-authored-by: alexr00 <[email protected]> * Revert yarn.lock to original state Co-authored-by: alexr00 <[email protected]> * Change delays, refresh if any timeline event occurred. * Delete useless tests * Start delay smaller --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: alexr00 <[email protected]>
1 parent 0a303b9 commit 8052cbe

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/github/issueOverview.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,17 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
350350
return this._replyMessage(message, reply);
351351
}
352352

353+
private _scheduledRefresh: Promise<void> | undefined;
353354
protected async tryScheduleCopilotRefresh(commentBody: string, reviewType?: ReviewStateValue) {
355+
if (!this._scheduledRefresh) {
356+
this._scheduledRefresh = this.doScheduleCopilotRefresh(commentBody, reviewType)
357+
.finally(() => {
358+
this._scheduledRefresh = undefined;
359+
});
360+
}
361+
}
362+
363+
private async doScheduleCopilotRefresh(commentBody: string, reviewType?: ReviewStateValue) {
354364
if (!COPILOT_ACCOUNTS[this._item.author.login]) {
355365
return;
356366
}
@@ -359,7 +369,31 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
359369
return;
360370
}
361371

362-
await new Promise(resolve => setTimeout(resolve, 1000));
372+
const initialTimeline = await this._getTimeline();
373+
const delays = [250, 500, 1000, 2000];
374+
375+
for (const delay of delays) {
376+
await new Promise(resolve => setTimeout(resolve, delay));
377+
if (this._isDisposed) {
378+
return;
379+
}
380+
381+
try {
382+
const currentTimeline = await this._getTimeline();
383+
384+
// Check if we have any new CopilotStarted events
385+
if (currentTimeline.length > initialTimeline.length) {
386+
// Found a new CopilotStarted event, refresh and stop
387+
this.refreshPanel();
388+
return;
389+
}
390+
} catch (error) {
391+
// If timeline fetch fails, continue with the next retry
392+
Logger.warn(`Failed to fetch timeline during Copilot refresh retry: ${error}`, IssueOverviewPanel.ID);
393+
}
394+
}
395+
396+
// If no new CopilotStarted events were found after all retries, still refresh once
363397
if (!this._isDisposed) {
364398
this.refreshPanel();
365399
}

0 commit comments

Comments
 (0)