Skip to content

Commit 88824e1

Browse files
committed
fix(web): offer retry while an environment is reconnecting
The chat banner hid its reconnect action during backoff, and Connections showed the wait with nothing to press. Retry now calls the existing reconnect action so a recovered server does not sit unread.
1 parent d18352e commit 88824e1

4 files changed

Lines changed: 93 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ import {
360360
import { type ReviewCommentContext } from "../reviewCommentContext";
361361
import { environmentCatalog } from "../connection/catalog";
362362
import { ConnectionDiagnosisHeadline } from "./settings/ConnectionDiagnosisDetails";
363+
import { environmentReconnectActionLabel } from "../connection/environmentReconnectAction";
363364
import { isDesktopLocalConnectionTarget } from "../connection/desktopLocal";
364365
import { useEnvironmentDisconnectDelay } from "../hooks/useEnvironmentDisconnectDelay";
365366
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
@@ -2343,6 +2344,10 @@ export default function ChatView(props: ChatViewProps) {
23432344
unavailableConnection !== null &&
23442345
(unavailableConnection.phase === "connecting" ||
23452346
unavailableConnection.phase === "reconnecting");
2347+
const reconnectActionLabel =
2348+
unavailableConnection === null
2349+
? null
2350+
: environmentReconnectActionLabel(unavailableConnection.phase);
23462351
const suppressUnavailableBanner =
23472352
environmentReconnecting && (updateRunning || !reconnectWarningGraceElapsed);
23482353
if (activeEnvironmentUnavailableState && unavailableConnection && !suppressUnavailableBanner) {
@@ -2356,7 +2361,7 @@ export default function ChatView(props: ChatViewProps) {
23562361
) : undefined,
23572362
actions: (
23582363
<>
2359-
{!environmentReconnecting ? (
2364+
{reconnectActionLabel !== null ? (
23602365
<Button
23612366
size="xs"
23622367
variant="ghost"
@@ -2366,7 +2371,7 @@ export default function ChatView(props: ChatViewProps) {
23662371
)
23672372
}
23682373
>
2369-
Reconnect
2374+
{reconnectActionLabel}
23702375
</Button>
23712376
) : null}
23722377
{disconnectAction}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ import { RemoveT3ConnectEnvironmentDialog } from "../clerk/RemoveT3ConnectEnviro
170170
import { useCloudLinkController } from "~/cloud/useCloudLinkController";
171171
import { authEnvironment } from "~/state/auth";
172172
import { environmentCatalog } from "~/connection/catalog";
173+
import { environmentReconnectActionLabel } from "~/connection/environmentReconnectAction";
173174
import {
174175
connectPairing as connectPairingAtom,
175176
connectSshEnvironment as connectSshEnvironmentAtom,
@@ -1429,6 +1430,7 @@ type SavedBackendListRowProps = {
14291430
environment: EnvironmentPresentation;
14301431
removingEnvironmentId: EnvironmentId | null;
14311432
onSetEnabled: (environmentId: EnvironmentId, enabled: boolean) => void;
1433+
onRetry: (environmentId: EnvironmentId) => void;
14321434
onRemove: (environment: EnvironmentPresentation) => void;
14331435
onAddRoute: (environment: EnvironmentPresentation) => void;
14341436
};
@@ -1468,6 +1470,7 @@ function SavedBackendListRow({
14681470
environment,
14691471
removingEnvironmentId,
14701472
onSetEnabled,
1473+
onRetry,
14711474
onRemove,
14721475
onAddRoute,
14731476
}: SavedBackendListRowProps) {
@@ -1527,6 +1530,12 @@ function SavedBackendListRow({
15271530
const resumingServerUpdate =
15281531
serverUpdateState.status === "running" && serverUpdateState.stage === "resuming";
15291532
const status = savedBackendStatus(environment);
1533+
// Only the backoff wait gets a new control. Offline and failed connections
1534+
// keep the switch and their existing recovery.
1535+
const retryNowLabel =
1536+
environmentReconnectActionLabel(environment.connection.phase) === "Retry now"
1537+
? "Retry now"
1538+
: null;
15301539
const serverVersion = environment.serverConfig?.environment.serverVersion ?? null;
15311540
// Discovery empties its map on every refresh, so hold the last descriptor
15321541
// seen or the glyph would blink back to the generic one each time.
@@ -1736,6 +1745,16 @@ function SavedBackendListRow({
17361745
appearance="icon"
17371746
/>
17381747
) : null}
1748+
{retryNowLabel !== null ? (
1749+
<Button
1750+
size="xs"
1751+
variant="ghost"
1752+
disabled={isRemoving}
1753+
onClick={() => onRetry(environmentId)}
1754+
>
1755+
{retryNowLabel}
1756+
</Button>
1757+
) : null}
17391758
<Tooltip>
17401759
<TooltipTrigger
17411760
render={
@@ -2066,6 +2085,7 @@ export function ConnectionsSettings() {
20662085
const setEnvironmentEnabled = useAtomCommand(environmentCatalog.setEnabled, {
20672086
reportFailure: false,
20682087
});
2088+
const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, { reportFailure: false });
20692089
const primaryEnvironmentId = primaryEnvironment?.environmentId ?? null;
20702090
const primarySessionState = usePrimarySessionState();
20712091
const currentSessionScopes = primarySessionState.data?.authenticated
@@ -2687,6 +2707,20 @@ export function ConnectionsSettings() {
26872707
}
26882708
};
26892709

2710+
const handleRetrySavedBackend = async (environmentId: EnvironmentId) => {
2711+
const result = await retryEnvironment(environmentId);
2712+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2713+
const error = squashAtomCommandFailure(result);
2714+
toastManager.add(
2715+
stackedThreadToast({
2716+
type: "error",
2717+
title: "Could not reconnect environment",
2718+
description: error instanceof Error ? error.message : "Failed to reconnect.",
2719+
}),
2720+
);
2721+
}
2722+
};
2723+
26902724
const handleSetSavedBackendEnabled = async (environmentId: EnvironmentId, enabled: boolean) => {
26912725
setSavedBackendError(null);
26922726
const result = await setEnvironmentEnabled({ environmentId, enabled });
@@ -3973,6 +4007,7 @@ export function ConnectionsSettings() {
39734007
environment={environment}
39744008
removingEnvironmentId={removingSavedEnvironmentId}
39754009
onSetEnabled={handleSetSavedBackendEnabled}
4010+
onRetry={(environmentId) => void handleRetrySavedBackend(environmentId)}
39764011
onRemove={handleRemoveSavedBackend}
39774012
onAddRoute={(target) => {
39784013
setRouteTarget(target);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { environmentReconnectActionLabel } from "./environmentReconnectAction";
4+
5+
describe("environmentReconnectActionLabel", () => {
6+
it("offers Retry now while an environment is waiting to reconnect", () => {
7+
expect(environmentReconnectActionLabel("reconnecting")).toBe("Retry now");
8+
});
9+
10+
it("leaves the first connecting attempt alone", () => {
11+
expect(environmentReconnectActionLabel("connecting")).toBeNull();
12+
});
13+
14+
it("keeps Reconnect for unavailable phases that are not already retrying", () => {
15+
expect(environmentReconnectActionLabel("offline")).toBe("Reconnect");
16+
expect(environmentReconnectActionLabel("error")).toBe("Reconnect");
17+
expect(environmentReconnectActionLabel("available")).toBe("Reconnect");
18+
expect(environmentReconnectActionLabel("unsupported")).toBe("Reconnect");
19+
});
20+
21+
it("offers nothing once the environment is connected", () => {
22+
expect(environmentReconnectActionLabel("connected")).toBeNull();
23+
});
24+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2+
3+
/**
4+
* Label for the explicit retry on an unavailable environment.
5+
*
6+
* Reconnecting is the backoff wait, which an explicit retry skips. The first
7+
* connecting attempt is already in flight, so it has no action. Every other
8+
* unavailable phase keeps the chat banner's existing Reconnect control.
9+
* Connections settings only renders the "Retry now" case; a failed connection
10+
* stays on its own recovery.
11+
*/
12+
export function environmentReconnectActionLabel(
13+
phase: EnvironmentConnectionPhase,
14+
): "Retry now" | "Reconnect" | null {
15+
switch (phase) {
16+
case "reconnecting":
17+
return "Retry now";
18+
case "connecting":
19+
case "connected":
20+
return null;
21+
case "available":
22+
case "offline":
23+
case "error":
24+
case "unsupported":
25+
return "Reconnect";
26+
}
27+
}

0 commit comments

Comments
 (0)