Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/vs/platform/agentHost/node/copilot/copilotAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,10 @@ export class CopilotAgent extends Disposable implements IAgent {
this._handleCopilotSessionAuthRequired();
}
await this._handleClientOperationFailure(err, 'modelRefresh');
// Teardown may have begun while the failure was handled: a retry would outlive the agent.
if (this._shutdownPromise || this._store.isDisposed) {
return;
}
if (attempt + 1 < this._modelRefreshMaxAttempts) {
const delay = this._modelRefreshBackoff(attempt);
this._logService.warn(`[Copilot] Failed to refresh models (attempt ${attempt + 1}), retrying in ${delay}ms`, err);
Expand Down
27 changes: 27 additions & 0 deletions src/vs/platform/agentHost/test/node/copilotAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7868,6 +7868,33 @@ suite('CopilotAgent', () => {
}
});

test('does not schedule a model refresh retry when the agent is torn down while a refresh failure is handled', async () => {
const client = new TestCopilotClient([], [{
id: 'gpt-4o',
name: 'GPT-4o',
}]);
client.modelListErrors.push(new Error('429 "too many requests"'));
const agent = createTestAgent(disposables, { copilotClient: client });
// Handling a failure can take a while, e.g. while a closed connection is recovered.
const failureHandlingStarted = new DeferredPromise<void>();
const finishFailureHandling = new DeferredPromise<void>();
(agent as unknown as { _handleClientOperationFailure(): Promise<undefined> })._handleClientOperationFailure = async () => {
failureHandlingStarted.complete();
await finishFailureHandling.p;
return undefined;
};
const authenticated = agent.authenticate('https://api.github.com', 'token');
await failureHandlingStarted.p;

await disposeAgent(agent);
finishFailureHandling.complete();
await authenticated;
await timeout(0);

// A retry timer scheduled now would outlive the agent: the suite's leak check reports it.
assert.strictEqual(client.modelListRequests.length, 1);
});

test('does not refresh models or restart the client after shutdown', async () => {
const client = new TestCopilotClient([], [{
id: 'gpt-4o',
Expand Down
Loading