Skip to content

Commit e85e009

Browse files
t3dotggYuruzuuclaude
authored
fix(web): checking for updates finds provider updates on every machine (#33538)
Co-authored-by: Yuruzuu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Claude Code <[email protected]>
1 parent bf469bb commit e85e009

5 files changed

Lines changed: 120 additions & 14 deletions

File tree

‎apps/web/src/components/ProviderUpdatesAction.browser.test.tsx‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ProviderInstanceId,
88
type ServerProvider,
99
} from "@t3tools/contracts";
10+
import * as Cause from "effect/Cause";
1011
import { AsyncResult, Atom } from "effect/reactivity";
1112
import { useEffect } from "react";
1213
import { expect, it, vi } from "vite-plus/test";
@@ -21,6 +22,8 @@ const state = vi.hoisted(() => ({
2122
}[],
2223
providers: new Map<EnvironmentId, ReadonlyArray<ServerProvider>>(),
2324
requests: [] as EnvironmentId[],
25+
checks: [] as { environmentId: EnvironmentId; input: unknown }[],
26+
checkResult: null as AsyncResult.AsyncResult<unknown, unknown> | null,
2427
sessions: new Map<EnvironmentId, Atom.Writable<AsyncResult.AsyncResult<AuthSessionState>>>(),
2528
}));
2629

@@ -41,18 +44,23 @@ vi.mock(import("@t3tools/client-runtime/state/session"), async (original) => {
4144
};
4245
});
4346
vi.mock(import("~/state/server"), () => ({
44-
serverEnvironment: { updateProvider: {} } as never,
47+
serverEnvironment: { updateProvider: "update", refreshProviders: "refresh" } as never,
4548
}));
4649
vi.mock(import("~/state/use-atom-command"), () => ({
47-
useAtomCommand: (() =>
48-
async ({ environmentId }: { environmentId: EnvironmentId }) => {
49-
state.requests.push(environmentId);
50-
return AsyncResult.success(undefined);
50+
useAtomCommand: ((command: string) =>
51+
async ({ environmentId, input }: { environmentId: EnvironmentId; input: unknown }) => {
52+
if (command !== "refresh") {
53+
state.requests.push(environmentId);
54+
return AsyncResult.success(undefined);
55+
}
56+
state.checks.push({ environmentId, input });
57+
return state.checkResult ?? AsyncResult.success(undefined);
5158
}) as never,
5259
}));
5360

5461
import { appAtomRegistry } from "~/rpc/atomRegistry";
55-
import { useProviderUpdates } from "./ProviderUpdatesAction";
62+
import { toastManager } from "./ui/toast";
63+
import { useCheckProviderUpdates, useProviderUpdates } from "./ProviderUpdatesAction";
5664

5765
const provider: ServerProvider = {
5866
instanceId: ProviderInstanceId.make("codex"),
@@ -102,6 +110,8 @@ function setup() {
102110
state.environments.map(({ environmentId }) => [environmentId, [provider]]),
103111
);
104112
state.requests = [];
113+
state.checks = [];
114+
state.checkResult = null;
105115
const sessions = new Map<EnvironmentId, Atom.Writable<AsyncResult.AsyncResult<AuthSessionState>>>(
106116
[
107117
[state.environments[0]!.environmentId, Atom.make(session(["orchestration:read"]))],
@@ -118,14 +128,17 @@ function setup() {
118128
return { sessions };
119129
}
120130

121-
it("bulk provider updates exclude connections without a confirmed management grant", async () => {
131+
it("provider updates and checks exclude connections without a confirmed management grant", async () => {
122132
const fixture = setup();
123133
let updates!: ReturnType<typeof useProviderUpdates>;
134+
let check!: ReturnType<typeof useCheckProviderUpdates>;
124135
function Probe() {
125136
const nextUpdates = useProviderUpdates();
137+
const nextCheck = useCheckProviderUpdates();
126138
useEffect(() => {
127139
updates = nextUpdates;
128-
}, [nextUpdates]);
140+
check = nextCheck;
141+
}, [nextUpdates, nextCheck]);
129142
return null;
130143
}
131144
await using _screen = await render(
@@ -140,6 +153,29 @@ it("bulk provider updates exclude connections without a confirmed management gra
140153
await updates.updateAll({ quiet: true });
141154
});
142155
expect(state.requests).toEqual([writableId]);
156+
await act(async () => {
157+
await check();
158+
});
159+
// A model refresh always drops the server's cached latest provider versions.
160+
expect(state.checks).toEqual([{ environmentId: writableId, input: { refreshModels: true } }]);
161+
162+
using toast = vi.spyOn(toastManager, "add");
163+
state.checkResult = AsyncResult.failure(Cause.interrupt());
164+
await act(async () => {
165+
await check();
166+
});
167+
expect(toast).not.toHaveBeenCalled();
168+
state.checkResult = AsyncResult.failure(Cause.fail(new Error("offline")));
169+
await act(async () => {
170+
await check({ quiet: true });
171+
});
172+
expect(toast).not.toHaveBeenCalled();
173+
await act(async () => {
174+
await check();
175+
});
176+
expect(toast).toHaveBeenCalledWith(
177+
expect.objectContaining({ title: "Could not check provider updates" }),
178+
);
143179

144180
await act(() => {
145181
appAtomRegistry.set(fixture.sessions.get(writableId)!, session(["orchestration:read"]));

‎apps/web/src/components/ProviderUpdatesAction.tsx‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { AuthProvidersManageScope, PROVIDER_DISPLAY_NAMES } from "@t3tools/contracts";
2-
import { settlePromise } from "@t3tools/client-runtime/state/runtime";
2+
import {
3+
isAtomCommandInterrupted,
4+
settlePromise,
5+
squashAtomCommandFailure,
6+
} from "@t3tools/client-runtime/state/runtime";
37
import { useRef, useState } from "react";
48

59
import { useEnvironmentProviders, useEnvironments } from "~/state/environments";
@@ -16,6 +20,53 @@ import { Button } from "./ui/button";
1620
import { stackedThreadToast, toastManager } from "./ui/toast";
1721
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
1822

23+
// `refreshModels` always drops the server's hour-long latest-version cache. `modelCatalogOnly`
24+
// drops it only when the model manifest changed.
25+
export function useCheckProviderUpdates() {
26+
const { environments } = useEnvironments();
27+
const manageableIds = useEnvironmentsWithScope(environments, AuthProvidersManageScope);
28+
const refreshProviders = useAtomCommand(serverEnvironment.refreshProviders, {
29+
reportFailure: false,
30+
});
31+
const inFlight = useRef<Promise<void> | null>(null);
32+
33+
const check = async (quiet: boolean) => {
34+
const failures = await Promise.all(
35+
environments
36+
.filter(
37+
(environment) =>
38+
environment.connection.phase === "connected" &&
39+
manageableIds.has(environment.environmentId),
40+
)
41+
.map(async ({ environmentId, label }) => {
42+
const result = await refreshProviders({ environmentId, input: { refreshModels: true } });
43+
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return [];
44+
const error = squashAtomCommandFailure(result);
45+
return [`${label}: ${error instanceof Error ? error.message : "Refresh failed."}`];
46+
}),
47+
);
48+
const lines = failures.flat();
49+
if (quiet || lines.length === 0) return;
50+
toastManager.add(
51+
stackedThreadToast({
52+
type: "error",
53+
title: "Could not check provider updates",
54+
description: <span className="whitespace-pre-line">{lines.join("\n")}</span>,
55+
}),
56+
);
57+
};
58+
59+
// A repeat click must not start a second model rediscovery while one is running.
60+
return ({ quiet = false }: { readonly quiet?: boolean } = {}) => {
61+
if (inFlight.current) return inFlight.current;
62+
const running = check(quiet).finally(() => {
63+
inFlight.current = null;
64+
});
65+
inFlight.current = running;
66+
return running;
67+
};
68+
}
69+
1970
export function useProviderUpdates() {
2071
const { environments } = useEnvironments();
2172
const manageableIds = useEnvironmentsWithScope(environments, AuthProvidersManageScope);

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import { StorageCleanupSections } from "./StorageSettings";
110110
import { UpdateTrackSwitchDialog } from "./UpdateTrackSwitchDialog";
111111
import { environmentIdsKey } from "~/state/environmentAtomList";
112112
import { environmentSessionStatesAtom } from "~/state/session";
113+
import { useCheckProviderUpdates } from "../ProviderUpdatesAction";
113114
import { canUpdateServer } from "../ServerUpdateAction";
114115
import { useUpdateEverythingRun } from "../sidebar/updateEverythingRun";
115116
import { awaitsTrackSwitch, channelSwitchLabel } from "../sidebar/updateEverything.logic";
@@ -162,6 +163,7 @@ function AboutVersionSection() {
162163
);
163164
// A second run would replace the first run's progress and local download.
164165
const updateRun = useUpdateEverythingRun();
166+
const checkProviderUpdates = useCheckProviderUpdates();
165167

166168
const hasDesktopBridge = typeof window !== "undefined" && Boolean(window.desktopBridge);
167169
const selectedUpdateChannel = updateState?.channel ?? "latest";
@@ -252,6 +254,7 @@ function AboutVersionSection() {
252254
}
253255

254256
if (typeof bridge.checkForUpdate !== "function") return;
257+
void checkProviderUpdates();
255258
void bridge
256259
.checkForUpdate()
257260
.then((result) => {

‎apps/web/src/components/sidebar/SidebarUpdatePill.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
shouldToastDesktopUpdateActionResult,
2929
} from "../desktopUpdate.logic";
3030
import { showDesktopUpdateDownloadedToast } from "../desktopUpdate.toast";
31+
import { useCheckProviderUpdates } from "../ProviderUpdatesAction";
3132
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
3233
import { Popover, PopoverCreateHandle, PopoverPopup, PopoverTrigger } from "../ui/popover";
3334
import { SidebarMenuItem } from "../ui/sidebar";
@@ -200,6 +201,8 @@ function SidebarUpdateControl() {
200201
// The desktop updates this machine, whose policy the primary environment reports.
201202
const updatesDenial = managedUpdatesDenial(usePrimaryManagedPolicy());
202203
const [isActionPending, setIsActionPending] = useState(false);
204+
const [providerCheck, setProviderCheck] = useState<"button" | "dialog" | null>(null);
205+
const isCheckingProviders = providerCheck === "button";
203206
const [isConfirmingEverything, setIsConfirmingEverything] = useState(false);
204207
const [checkAnimationKey, setCheckAnimationKey] = useState(0);
205208
const [releaseNotesPopoverHandle] = useState(() => PopoverCreateHandle());
@@ -230,12 +233,13 @@ function SidebarUpdateControl() {
230233
const localUpdateVersion =
231234
state && action !== "none" ? getDesktopUpdateDownloadedVersion(state) : null;
232235
const everything = useUpdateEverything(localUpdateVersion);
236+
const checkProviderUpdates = useCheckProviderUpdates();
233237
const runsEverything = everything.hasUpdates && !isDownloading;
234238
const run = useUpdateEverythingRun();
235239
const isRunningEverything = run !== null;
236240
const showCheckIcon = shouldShowDesktopUpdateCheckIcon({
237241
isAnimationLatched: isCheckAnimationLatched,
238-
isChecking: state?.status === "checking",
242+
isChecking: state?.status === "checking" || isCheckingProviders,
239243
prefersReducedMotion,
240244
});
241245
const { iconStatus, showUpdateDetails, showUpdateIconState } = resolveSidebarUpdatePresentation({
@@ -283,6 +287,9 @@ function SidebarUpdateControl() {
283287

284288
if (runsEverything) {
285289
setIsConfirmingEverything(true);
290+
// Machines that still cache an older latest version add their rows while the dialog is open.
291+
setProviderCheck("dialog");
292+
void checkProviderUpdates({ quiet: true }).finally(() => setProviderCheck(null));
286293
return;
287294
}
288295

@@ -325,7 +332,7 @@ function SidebarUpdateControl() {
325332
setIsCheckAnimationLatched(true);
326333
setCheckAnimationKey((key) => key + 1);
327334
}
328-
void bridge
335+
const appCheck = bridge
329336
.checkForUpdate()
330337
.then((result) => {
331338
if (result.checked) return;
@@ -348,8 +355,10 @@ function SidebarUpdateControl() {
348355
description: error instanceof Error ? error.message : "Update check failed.",
349356
}),
350357
);
351-
})
352-
.finally(() => setIsActionPending(false));
358+
});
359+
setProviderCheck("button");
360+
const providersChecked = checkProviderUpdates().finally(() => setProviderCheck(null));
361+
void Promise.allSettled([appCheck, providersChecked]).then(() => setIsActionPending(false));
353362
};
354363

355364
const runEverything = async () => {
@@ -385,7 +394,7 @@ function SidebarUpdateControl() {
385394
const handleCheckAnimationIteration = () => {
386395
setIsCheckAnimationLatched(
387396
shouldContinueDesktopUpdateCheckAnimation({
388-
isChecking: state?.status === "checking",
397+
isChecking: state?.status === "checking" || isCheckingProviders,
389398
prefersReducedMotion,
390399
}),
391400
);
@@ -410,6 +419,7 @@ function SidebarUpdateControl() {
410419
providerCount={everything.providerCount}
411420
rows={everything.rows}
412421
restarts={everything.restarts}
422+
checking={providerCheck === "dialog"}
413423
onConfirm={() => void runEverything()}
414424
/>
415425
);

‎apps/web/src/components/sidebar/UpdateEverythingDialog.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ interface UpdateEverythingDialogProps {
5555
readonly disabledReason?: string | null;
5656
/** The confirmed work is starting; it cannot be cancelled from here. */
5757
readonly busy?: boolean;
58+
/** Machines are still looking for provider updates, so more rows can appear. */
59+
readonly checking?: boolean;
5860
}
5961

6062
type UpdateEverythingDialogContentProps = Omit<
@@ -102,6 +104,7 @@ function UpdateEverythingDialogContent({
102104
notes = [],
103105
disabledReason = null,
104106
busy = false,
107+
checking = false,
105108
}: UpdateEverythingDialogContentProps) {
106109
const stopped = useAtomValue(
107110
runningThreadCountAtom(
@@ -141,6 +144,9 @@ function UpdateEverythingDialogContent({
141144
{providerCount > 0
142145
? `${providerCount} provider ${providerCount === 1 ? "update" : "updates"}`
143146
: null}
147+
{checking
148+
? `${version !== null || providerCount > 0 ? " · " : ""}Checking for more…`
149+
: null}
144150
</AlertDialogDescription>
145151
</AlertDialogHeader>
146152
<ScrollArea scrollFade>

0 commit comments

Comments
 (0)