fix(web): surface secondary backend update failures instead of reporting success
The provider-update fan-out dispatches to the primary and every connected desktopLocal backend, but completion handling only inspected promise rejections and the primary's instance ids. A secondary backend (e.g. WSL) whose updateProvider resolved with a failed or unchanged provider in its payload was silently dropped, so the launch toast and settings flow could report success while the WSL copy stayed outdated. - updateProviderAcrossLocalEnvironments now resolves each dispatch to a normalized outcome carrying the matched provider snapshot (with its terminal updateState) plus isPrimary / environment metadata. - The launch toast aggregates outcomes across backends to the worst-case status per driver, and gates the primary-only serverState effect behind an awaitingSettlement flag so it cannot finalize success before every dispatched update settles. - The settings flow surfaces a secondary backend's failed/unchanged result via a toast; the primary's own result is already shown inline.
This commit is contained in:
1 parent
76bd75b9f0
commit
50869788e4
5 files changed
+316
-17
No files matched your search
@@ -1,11 +1,14 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
|
||||
|
||||
import type { LocalProviderUpdateOutcome } from "../environmentApi";
|
||||
import {
|
||||
canOneClickUpdateProviderCandidate,
|
||||
collectProviderUpdateCandidates,
|
||||
collectProviderUpdateOutcomeSnapshots,
|
||||
collectUpdatedProviderSnapshots,
|
||||
firstRejectedProviderUpdateMessage,
|
||||
firstUnsuccessfulSecondaryProviderOutcome,
|
||||
getProviderUpdateInitialToastView,
|
||||
getProviderUpdateProgressToastView,
|
||||
getProviderUpdateRejectedToastView,
|
||||
@@ -670,4 +673,164 @@ describe("provider update launch notification logic", () => {
|
||||
]),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
describe("multi-backend update outcomes", () => {
|
||||
const terminalState = (
|
||||
status: "succeeded" | "failed" | "unchanged",
|
||||
message: string,
|
||||
): NonNullable<ServerProvider["updateState"]> => ({
|
||||
status,
|
||||
startedAt: checkedAt,
|
||||
finishedAt: checkedAt,
|
||||
message,
|
||||
output: null,
|
||||
});
|
||||
|
||||
const fulfilledOutcome = (
|
||||
isPrimary: boolean,
|
||||
snapshot: ServerProvider | null,
|
||||
environment = "env",
|
||||
): PromiseSettledResult<LocalProviderUpdateOutcome> => ({
|
||||
status: "fulfilled",
|
||||
value: {
|
||||
environmentId: environment as LocalProviderUpdateOutcome["environmentId"],
|
||||
isPrimary,
|
||||
driver: snapshot?.driver ?? driver("codex"),
|
||||
instanceId: snapshot?.instanceId ?? instanceId("codex"),
|
||||
provider: snapshot,
|
||||
},
|
||||
});
|
||||
|
||||
it("surfaces a secondary backend's failed update over the primary's success", () => {
|
||||
const snapshots = collectProviderUpdateOutcomeSnapshots([
|
||||
fulfilledOutcome(
|
||||
true,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "Provider updated."),
|
||||
}),
|
||||
),
|
||||
fulfilledOutcome(
|
||||
false,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("failed", "npm: NotFound"),
|
||||
}),
|
||||
),
|
||||
]);
|
||||
|
||||
expect(snapshots).toHaveLength(1);
|
||||
expect(snapshots[0]?.updateState?.status).toBe("failed");
|
||||
expect(
|
||||
getProviderUpdateProgressToastView({ providers: snapshots, providerCount: 1 }),
|
||||
).toMatchObject({ phase: "failed" });
|
||||
});
|
||||
|
||||
it("surfaces a secondary backend that stayed outdated over the primary's success", () => {
|
||||
const snapshots = collectProviderUpdateOutcomeSnapshots([
|
||||
fulfilledOutcome(
|
||||
true,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "Provider updated."),
|
||||
}),
|
||||
),
|
||||
fulfilledOutcome(
|
||||
false,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("unchanged", "still outdated"),
|
||||
}),
|
||||
),
|
||||
]);
|
||||
|
||||
expect(snapshots[0]?.updateState?.status).toBe("unchanged");
|
||||
expect(
|
||||
getProviderUpdateProgressToastView({ providers: snapshots, providerCount: 1 }),
|
||||
).toMatchObject({ phase: "unchanged" });
|
||||
});
|
||||
|
||||
it("reports success only when every backend succeeded", () => {
|
||||
const snapshots = collectProviderUpdateOutcomeSnapshots([
|
||||
fulfilledOutcome(
|
||||
true,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "Provider updated."),
|
||||
}),
|
||||
),
|
||||
fulfilledOutcome(
|
||||
false,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "Provider updated."),
|
||||
}),
|
||||
),
|
||||
]);
|
||||
|
||||
expect(
|
||||
getProviderUpdateProgressToastView({ providers: snapshots, providerCount: 1 }),
|
||||
).toMatchObject({ phase: "succeeded" });
|
||||
});
|
||||
|
||||
it("ignores backends that did not return the targeted instance", () => {
|
||||
const primary = provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "Provider updated."),
|
||||
});
|
||||
const snapshots = collectProviderUpdateOutcomeSnapshots([
|
||||
fulfilledOutcome(true, primary),
|
||||
fulfilledOutcome(false, null),
|
||||
]);
|
||||
|
||||
expect(snapshots).toEqual([primary]);
|
||||
});
|
||||
|
||||
it("flags the first unsuccessful secondary outcome, skipping the primary and successes", () => {
|
||||
const primaryFailed = provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("failed", "primary boom"),
|
||||
});
|
||||
|
||||
expect(
|
||||
firstUnsuccessfulSecondaryProviderOutcome([
|
||||
fulfilledOutcome(true, primaryFailed),
|
||||
fulfilledOutcome(
|
||||
false,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "ok"),
|
||||
}),
|
||||
),
|
||||
]),
|
||||
).toBeNull();
|
||||
|
||||
expect(
|
||||
firstUnsuccessfulSecondaryProviderOutcome([
|
||||
fulfilledOutcome(true, primaryFailed),
|
||||
fulfilledOutcome(
|
||||
false,
|
||||
provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("failed", "wsl boom"),
|
||||
}),
|
||||
),
|
||||
]),
|
||||
).toMatchObject({ status: "failed", provider: { updateState: { message: "wsl boom" } } });
|
||||
});
|
||||
|
||||
it("treats a rejected dispatch as not contributing a snapshot", () => {
|
||||
const primary = provider({
|
||||
driver: driver("codex"),
|
||||
updateState: terminalState("succeeded", "Provider updated."),
|
||||
});
|
||||
const results: PromiseSettledResult<LocalProviderUpdateOutcome>[] = [
|
||||
fulfilledOutcome(true, primary),
|
||||
{ status: "rejected", reason: new Error("WebSocket closed") },
|
||||
];
|
||||
|
||||
expect(collectProviderUpdateOutcomeSnapshots(results)).toEqual([primary]);
|
||||
expect(firstRejectedProviderUpdateMessage(results)).toBe("WebSocket closed");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
type ServerProvider,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import type { LocalProviderUpdateOutcome } from "../environmentApi";
|
||||
|
||||
export type ProviderUpdateCandidate = ServerProvider & {
|
||||
readonly versionAdvisory: NonNullable<ServerProvider["versionAdvisory"]> & {
|
||||
readonly status: "behind_latest";
|
||||
@@ -358,6 +360,73 @@ export function firstRejectedProviderUpdateMessage(
|
||||
return rejected.reason instanceof Error ? rejected.reason.message : "Provider update failed.";
|
||||
}
|
||||
|
||||
// Worst-case ordering across backends: a failed copy outranks an unchanged one,
|
||||
// which outranks a still-running one, which outranks a succeeded one.
|
||||
const PROVIDER_UPDATE_STATUS_SEVERITY: Record<string, number> = {
|
||||
succeeded: 1,
|
||||
queued: 2,
|
||||
running: 2,
|
||||
unchanged: 3,
|
||||
failed: 4,
|
||||
};
|
||||
|
||||
function providerUpdateOutcomeSeverity(provider: ServerProvider): number {
|
||||
return PROVIDER_UPDATE_STATUS_SEVERITY[provider.updateState?.status ?? ""] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce per-backend update outcomes to one representative snapshot per driver,
|
||||
* keeping the worst-case status across every local backend. Because the same
|
||||
* driver has a distinct instance id per environment, a secondary backend (e.g.
|
||||
* WSL) that *resolved* with a failed or unchanged provider would otherwise be
|
||||
* filtered out (its instance id is not the primary's) or collapsed behind the
|
||||
* primary's success — this surfaces it instead.
|
||||
*/
|
||||
export function collectProviderUpdateOutcomeSnapshots(
|
||||
results: ReadonlyArray<PromiseSettledResult<LocalProviderUpdateOutcome>>,
|
||||
): ServerProvider[] {
|
||||
const worstByDriver = new Map<ProviderDriverKind, ServerProvider>();
|
||||
for (const result of results) {
|
||||
if (result.status !== "fulfilled" || result.value.provider === null) {
|
||||
continue;
|
||||
}
|
||||
const provider = result.value.provider;
|
||||
const current = worstByDriver.get(provider.driver);
|
||||
if (
|
||||
!current ||
|
||||
providerUpdateOutcomeSeverity(provider) > providerUpdateOutcomeSeverity(current)
|
||||
) {
|
||||
worstByDriver.set(provider.driver, provider);
|
||||
}
|
||||
}
|
||||
return [...worstByDriver.values()];
|
||||
}
|
||||
|
||||
/**
|
||||
* The first secondary (non-primary) backend whose update resolved without
|
||||
* succeeding. The primary's own failed/unchanged state is already surfaced
|
||||
* inline in settings, so only secondaries (which have no inline row) need an
|
||||
* explicit callout.
|
||||
*/
|
||||
export function firstUnsuccessfulSecondaryProviderOutcome(
|
||||
results: ReadonlyArray<PromiseSettledResult<LocalProviderUpdateOutcome>>,
|
||||
): { readonly provider: ServerProvider; readonly status: "failed" | "unchanged" } | null {
|
||||
for (const result of results) {
|
||||
if (result.status !== "fulfilled") {
|
||||
continue;
|
||||
}
|
||||
const outcome = result.value;
|
||||
if (outcome.isPrimary || outcome.provider === null) {
|
||||
continue;
|
||||
}
|
||||
const status = outcome.provider.updateState?.status;
|
||||
if (status === "failed" || status === "unchanged") {
|
||||
return { provider: outcome.provider, status };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getUpdateFinishedAt(provider: ServerProvider): string | null {
|
||||
return provider.updateState?.finishedAt ?? null;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { PROVIDER_ICON_BY_PROVIDER } from "./chat/providerIconUtils";
|
||||
import {
|
||||
canOneClickUpdateProviderCandidate,
|
||||
collectProviderUpdateCandidates,
|
||||
collectUpdatedProviderSnapshots,
|
||||
collectProviderUpdateOutcomeSnapshots,
|
||||
firstRejectedProviderUpdateMessage,
|
||||
getProviderUpdateInitialToastView,
|
||||
getProviderUpdateProgressToastView,
|
||||
@@ -32,6 +32,10 @@ type ActiveProviderUpdateToast =
|
||||
readonly toastId: ProviderUpdateToastId;
|
||||
readonly providerInstanceIds: ReadonlySet<ProviderInstanceId>;
|
||||
readonly providerCount: number;
|
||||
// True until every dispatched backend update settles. While true the
|
||||
// primary-only serverState effect must not finalize the toast, since it
|
||||
// cannot observe a secondary (e.g. WSL) backend's outcome.
|
||||
readonly awaitingSettlement: boolean;
|
||||
};
|
||||
|
||||
function ProviderUpdateToastIcon({ provider }: { provider: ProviderDriverKind }) {
|
||||
@@ -139,6 +143,14 @@ export function ProviderUpdateLaunchNotification() {
|
||||
return;
|
||||
}
|
||||
|
||||
// The dispatched updates have not all settled yet. This effect only sees the
|
||||
// primary backend's serverState, so it cannot tell whether a secondary (e.g.
|
||||
// WSL) backend succeeded — leave the running toast in place and let the
|
||||
// settled-promise handler report the aggregate outcome.
|
||||
if (activeToast.awaitingSettlement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeProviders = providers.filter((provider) =>
|
||||
activeToast.providerInstanceIds.has(provider.instanceId),
|
||||
);
|
||||
@@ -198,6 +210,7 @@ export function ProviderUpdateLaunchNotification() {
|
||||
toastId,
|
||||
providerInstanceIds,
|
||||
providerCount,
|
||||
awaitingSettlement: true,
|
||||
};
|
||||
|
||||
updateProviderUpdateToast({
|
||||
@@ -216,6 +229,9 @@ export function ProviderUpdateLaunchNotification() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Every backend has settled — release the live serverState effect.
|
||||
activeToastRef.current = { ...activeUpdateToast, awaitingSettlement: false };
|
||||
|
||||
const rejectedMessage = firstRejectedProviderUpdateMessage(results);
|
||||
if (rejectedMessage) {
|
||||
updateProviderUpdateToast({
|
||||
@@ -227,10 +243,7 @@ export function ProviderUpdateLaunchNotification() {
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedProviderSnapshots = collectUpdatedProviderSnapshots({
|
||||
results,
|
||||
providerInstanceIds,
|
||||
});
|
||||
const updatedProviderSnapshots = collectProviderUpdateOutcomeSnapshots(results);
|
||||
const view = getProviderUpdateProgressToastView({
|
||||
providers: updatedProviderSnapshots,
|
||||
providerCount,
|
||||
|
||||
@@ -61,6 +61,7 @@ import { AddProviderInstanceDialog } from "./AddProviderInstanceDialog";
|
||||
import {
|
||||
canOneClickUpdateProviderCandidate,
|
||||
collectProviderUpdateCandidates,
|
||||
firstUnsuccessfulSecondaryProviderOutcome,
|
||||
hasOneClickUpdateProviderCandidate,
|
||||
isProviderUpdateActive,
|
||||
type ProviderUpdateCandidate,
|
||||
@@ -993,6 +994,26 @@ export function ProviderSettingsPanel() {
|
||||
if (rejected?.status === "rejected") {
|
||||
throw rejected.reason;
|
||||
}
|
||||
// The primary's own outcome is reflected inline (its row refreshes from
|
||||
// serverState), but a secondary backend (e.g. WSL) has no inline row, so a
|
||||
// copy that resolved as failed or still-outdated would otherwise look like
|
||||
// a success. Surface it explicitly.
|
||||
const secondaryIssue = firstUnsuccessfulSecondaryProviderOutcome(results);
|
||||
if (secondaryIssue) {
|
||||
const providerName = PROVIDER_DISPLAY_NAMES[candidate.driver] ?? candidate.driver;
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: secondaryIssue.status === "failed" ? "error" : "warning",
|
||||
title:
|
||||
secondaryIssue.status === "failed"
|
||||
? `Could not update ${providerName} in a connected environment`
|
||||
: `${providerName} still needs an update in a connected environment`,
|
||||
description:
|
||||
secondaryIssue.provider.updateState?.message ??
|
||||
"The update did not complete in a connected environment. Check provider settings for details.",
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
|
||||
@@ -3,10 +3,10 @@ import type {
|
||||
EnvironmentApi,
|
||||
ProviderDriverKind,
|
||||
ProviderInstanceId,
|
||||
ServerProviderUpdatedPayload,
|
||||
ServerProvider,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import type { WsRpcClient } from "@t3tools/client-runtime";
|
||||
import type { EnvironmentConnection, WsRpcClient } from "@t3tools/client-runtime";
|
||||
import {
|
||||
getPrimaryEnvironmentConnection,
|
||||
getSavedEnvironmentRuntimeState,
|
||||
@@ -98,22 +98,57 @@ export function ensureEnvironmentApi(environmentId: EnvironmentId): EnvironmentA
|
||||
return api;
|
||||
}
|
||||
|
||||
/**
|
||||
* The settled result of dispatching a provider update to a single local
|
||||
* backend. `provider` is the matching snapshot from that backend's update
|
||||
* payload, carrying its terminal `updateState` (succeeded / unchanged /
|
||||
* failed) — `null` only if the backend did not return the targeted instance.
|
||||
* Callers use this to detect a secondary backend that *resolved* with a failed
|
||||
* or unchanged provider, which a bare promise (rejection-only) would miss.
|
||||
*/
|
||||
export interface LocalProviderUpdateOutcome {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly isPrimary: boolean;
|
||||
readonly driver: ProviderDriverKind;
|
||||
readonly instanceId: ProviderInstanceId;
|
||||
readonly provider: ServerProvider | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* return one in-flight outcome per environment so callers can aggregate results
|
||||
* across backends. 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>> {
|
||||
): ReadonlyArray<Promise<LocalProviderUpdateOutcome>> {
|
||||
const primary = getPrimaryEnvironmentConnection();
|
||||
const dispatches: Array<Promise<ServerProviderUpdatedPayload>> = [
|
||||
primary.client.server.updateProvider({ provider: driver, instanceId: primaryInstanceId }),
|
||||
|
||||
const dispatch = (
|
||||
connection: EnvironmentConnection,
|
||||
instanceId: ProviderInstanceId,
|
||||
isPrimary: boolean,
|
||||
): Promise<LocalProviderUpdateOutcome> =>
|
||||
connection.client.server
|
||||
.updateProvider({ provider: driver, instanceId })
|
||||
.then((payload) => ({
|
||||
environmentId: connection.environmentId,
|
||||
isPrimary,
|
||||
driver,
|
||||
instanceId,
|
||||
provider:
|
||||
payload.providers.find(
|
||||
(candidate) => candidate.driver === driver && candidate.instanceId === instanceId,
|
||||
) ?? null,
|
||||
}));
|
||||
|
||||
const dispatches: Array<Promise<LocalProviderUpdateOutcome>> = [
|
||||
dispatch(primary, primaryInstanceId, true),
|
||||
];
|
||||
|
||||
for (const record of listSavedEnvironmentRecords()) {
|
||||
@@ -131,9 +166,7 @@ export function updateProviderAcrossLocalEnvironments(
|
||||
if (!match) {
|
||||
continue; // provider not configured in this environment
|
||||
}
|
||||
dispatches.push(
|
||||
connection.client.server.updateProvider({ provider: driver, instanceId: match.instanceId }),
|
||||
);
|
||||
dispatches.push(dispatch(connection, match.instanceId, false));
|
||||
}
|
||||
|
||||
return dispatches;
|
||||
|
||||
Reference in new issue
Block a user