Compare commits

...
Author SHA1 Message Date
paseo-bot[bot]andMatchy a6f7ddb816 fix(server): reconnect saved hosts after SSH authentication recovers
The host registry stopped reconnecting when the SSH transport reported
the same failure code as a rejected daemon credential. Give the SSH
failure its own code so the existing backoff can reopen the tunnel.

Co-authored-by: Matchy <32197833+matchy233@users.noreply.github.com>
2026-12-04 11:33:08 +00:00
4 changed files with 63 additions and 36 deletions
+14 -10
View File
@@ -244,16 +244,20 @@ export function createHostTransportFactory(
transport: factory({ ...attemptOptions, url: socketTarget.url }),
describeError: (error) => {
const detail = sshTunnel?.failureDetail() ?? "";
return /permission denied|authentication failed|host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED/i.test(
detail,
)
? Object.assign(
new Error(
"SSH authentication or host verification failed. Check the SSH configuration on this daemon.",
),
{ code: "authentication_failed" },
)
: error;
let reason: string;
if (/host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED/i.test(detail)) {
reason = "SSH host key verification failed";
} else if (/permission denied|authentication failed/i.test(detail)) {
reason = "SSH authentication failed";
} else {
return error;
}
return Object.assign(
new Error(`${reason}. Check the SSH configuration on this daemon.`),
{
code: "ssh_authentication_failed",
},
);
},
};
});
@@ -768,6 +768,10 @@ test("old capabilities fail before execution and authentication errors recover t
await expect
.poll(async () => (await paseo.hosts.list()).hosts[0]!.error?.code)
.toBe("authentication_failed");
expect((await paseo.hosts.list()).hosts[0]).toMatchObject({
status: "error",
nextRetryAt: null,
});
expect(JSON.stringify(await paseo.hosts.list())).not.toContain("wrong-password");
await paseo.hosts.update(saved.registrationId, {
connection: `tcp://127.0.0.1:${b.port}?password=right-password`,
@@ -1479,12 +1483,22 @@ test.skipIf(process.platform !== "linux" || !existsSync("/usr/sbin/sshd"))(
await writeFile(join(root, "authorized_keys"), "");
await paseo.hosts.update(host.registrationId, { enabled: true });
await expect
.poll(async () => (await paseo.hosts.list()).hosts[0]?.error?.code, { timeout: 15000 })
.toBe("authentication_failed");
expect((await paseo.hosts.list()).hosts[0]?.nextRetryAt).toBeNull();
.poll(async () => (await paseo.hosts.list()).hosts[0], { timeout: 15000 })
.toMatchObject({
status: "offline",
error: { code: "ssh_authentication_failed" },
nextRetryAt: expect.any(String),
});
const attemptsDuringFailure = await attempts();
await writeFile(join(root, "authorized_keys"), authorized);
await paseo.hosts.update(host.registrationId, { enabled: true });
await online(paseo);
const recovered = (await online(paseo)).hosts[0];
expect(recovered).toMatchObject({
registrationId: host.registrationId,
serverId: b.daemon.getServerId(),
error: null,
nextRetryAt: null,
});
expect(await attempts()).toBeGreaterThan(attemptsDuringFailure);
},
60000,
);
@@ -4,6 +4,7 @@ import { randomUUID, createHash } from "node:crypto";
import { mkdir, readFile, rename, writeFile, rm } from "node:fs/promises";
import { join } from "node:path";
import { z } from "zod";
import type { Logger } from "pino";
import {
createHostClient,
createHostChannelTransport,
@@ -81,6 +82,7 @@ export class ConnectedHosts {
constructor(
private readonly home: string,
private readonly self: HostDirectory["self"] & { version?: string },
private readonly logger?: Logger,
) {
this.ready = this.load();
void this.ready.catch(() => {});
@@ -356,6 +358,7 @@ export class ConnectedHosts {
live.permissions = info.permissions ? [...info.permissions] : undefined;
live.connectedAt = next.lastOnlineAt;
attempts = 0;
this.logger?.info({ registrationId: row.registrationId }, "Connected host is online");
this.changed();
});
} catch (error) {
@@ -389,23 +392,31 @@ export class ConnectedHosts {
if (route.registrationId === row.registrationId) route.close();
row.status = state.status === "connecting" ? "connecting" : "offline";
row.nextRetryAt = state.status === "disconnected" ? (state.nextRetryAt ?? null) : null;
if (state.status === "disconnected")
row.error = connectionFailure(
Object.assign(new Error("Check the SSH configuration and daemon credentials"), {
code: state.failureCode,
}),
client.helloRejection !== null,
) ?? {
if (state.status === "disconnected") {
row.error = connectionFailure(undefined, client.helloRejection !== null) ?? {
code: "host_offline",
message: "Cannot reach host. Check the connection; retrying automatically.",
};
else if (row.error?.code !== "unsupported_capability") row.error = null;
if (row.error?.code === "authentication_failed") {
row.status = "error";
row.nextRetryAt = null;
client.setReconnectEnabled(false);
void client.close();
}
if (row.error.code === "authentication_failed") {
row.status = "error";
row.nextRetryAt = null;
client.setReconnectEnabled(false);
void client.close();
} else if (state.failureCode === "ssh_authentication_failed") {
row.error = {
code: state.failureCode,
message: `${state.reason ?? "SSH authentication failed."} Retrying automatically.`,
};
this.logger?.warn(
{
registrationId: row.registrationId,
code: row.error.code,
nextRetryAt: row.nextRetryAt,
},
row.error.message,
);
}
} else if (row.error?.code !== "unsupported_capability") row.error = null;
this.changed();
});
void client.connect().catch(() => {});
@@ -629,8 +640,6 @@ const terminalFailures = new Set([
function connectionFailure(error: unknown, authenticationFailed: boolean): HostSummary["error"] {
if (error instanceof HostError) return { code: error.code, message: error.message };
if (error instanceof Error && "code" in error && error.code === "authentication_failed")
return { code: "authentication_failed", message: error.message };
if (authenticationFailed)
return {
code: "authentication_failed",
@@ -1010,11 +1010,11 @@ export class VoiceAssistantWebSocketServer {
this.workspaceAutoName = workspaceAutoName;
this.downloadTokenStore = downloadTokenStore;
this.paseoHome = paseoHome;
this.connectedHosts = new ConnectedHosts(paseoHome, {
serverId,
label: getHostName(),
version: this.daemonVersion,
});
this.connectedHosts = new ConnectedHosts(
paseoHome,
{ serverId, label: getHostName(), version: this.daemonVersion },
logger.child({ module: "connected-hosts" }),
);
this.passwordStore = this.resolvePasswordStore(auth, daemonConfigStore);
this.daemonConfigStore = daemonConfigStore;
this.unsubscribePasswordChange = this.bindPasswordReloadListener();