Skip to content

Commit 79e392c

Browse files
fix(web): SSH environments on an older reused remote server explain the version mismatch instead of reconnecting forever (pingdotgg#23647)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent d31269e commit 79e392c

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎apps/desktop/src/ipc/methods/sshEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class DesktopSshEnvironmentRequestError extends Data.TaggedError(
8383
readonly cause: DesktopSshEnvironmentRequestCause;
8484
readonly sshHttpStatus: number | null;
8585
}> {
86+
// The web client matches "[ssh_http:500]" to explain version-skewed SSH pairing.
8687
override get message() {
8788
const prefix = this.sshHttpStatus === null ? "" : `[ssh_http:${this.sshHttpStatus}] `;
8889
return `${prefix}SSH remote API request failed during ${this.operation}.`;

‎apps/web/src/connection/platform.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
provisionDesktopSshEnvironment,
2929
secondaryRegistrationsToRetainAfterTopologyRead,
3030
} from "./platform.ts";
31+
import { APP_VERSION } from "../branding.ts";
3132

3233
const TARGET: DesktopSshEnvironmentTarget = {
3334
alias: "devbox",
@@ -224,6 +225,41 @@ describe("desktop SSH pairing", () => {
224225
}),
225226
);
226227

228+
const failPairing = (serverVersion: string, message: string) => {
229+
const bridge = makeBridge([]);
230+
const fetchDescriptor = bridge.fetchSshEnvironmentDescriptor;
231+
vi.spyOn(bridge, "fetchSshEnvironmentDescriptor").mockImplementation(async (url) => ({
232+
...(await fetchDescriptor(url)),
233+
serverVersion,
234+
}));
235+
vi.spyOn(bridge, "bootstrapSshBearerSession").mockRejectedValue(new Error(message));
236+
return provisionDesktopSshEnvironment(bridge, TARGET).pipe(Effect.flip);
237+
};
238+
const PAIRING_500 =
239+
"[ssh_http:500] SSH remote API request failed during bootstrap-bearer-session.";
240+
241+
it.effect("blocks with both versions when a server on another build rejects pairing", () =>
242+
Effect.gen(function* () {
243+
const error = yield* failPairing("0.0.46-nightly.20261004.2652", PAIRING_500);
244+
245+
expect(error).toBeInstanceOf(ConnectionBlockedError);
246+
expect(error.detail).toContain("0.0.46-nightly.20261004.2652");
247+
expect(error.detail).toContain(APP_VERSION);
248+
}),
249+
);
250+
251+
it.effect("keeps retrying pairing failures that are not a version mismatch", () =>
252+
Effect.gen(function* () {
253+
expect(yield* failPairing(APP_VERSION, PAIRING_500)).toBeInstanceOf(ConnectionTransientError);
254+
expect(
255+
yield* failPairing(
256+
"0.0.46-nightly.20261004.2652",
257+
"SSH remote API request failed during bootstrap-bearer-session.",
258+
),
259+
).toBeInstanceOf(ConnectionTransientError);
260+
}),
261+
);
262+
227263
it.effect("reconnects with the saved token while it holds every standard scope", () =>
228264
Effect.gen(function* () {
229265
const calls: string[] = [];

‎apps/web/src/connection/platform.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,22 @@ export const provisionDesktopSshEnvironment = Effect.fn(
238238
}
239239
const access = yield* Effect.tryPromise({
240240
try: () => bridge.bootstrapSshBearerSession(bootstrap.httpBaseUrl, pairingToken),
241-
catch: sshPreparationError,
241+
catch: (cause) => {
242+
const error = sshPreparationError(cause);
243+
// A reused remote server on another build can fail to decode the grant
244+
// the desktop's runner just minted, and answers 500 on every retry.
245+
if (
246+
error._tag === "ConnectionBlockedError" ||
247+
descriptor.serverVersion === APP_VERSION ||
248+
!error.detail.includes("[ssh_http:500]")
249+
) {
250+
return error;
251+
}
252+
return new ConnectionBlockedError({
253+
reason: "configuration",
254+
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.`,
255+
});
256+
},
242257
});
243258
return {
244259
environmentId: descriptor.environmentId,

0 commit comments

Comments
 (0)