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.
This commit is contained in:
Josh Gratton committed 2026-06-13 10:41:18 -04:00
1 parent 70db2edcde
commit 4cb3a5c1d4
3 files changed
+65 -12

No files matched your search

@@ -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;
@@ -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({
+54 -2
View File
@@ -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<EnvironmentId, EnvironmentApi>();
@@ -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<Promise<ServerProviderUpdatedPayload>> {
const primary = getPrimaryEnvironmentConnection();
const dispatches: Array<Promise<ServerProviderUpdatedPayload>> = [
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,