From 4cb3a5c1d4e7bd174fb57f8c1f14ff1a228d5ad8 Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Sat, 13 Jun 2026 10:41:18 -0400 Subject: [PATCH] fix(web): update providers in every connected local environment, not just the primary The provider update popover and settings dispatched updateProvider only to the primary environment (ensureLocalApi). In dual-backend mode that left the WSL (or any other local secondary) provider un-updated. Add a small helper that fans the update out to the primary plus every connected local secondary backend that has the provider configured, looking up each environment's own instance id (the same driver has a distinct instance id per environment). Wire it into both dispatch sites and reuse the existing result aggregation / toasts unchanged. Remote (SSH / relay) environments are skipped. --- .../ProviderUpdateLaunchNotification.tsx | 9 +-- .../components/settings/SettingsPanels.tsx | 12 ++-- apps/web/src/environmentApi.ts | 56 ++++++++++++++++++- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/apps/web/src/components/ProviderUpdateLaunchNotification.tsx b/apps/web/src/components/ProviderUpdateLaunchNotification.tsx index 69cd83bf8d..efc618584b 100644 --- a/apps/web/src/components/ProviderUpdateLaunchNotification.tsx +++ b/apps/web/src/components/ProviderUpdateLaunchNotification.tsx @@ -3,7 +3,7 @@ import { DownloadIcon } from "lucide-react"; import { useCallback, useEffect, useMemo, useRef } from "react"; import { type ProviderDriverKind, type ProviderInstanceId } from "@t3tools/contracts"; -import { ensureLocalApi } from "../localApi"; +import { updateProviderAcrossLocalEnvironments } from "../environmentApi"; import { useDismissedProviderUpdateNotificationKeys } from "../providerUpdateDismissal"; import { useServerProviders } from "../rpc/serverState"; import { PROVIDER_ICON_BY_PROVIDER } from "./chat/providerIconUtils"; @@ -207,11 +207,8 @@ export function ProviderUpdateLaunchNotification() { }); void Promise.allSettled( - oneClickProviders.map(async (provider) => - ensureLocalApi().server.updateProvider({ - provider: provider.driver, - instanceId: provider.instanceId, - }), + oneClickProviders.flatMap((provider) => + updateProviderAcrossLocalEnvironments(provider.driver, provider.instanceId), ), ).then((results) => { const activeUpdateToast = activeToastRef.current; diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index 76d5d34c35..3e079f2195 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -46,6 +46,7 @@ import { sortProviderInstanceEntries, } from "../../providerInstances"; import { ensureLocalApi, readLocalApi } from "../../localApi"; +import { updateProviderAcrossLocalEnvironments } from "../../environmentApi"; import { useShallow } from "zustand/react/shallow"; import { selectProjectsAcrossEnvironments, useStore } from "../../store"; import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState"; @@ -985,10 +986,13 @@ export function ProviderSettingsPanel() { } try { - await ensureLocalApi().server.updateProvider({ - provider: candidate.driver, - instanceId: candidate.instanceId, - }); + const results = await Promise.allSettled( + updateProviderAcrossLocalEnvironments(candidate.driver, candidate.instanceId), + ); + const rejected = results.find((result) => result.status === "rejected"); + if (rejected?.status === "rejected") { + throw rejected.reason; + } } catch (error) { toastManager.add( stackedThreadToast({ diff --git a/apps/web/src/environmentApi.ts b/apps/web/src/environmentApi.ts index bdb2e79306..4480323c99 100644 --- a/apps/web/src/environmentApi.ts +++ b/apps/web/src/environmentApi.ts @@ -1,7 +1,18 @@ -import type { EnvironmentId, EnvironmentApi } from "@t3tools/contracts"; +import type { + EnvironmentId, + EnvironmentApi, + ProviderDriverKind, + ProviderInstanceId, + ServerProviderUpdatedPayload, +} from "@t3tools/contracts"; import type { WsRpcClient } from "@t3tools/client-runtime"; -import { readEnvironmentConnection } from "./environments/runtime"; +import { + getPrimaryEnvironmentConnection, + getSavedEnvironmentRuntimeState, + listSavedEnvironmentRecords, + readEnvironmentConnection, +} from "./environments/runtime"; const environmentApiOverridesForTests = new Map(); @@ -87,6 +98,47 @@ export function ensureEnvironmentApi(environmentId: EnvironmentId): EnvironmentA return api; } +/** + * Dispatch a provider update to every connected local backend that has the + * provider configured — the primary plus any local secondary (e.g. WSL) — and + * return one in-flight promise per environment so callers can aggregate results + * with the existing toast helpers. The update candidate always comes from the + * primary's provider list, so its instance id is passed in for the primary; + * each secondary's instance id is looked up from that environment's own server + * config, since the same driver has a distinct instance id per environment. + */ +export function updateProviderAcrossLocalEnvironments( + driver: ProviderDriverKind, + primaryInstanceId: ProviderInstanceId, +): ReadonlyArray> { + const primary = getPrimaryEnvironmentConnection(); + const dispatches: Array> = [ + primary.client.server.updateProvider({ provider: driver, instanceId: primaryInstanceId }), + ]; + + for (const record of listSavedEnvironmentRecords()) { + // Local backends only (skip SSH / relay / remote), and never the primary twice. + if (!record.desktopLocal || record.environmentId === primary.environmentId) { + continue; + } + const connection = readEnvironmentConnection(record.environmentId); + if (!connection) { + continue; // not connected / not settled + } + const providers = + getSavedEnvironmentRuntimeState(record.environmentId).serverConfig?.providers ?? []; + const match = providers.find((provider) => provider.driver === driver); + if (!match) { + continue; // provider not configured in this environment + } + dispatches.push( + connection.client.server.updateProvider({ provider: driver, instanceId: match.instanceId }), + ); + } + + return dispatches; +} + export function __setEnvironmentApiOverrideForTests( environmentId: EnvironmentId, api: EnvironmentApi,