Skip to content

Commit e3e8dfb

Browse files
ScriptedAlchemydevin-ai-integration[bot]claude
authored
fix(ssh): reuse the desktop-installed CLI during remote setup (#47)
* fix(ssh): reuse the desktop-installed CLI during remote setup * fix(ssh): bound installed-CLI probes in the remote runner A wedged candidate stalled remote setup until the outer SSH timeout: a hung --version or __ssh-helper probe blocked forever, and an executable non-regular file (e.g. a FIFO) at a candidate path made the shell's read-as-script fallback block on open. Probe each candidate through a watchdog that falls through to the archive download, require a regular file, and route probe output through a temp file so orphaned children cannot hold the capture open. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(ssh): tighten the installed-CLI probe comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 94e1eca commit e3e8dfb

2 files changed

Lines changed: 80 additions & 19 deletions

File tree

‎packages/ssh/src/tunnel.test.ts‎

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,29 @@ function commandArgs(command: ChildProcess.Command): ReadonlyArray<string> {
8383
const ARCHIVE = { archiveVersion: "1.2.3-preview.20260911.4" } as const;
8484

8585
const runArchiveRunner = Effect.fn("test.runArchiveRunner")(
86-
function* (installedVersion: string) {
86+
function* (
87+
installedVersion: string,
88+
installDirectory = ".local/bin",
89+
options?: { readonly cliScript?: string; readonly fifo?: boolean },
90+
) {
8791
const fs = yield* FileSystem.FileSystem;
8892
const root = yield* fs.makeTempDirectoryScoped();
89-
yield* fs.makeDirectory(`${root}/.local/bin`, { recursive: true });
93+
yield* fs.makeDirectory(`${root}/${installDirectory}`, { recursive: true });
9094
yield* fs.makeDirectory(`${root}/bin`);
91-
yield* fs.writeFileString(
92-
`${root}/.local/bin/t3`,
93-
`#!/bin/sh\ncase "$1" in\n--version) echo 't3 v${installedVersion}';;\n__ssh-helper) exit 0;;\n*) printf 'installed:%s\\n' "$*";;\nesac\n`,
94-
);
95-
yield* fs.chmod(`${root}/.local/bin/t3`, 0o700);
95+
if (options?.fifo) {
96+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
97+
const mkfifo = yield* spawner.spawn(
98+
ChildProcess.make("mkfifo", ["-m", "700", `${root}/${installDirectory}/t3`]),
99+
);
100+
yield* mkfifo.exitCode;
101+
} else {
102+
yield* fs.writeFileString(
103+
`${root}/${installDirectory}/t3`,
104+
options?.cliScript ??
105+
`#!/bin/sh\ncase "$1" in\n--version) echo 't3 v${installedVersion}';;\n__ssh-helper) exit 0;;\n*) printf 'installed:%s\\n' "$*";;\nesac\n`,
106+
);
107+
yield* fs.chmod(`${root}/${installDirectory}/t3`, 0o700);
108+
}
96109
yield* fs.writeFileString(`${root}/bin/curl`, '#!/bin/sh\necho "HTTP 404" >&2\nexit 22\n');
97110
yield* fs.chmod(`${root}/bin/curl`, 0o700);
98111
yield* fs.writeFileString(`${root}/runner.sh`, SshTunnel.buildRemoteT3RunnerScript(ARCHIVE));
@@ -161,13 +174,15 @@ describe("ssh tunnel scripts", () => {
161174
}),
162175
);
163176

164-
it.live("reuses an installed CLI only when it matches the exact requested release", () =>
165-
Effect.gen(function* () {
166-
const result = yield* runArchiveRunner(ARCHIVE.archiveVersion);
167-
assert.equal(result.exitCode, 0, result.stderr);
168-
assert.equal(result.stdout, "installed:pair --json\n");
169-
assert.isFalse(result.runtimeExists);
170-
}),
177+
it.live.each([".local/bin", ".t3/bin"])(
178+
"reuses an exact-release installed CLI in %s",
179+
(installDirectory) =>
180+
Effect.gen(function* () {
181+
const result = yield* runArchiveRunner(ARCHIVE.archiveVersion, installDirectory);
182+
assert.equal(result.exitCode, 0, result.stderr);
183+
assert.equal(result.stdout, "installed:pair --json\n");
184+
assert.isFalse(result.runtimeExists);
185+
}),
171186
);
172187

173188
it.live.each(["1.2.2", "1.2.3", "1.2.3-nightly.20260911.4", "1.2.3-preview.20260911.3"])(
@@ -185,6 +200,28 @@ describe("ssh tunnel scripts", () => {
185200
}),
186201
);
187202

203+
it.live(
204+
"skips an installed CLI whose probes hang and falls through to the archive download",
205+
() =>
206+
Effect.gen(function* () {
207+
const result = yield* runArchiveRunner(ARCHIVE.archiveVersion, ".t3/bin", {
208+
cliScript: `#!/bin/sh\ncase "$1" in\n--version) sleep 300;;\n__ssh-helper) sleep 300;;\n*) printf 'installed:%s\\n' "$*";;\nesac\n`,
209+
});
210+
assert.notEqual(result.exitCode, 0);
211+
assert.include(result.stderr, `v${ARCHIVE.archiveVersion}/SHA256SUMS`);
212+
assert.isFalse(result.runtimeExists);
213+
}),
214+
);
215+
216+
it.live("skips a non-regular file at the desktop CLI path", () =>
217+
Effect.gen(function* () {
218+
const result = yield* runArchiveRunner(ARCHIVE.archiveVersion, ".t3/bin", { fifo: true });
219+
assert.notEqual(result.exitCode, 0);
220+
assert.include(result.stderr, `v${ARCHIVE.archiveVersion}/SHA256SUMS`);
221+
assert.isFalse(result.runtimeExists);
222+
}),
223+
);
224+
188225
it("rejects archive versions that are not a single exact version segment", () => {
189226
for (const archiveVersion of [
190227
"../other",

‎packages/ssh/src/tunnel.ts‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const REMOTE_LAUNCH_TIMEOUT_MS = 90_000;
5858
const REMOTE_ARCHIVE_CHECKSUMS_SECONDS = 30;
5959
const REMOTE_ARCHIVE_DOWNLOAD_SECONDS = 240;
6060
const REMOTE_ARCHIVE_LOCK_WAIT_SECONDS = 360;
61+
const REMOTE_INSTALLED_PROBE_SECONDS = 15;
6162
const REMOTE_ARCHIVE_LAUNCH_TIMEOUT_MS = 900_000;
6263
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
6364

@@ -445,14 +446,36 @@ T3_RUNTIME_DIR="$HOME/.t3/runtime/versions/$T3_ARCHIVE_VERSION"
445446
t3_runtime_ready() {
446447
[ -x "$T3_RUNTIME_DIR/t3" ] && [ "$(cat "$T3_RUNTIME_DIR/.install-complete" 2>/dev/null)" = "$T3_ARCHIVE_VERSION" ]
447448
}
448-
# Without the pinned runtime, reuse only an exact-release CLI from install.sh's PATH symlink.
449+
# Bound each probe so a hung candidate falls through to the archive download
450+
# instead of stalling until the SSH timeout. Output goes through a file and the
451+
# watchdog is detached: orphaned children holding a pipe would block the capture.
452+
t3_probe() {
453+
T3_PROBE_OUT="$(mktemp "\${TMPDIR:-/tmp}/t3-probe.XXXXXX")"
454+
"$@" >"$T3_PROBE_OUT" 2>/dev/null </dev/null &
455+
T3_PROBE_PID=$!
456+
(
457+
sleep @@T3_INSTALLED_PROBE_SECONDS@@
458+
kill "$T3_PROBE_PID" 2>/dev/null
459+
sleep 2
460+
kill -KILL "$T3_PROBE_PID" 2>/dev/null
461+
) >/dev/null 2>&1 &
462+
T3_PROBE_DOG=$!
463+
wait "$T3_PROBE_PID" 2>/dev/null
464+
T3_PROBE_RC=$?
465+
kill "$T3_PROBE_DOG" 2>/dev/null
466+
wait "$T3_PROBE_DOG" 2>/dev/null
467+
cat "$T3_PROBE_OUT"
468+
rm -f "$T3_PROBE_OUT"
469+
return "$T3_PROBE_RC"
470+
}
471+
# Reuse only an exact-release CLI from the shell or the standard install locations.
449472
if ! t3_runtime_ready; then
450-
for T3_INSTALLED in "$(command -v t3 2>/dev/null || true)" "$HOME/.local/bin/t3"; do
451-
[ -n "$T3_INSTALLED" ] && [ -x "$T3_INSTALLED" ] || continue
452-
T3_INSTALLED_VERSION="$("$T3_INSTALLED" --version 2>/dev/null || true)"
473+
for T3_INSTALLED in "$(command -v t3 2>/dev/null || true)" "$HOME/.local/bin/t3" "$HOME/.t3/bin/t3"; do
474+
[ -n "$T3_INSTALLED" ] && [ -f "$T3_INSTALLED" ] && [ -x "$T3_INSTALLED" ] || continue
475+
T3_INSTALLED_VERSION="$(t3_probe "$T3_INSTALLED" --version 2>/dev/null || true)"
453476
case "$T3_INSTALLED_VERSION" in
454477
"t3 v$T3_ARCHIVE_VERSION")
455-
if "$T3_INSTALLED" __ssh-helper --help >/dev/null 2>&1; then
478+
if t3_probe "$T3_INSTALLED" __ssh-helper --help >/dev/null 2>&1; then
456479
exec "$T3_INSTALLED" "$@"
457480
fi
458481
;;
@@ -829,6 +852,7 @@ export function buildRemoteT3RunnerScript(input?: RemoteT3RunnerOptions): string
829852
T3_ARCHIVE_VERSION: shellSingleQuote(archiveVersion),
830853
T3_RELEASE_BASE_URL: shellSingleQuote(releaseBaseUrl),
831854
T3_ARCHIVE_LOCK_WAIT_SECONDS: String(REMOTE_ARCHIVE_LOCK_WAIT_SECONDS),
855+
T3_INSTALLED_PROBE_SECONDS: String(REMOTE_INSTALLED_PROBE_SECONDS),
832856
T3_ARCHIVE_DOWNLOAD_SECONDS: String(REMOTE_ARCHIVE_DOWNLOAD_SECONDS),
833857
T3_ARCHIVE_CHECKSUMS_SECONDS: String(REMOTE_ARCHIVE_CHECKSUMS_SECONDS),
834858
T3_NODE_ENV_SCRIPT: buildRemoteNodeEnvScript(input),

0 commit comments

Comments
 (0)