Skip to content
TypeScript

fix(web): SSH environments on an older reused remote server explain the version mismatch instead of reconnecting forever (#23647)

Julius Marminge79e392cbfba9
diff --git a/apps/desktop/src/ipc/methods/sshEnvironment.ts b/apps/desktop/src/ipc/methods/sshEnvironment.ts
index e9535300104..099b97ce7bf 100644
--- a/apps/desktop/src/ipc/methods/sshEnvironment.ts
+++ b/apps/desktop/src/ipc/methods/sshEnvironment.ts
@@ -83,6 +83,7 @@ export class DesktopSshEnvironmentRequestError extends Data.TaggedError(
readonly cause: DesktopSshEnvironmentRequestCause;
readonly sshHttpStatus: number | null;
}> {
+ // The web client matches "[ssh_http:500]" to explain version-skewed SSH pairing.
override get message() {
const prefix = this.sshHttpStatus === null ? "" : `[ssh_http:${this.sshHttpStatus}] `;
return `${prefix}SSH remote API request failed during ${this.operation}.`;
diff --git a/apps/web/src/connection/platform.test.ts b/apps/web/src/connection/platform.test.ts
index 03870b488c2..eb6162a6318 100644
--- a/apps/web/src/connection/platform.test.ts
+++ b/apps/web/src/connection/platform.test.ts
@@ -28,6 +28,7 @@ import {
provisionDesktopSshEnvironment,
secondaryRegistrationsToRetainAfterTopologyRead,
} from "./platform.ts";
+import { APP_VERSION } from "../branding.ts";
const TARGET: DesktopSshEnvironmentTarget = {
alias: "devbox",
@@ -224,6 +225,41 @@ describe("desktop SSH pairing", () => {
}),
);
+ const failPairing = (serverVersion: string, message: string) => {
+ const bridge = makeBridge([]);
+ const fetchDescriptor = bridge.fetchSshEnvironmentDescriptor;
+ vi.spyOn(bridge, "fetchSshEnvironmentDescriptor").mockImplementation(async (url) => ({
+ ...(await fetchDescriptor(url)),
+ serverVersion,
+ }));
+ vi.spyOn(bridge, "bootstrapSshBearerSession").mockRejectedValue(new Error(message));
+ return provisionDesktopSshEnvironment(bridge, TARGET).pipe(Effect.flip);
+ };
+ const PAIRING_500 =
+ "[ssh_http:500] SSH remote API request failed during bootstrap-bearer-session.";
+
+ it.effect("blocks with both versions when a server on another build rejects pairing", () =>
+ Effect.gen(function* () {
+ const error = yield* failPairing("0.0.46-nightly.20261004.2652", PAIRING_500);
+
+ expect(error).toBeInstanceOf(ConnectionBlockedError);
+ expect(error.detail).toContain("0.0.46-nightly.20261004.2652");
+ expect(error.detail).toContain(APP_VERSION);
+ }),
+ );
+
+ it.effect("keeps retrying pairing failures that are not a version mismatch", () =>
+ Effect.gen(function* () {
+ expect(yield* failPairing(APP_VERSION, PAIRING_500)).toBeInstanceOf(ConnectionTransientError);
+ expect(
+ yield* failPairing(
+ "0.0.46-nightly.20261004.2652",
+ "SSH remote API request failed during bootstrap-bearer-session.",
+ ),
+ ).toBeInstanceOf(ConnectionTransientError);
+ }),
+ );
+
it.effect("reconnects with the saved token while it holds every standard scope", () =>
Effect.gen(function* () {
const calls: string[] = [];
diff --git a/apps/web/src/connection/platform.ts b/apps/web/src/connection/platform.ts
index 7b0490b6e10..aeb76f41659 100644
--- a/apps/web/src/connection/platform.ts
+++ b/apps/web/src/connection/platform.ts
@@ -238,7 +238,22 @@ export const provisionDesktopSshEnvironment = Effect.fn(
}
const access = yield* Effect.tryPromise({
try: () => bridge.bootstrapSshBearerSession(bootstrap.httpBaseUrl, pairingToken),
- catch: sshPreparationError,
+ catch: (cause) => {
+ const error = sshPreparationError(cause);
+ // A reused remote server on another build can fail to decode the grant
+ // the desktop's runner just minted, and answers 500 on every retry.
+ if (
+ error._tag === "ConnectionBlockedError" ||
+ descriptor.serverVersion === APP_VERSION ||
+ !error.detail.includes("[ssh_http:500]")
+ ) {
+ return error;
+ }
+ return new ConnectionBlockedError({
+ reason: "configuration",
+ detail: `${descriptor.label} runs T3 Code ${descriptor.serverVersion}, but this desktop is ${APP_VERSION}, and that server could not accept its pairing. Restart the T3 server on ${descriptor.label} so it runs ${APP_VERSION}, then retry.`,
+ });
+ },
});
return {
environmentId: descriptor.environmentId,