The best way to control Claude Code, Codex and more from any computer or phone
fix(ssh): SSH environments connect over links with about a second of round trip (#35418)
Julius Marminge committed
Nov 12, 2026 at 10:01 UTC
c58450f2cf11d1cee712967d36183b8f9fcc255d
2 files changed
+52
-1
packages/ssh/src/tunnel.test.ts
+49
@@ -527,6 +527,55 @@ describe("ssh tunnel scripts", () => {
527
}),
528
);
529
530
+ it.effect("connects through a tunnel whose responses take longer than a second", () =>
531
+ Effect.gen(function* () {
532
+ // Over a ~1s RTT link each request through the forward takes a few round trips.
533
+ const RESPONSE_MS = 2_500;
534
+ const tunnelSpawned = yield* Deferred.make<void>();
535
+ const spawner = ChildProcessSpawner.make((command) =>
536
+ commandArgs(command).includes("-N")
537
+ ? Deferred.succeed(tunnelSpawned, undefined).pipe(
538
+ Effect.as(makeRunningProcess(() => undefined)),
539
+ )
540
+ : Effect.succeed(makeSuccessfulProcess('{"remotePort":3773}\n')),
541
+ );
542
+ const httpClient = HttpClient.make((request) =>
543
+ Effect.sleep(Duration.millis(RESPONSE_MS)).pipe(
544
+ Effect.as(HttpClientResponse.fromWeb(request, new Response("", { status: 200 }))),
545
+ ),
546
+ );
547
+ const layer = Layer.mergeAll(
548
+ NodeServices.layer,
549
+ NodeCrypto.layer,
550
+ Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
551
+ Layer.succeed(HttpClient.HttpClient, httpClient),
552
+ Layer.succeed(NetService.NetService, testNetService),
553
+ SshAuth.SshPasswordPrompt.disabledLayer,
554
+ SshTunnel.SshEnvironmentManager.layer({ resolveCliRunner: Effect.succeed(ARCHIVE) }),
555
+ );
556
+ yield* Effect.gen(function* () {
557
+ const manager = yield* SshTunnel.SshEnvironmentManager;
558
+ const ensure = yield* Effect.forkChild(
559
+ Effect.result(
560
+ manager.ensureEnvironment({
561
+ alias: "devbox",
562
+ hostname: "devbox",
563
+ username: null,
564
+ port: null,
565
+ }),
566
+ ),
567
+ );
568
+ yield* Deferred.await(tunnelSpawned);
569
+ yield* TestClock.adjust(Duration.seconds(60));
570
+ const result = yield* Fiber.join(ensure);
571
+ assert.isTrue(
572
+ Result.isSuccess(result),
573
+ Result.isFailure(result) ? result.failure.message : undefined,
574
+ );
575
+ }).pipe(Effect.provide(layer), Effect.scoped);
576
+ }),
577
+ );
578
+
579
it.effect("reconnects a saved alias through the port its ssh config names now", () =>
580
Effect.gen(function* () {
581
let configPort = 53_791;
packages/ssh/src/tunnel.ts
+3
-1
@@ -51,6 +51,8 @@ const DEFAULT_REMOTE_PORT = 3773;
51
const REMOTE_PORT_SCAN_WINDOW = 200;
52
const SSH_READY_TIMEOUT_MS = 20_000;
53
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
54
+// Probes through the forward pay several link round trips, about 4s at a 1s RTT.
55
+const SSH_TUNNEL_READY_PROBE_TIMEOUT_MS = 5_000;
56
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
57
const TUNNEL_STDERR_TAIL_CHARS = 16_384;
58
const REMOTE_READY_TIMEOUT_MS = 60_000;
@@ -1159,7 +1161,7 @@ const waitForHttpReady = (input: {
1161
...(input.path === undefined ? {} : { path: input.path }),
1162
...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
1163
...(input.intervalMs === undefined ? {} : { intervalMs: input.intervalMs }),
1162
- probeTimeoutMs: input.probeTimeoutMs ?? SSH_READY_PROBE_TIMEOUT_MS,
1164
+ probeTimeoutMs: input.probeTimeoutMs ?? SSH_TUNNEL_READY_PROBE_TIMEOUT_MS,
1165
makeError: ({ requestUrl, probeTimeoutMs, cause }) => {
1166
if (typeof cause === "object" && cause !== null && "kind" in cause) {
1167
const kind = (cause as { readonly kind?: unknown }).kind;