fix(providers): prevent stale models during refresh

Provider settings sheets can remain mounted while hidden, so the old display cache could survive into a different provider. Scope the cache to the active provider identity and remount the sheet when that identity changes.
This commit is contained in:
Mohamed Boudra
2026-06-25 18:41:57 +07:00
parent f13c496ebc
commit 2692211ef9
4 changed files with 126 additions and 14 deletions
@@ -0,0 +1,69 @@
import { describe, expect, it } from "vitest";
import type { AgentModelDefinition } from "@getpaseo/protocol/agent-types";
import {
resolveProviderDiscoveredModels,
type ProviderDiscoveredModelsCache,
} from "./provider-diagnostic-models";
const piModel: AgentModelDefinition = {
provider: "pi",
id: "pi/model",
label: "Pi Model",
};
const grokModel: AgentModelDefinition = {
provider: "grok",
id: "grok-build",
label: "Grok Build",
};
function resolveModels(input: {
serverId?: string;
provider: string;
currentModels?: AgentModelDefinition[];
loading?: boolean;
cache?: ProviderDiscoveredModelsCache | null;
}) {
return resolveProviderDiscoveredModels({
serverId: input.serverId ?? "local",
provider: input.provider,
currentModels: input.currentModels,
providerSnapshotRefreshing: input.loading === true,
previousCache: input.cache ?? null,
});
}
describe("resolveProviderDiscoveredModels", () => {
it("keeps a provider's cached discovered models visible while that provider refreshes", () => {
const ready = resolveModels({ provider: "grok", currentModels: [grokModel] });
const refreshing = resolveModels({ provider: "grok", loading: true, cache: ready.cache });
expect(refreshing.models).toEqual([grokModel]);
});
it("does not show one provider's cached models while another provider loads", () => {
const ready = resolveModels({ provider: "pi", currentModels: [piModel] });
const refreshing = resolveModels({ provider: "grok", loading: true, cache: ready.cache });
expect(refreshing.models).toEqual([]);
});
it("does not show another server's cached models while the same provider loads", () => {
const ready = resolveModels({
serverId: "server-a",
provider: "grok",
currentModels: [grokModel],
});
const refreshing = resolveModels({
serverId: "server-b",
provider: "grok",
loading: true,
cache: ready.cache,
});
expect(refreshing.models).toEqual([]);
});
});