Skip to content
TypeScript

fix(server): report missing Node on SSH device hosts instead of a connection failure (#20377)

Scott Nortemandfda92872d5b
diff --git a/apps/server/src/device/DeviceService.test.ts b/apps/server/src/device/DeviceService.test.ts
index 25eab7a2ed4..54c6f814f95 100644
--- a/apps/server/src/device/DeviceService.test.ts
+++ b/apps/server/src/device/DeviceService.test.ts
@@ -12,6 +12,7 @@ import {
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as NetService from "@t3tools/shared/Net";
+import { SshCommandError } from "@t3tools/ssh/errors";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
import * as Deferred from "effect/Deferred";
@@ -694,6 +695,84 @@ it.effect("host retry exposes actionable failure without internal IDs or diagnos
}).pipe(Effect.scoped),
);
+it.effect.each([
+ {
+ name: "missing Node among private diagnostic lines",
+ exitCode: 1,
+ stderr:
+ "private diagnostics\r\nNode is missing from the non-interactive SSH PATH\r\nprivate diagnostics",
+ expected:
+ "Connected over SSH, but Node is not on this host's PATH for non-interactive SSH commands.",
+ },
+ {
+ name: "another remote command failure",
+ exitCode: 2,
+ stderr: "private diagnostics",
+ expected: "Connected over SSH, but the device host check failed (exit code 2).",
+ },
+ {
+ name: "an unrecognized exit-one diagnostic",
+ exitCode: 1,
+ stderr: "private diagnostics: Node is missing from the non-interactive SSH PATH",
+ expected: "Connected over SSH, but the device host check failed (exit code 1).",
+ },
+ {
+ name: "a connection failure",
+ exitCode: 255,
+ stderr: "Node is missing from the non-interactive SSH PATH",
+ expected: "Could not connect to this host over SSH.",
+ },
+ {
+ name: "a command that could not start",
+ exitCode: null,
+ stderr: "private diagnostics",
+ expected: "Could not connect to this host over SSH.",
+ },
+ {
+ name: "an untyped offline cause",
+ exitCode: undefined,
+ stderr: "private diagnostics",
+ expected: "Could not connect to this host over SSH.",
+ },
+])("reports $name through manual and agent host readiness", ({ exitCode, stderr, expected }) =>
+ Effect.gen(function* () {
+ const failure = new DeviceHost.DeviceHostError({
+ hostId: LOCAL_DEVICE_HOST_ID,
+ step: "probe",
+ cause:
+ exitCode === undefined
+ ? "offline"
+ : new SshCommandError({
+ command: ["ssh", "private arguments"],
+ exitCode,
+ stderr,
+ stdout: "private output",
+ message: "private diagnostics",
+ }),
+ });
+ const { service, settings } = yield* fixture(Effect.void, undefined, false, failure);
+ yield* Ref.update(settings, (current) => ({
+ ...current,
+ enableDeviceSupport: true,
+ enableAgentDeviceAccess: true,
+ }));
+ for (const readiness of [service.readiness(), service.agentReadinessIfSupported()]) {
+ const error = yield* readiness.pipe(Effect.flip);
+ expect(error).toMatchObject({ reason: expected, cause: failure });
+ expect((yield* service.state).hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({
+ status: "failed",
+ detail: expected,
+ });
+ }
+ for (const state of [yield* service.list, yield* service.retryHost(LOCAL_DEVICE_HOST_ID)]) {
+ expect(state.hostStatuses[LOCAL_DEVICE_HOST_ID]).toEqual({
+ status: "failed",
+ detail: expected,
+ });
+ }
+ }).pipe(Effect.scoped),
+);
+
it.effect("version discovery does not grant consent or start device tools", () =>
Effect.gen(function* () {
const { service, starts, agentStarts, requests } = yield* fixture();
diff --git a/apps/server/src/device/DeviceService.ts b/apps/server/src/device/DeviceService.ts
index d453d15adac..76099d23550 100644
--- a/apps/server/src/device/DeviceService.ts
+++ b/apps/server/src/device/DeviceService.ts
@@ -23,6 +23,7 @@ import {
LOCAL_DEVICE_HOST_ID,
type ThreadId,
} from "@t3tools/contracts";
+import { SshCommandError } from "@t3tools/ssh/errors";
import * as FileSystem from "effect/FileSystem";
import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
import * as Path from "effect/Path";
@@ -59,6 +60,28 @@ import * as LocalDeviceHost from "./LocalDeviceHost.ts";
export const DEVICE_HUB_ROUTE_PREFIX = "/api/device-hub";
+const sshProbeFailureMessage = (error: DeviceHost.DeviceHostError): string => {
+ const cause = error.cause;
+ if (
+ !(cause instanceof SshCommandError) ||
+ cause.exitCode === null ||
+ cause.exitCode < 1 ||
+ cause.exitCode > 254
+ )
+ return "Could not connect to this host over SSH.";
+
+ // Only the known bootstrap diagnostic is safe to expose as Node guidance.
+ if (
+ cause.exitCode === 1 &&
+ cause.stderr
+ .split(/\r?\n/u)
+ .some((line) => line.trim() === "Node is missing from the non-interactive SSH PATH")
+ )
+ return "Connected over SSH, but Node is not on this host's PATH for non-interactive SSH commands.";
+
+ return `Connected over SSH, but the device host check failed (exit code ${cause.exitCode}).`;
+};
+
const BOOT_TIMEOUT = Duration.minutes(3);
const SCREENSHOT_TIMEOUT = Duration.seconds(20);
@@ -250,7 +273,13 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
)
.pipe(
Effect.tapError((error) =>
- setHostStatus(host.id, { status: "failed", detail: error.message }),
+ setHostStatus(host.id, {
+ status: "failed",
+ detail:
+ error._tag === "DeviceHostError" && error.step === "probe"
+ ? sshProbeFailureMessage(error)
+ : error.message,
+ }),
),
Effect.mapError(
(error) =>
@@ -260,7 +289,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
error._tag === "NodeRuntimeUnavailableError"
? nodeRuntimeUnavailableMessage("Local device support")
: error.step === "probe"
- ? "Could not connect to this host over SSH."
+ ? sshProbeFailureMessage(error)
: `Device support failed during ${error.step}.`,
cause: error,
}),
@@ -305,7 +334,13 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
)
.pipe(
Effect.tapError((error) =>
- setHostStatus(host.id, { status: "failed", detail: error.message }),
+ setHostStatus(host.id, {
+ status: "failed",
+ detail:
+ error._tag === "DeviceHostError" && error.step === "probe"
+ ? sshProbeFailureMessage(error)
+ : error.message,
+ }),
),
Effect.mapError(
(error) =>
@@ -319,7 +354,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
: error._tag === "AgentDeviceStartError"
? error.message
: error.step === "probe"
- ? "Could not connect to this host over SSH."
+ ? sshProbeFailureMessage(error)
: `Device support failed during ${error.step}.`,
cause: error,
}),