865
866
private _startModelRefresh(generation: number): Promise<void> {
867
>
const refresh = this._refreshModels(0, generation).finally(() => {
copilotAgent.ts
868
>
if (this._modelRefreshInFlight === refresh) {
869
>
this._modelRefreshInFlight = undefined;
870
>
}
871
>
});
872
>
this._modelRefreshInFlight = refresh;
873
>
return refresh;
874
>
}
875
876
private async _refreshModels(attempt = 0, generation = this._modelCatalogGeneration): Promise<void> {
877
>
// A fresh refresh (e.g. a token change) supersedes any scheduled retry.
copilotAgent.ts
878
>
this._modelRefreshRetry.clear();
879
>
880
>
// Once teardown has begun, skip the refresh entirely: a retry timer that
881
>
// fires during the shutdown window would otherwise call `_ensureClient()`
882
>
// and resurrect the SDK subprocess after `shutdown()` tore it down.
883
>
if (this._shutdownPromise) {
884
return;
885
}
887
>
const tokenAtRefreshStart = this._githubToken;
888
>
if (!tokenAtRefreshStart) {
889
this._capiModels = [];
890
this._publishModels();
891
return;
892
}
894
>
const models = await this._listModels(tokenAtRefreshStart);
895
>
if (this._githubToken === tokenAtRefreshStart && this._modelCatalogGeneration === generation) {
896
this._capiModels = models;
897
this._publishModels();
898
}
900
// Token rotated mid-flight — a newer refresh owns the result — or
901
// teardown began while the request was in flight, in which case a