Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(remote-host): surface SSH bootstrap failures in Settings

vastsae380ec88b093
diff --git a/apps/desktop/electron/main/remote/ssh-bootstrap.ts b/apps/desktop/electron/main/remote/ssh-bootstrap.ts
index 345169a25..cf696c0ed 100644
--- a/apps/desktop/electron/main/remote/ssh-bootstrap.ts
+++ b/apps/desktop/electron/main/remote/ssh-bootstrap.ts
@@ -120,7 +120,23 @@ const DEFAULT_READY_TIMEOUT_SEC = 120;
const DEFAULT_INSTALL_TIMEOUT_MS = 900_000;
function fail(message: string, errorCode: string, data?: Record<string, unknown>): Error {
- return Object.assign(new Error(message), { errorCode, ...(data ?? {}) });
+ return Object.assign(new Error(message), { errorCode, ...(data ?? {}), data });
+}
+
+const REMOTE_STEP_MESSAGES: Record<string, string> = {
+ "missing-node": "the remote machine has no Node.js; pi-host needs Node.js 22 or newer",
+ "node-too-old": "the remote Node.js is too old; pi-host needs Node.js 22 or newer",
+ "download-failed": "the remote machine could not download the pi-host bundle from GitHub",
+ "checksum-mismatch": "the downloaded pi-host bundle did not match the published SHA-256",
+ "missing-tar": "the remote machine has no tar",
+ "install-failed": "the remote pi-host install.sh failed",
+ "ready-timeout": "the remote pi-host started but did not become ready in time",
+ "host-exited": "the remote pi-host process exited before it became ready",
+ "host-start-failed": "the remote pi-host process failed to start",
+};
+
+function remoteStepMessage(step: string): string {
+ return REMOTE_STEP_MESSAGES[step] ?? `the remote bootstrap failed at '${step}'`;
}
/**
@@ -307,18 +323,14 @@ export function createSshBootstrap(deps: SshBootstrapDeps): SshBootstrap {
String((error as { stdout?: unknown }).stdout ?? ""),
);
if (!reported.failure) throw error;
- throw fail(
- `the remote bootstrap failed at '${reported.failure}'`,
- ErrorCodes.HOST_BOOTSTRAP_FAILED,
- {
- step: reported.failure,
- stderr: String((error as { stderr?: unknown }).stderr ?? "").slice(-2000),
- },
- );
+ throw fail(remoteStepMessage(reported.failure), ErrorCodes.HOST_BOOTSTRAP_FAILED, {
+ step: reported.failure,
+ stderr: String((error as { stderr?: unknown }).stderr ?? "").slice(-2000),
+ });
}
const parsed = parseBootstrapOutput(result.stdout);
if (parsed.failure) {
- throw fail(`the remote bootstrap failed at '${parsed.failure}'`, ErrorCodes.HOST_BOOTSTRAP_FAILED, {
+ throw fail(remoteStepMessage(parsed.failure), ErrorCodes.HOST_BOOTSTRAP_FAILED, {
step: parsed.failure,
stderr: result.stderr.slice(-2000),
});
@@ -389,6 +401,16 @@ export function createSshBootstrap(deps: SshBootstrapDeps): SshBootstrap {
...(target.password !== undefined ? { sshSecret: target.password } : {}),
steps,
};
+ } catch (error) {
+ const err = error instanceof Error ? error : new Error(String(error));
+ log("error", "ssh bootstrap failed", {
+ host: target.host,
+ message: err.message,
+ errorCode: (error as { errorCode?: string }).errorCode,
+ step: (error as { step?: string }).step,
+ stderr: String((error as { stderr?: string }).stderr ?? "").slice(-500),
+ });
+ throw error;
} finally {
// On success the caller adopts the forward, which is a child of this
// transport — disposing here would tear down the tunnel it just got.
diff --git a/apps/desktop/electron/main/remote/ssh-transport.ts b/apps/desktop/electron/main/remote/ssh-transport.ts
index 53e117530..a92b83dc0 100644
--- a/apps/desktop/electron/main/remote/ssh-transport.ts
+++ b/apps/desktop/electron/main/remote/ssh-transport.ts
@@ -90,7 +90,18 @@ const DEFAULT_EXEC_TIMEOUT_MS = 120_000;
const DEFAULT_FORWARD_TIMEOUT_MS = 30_000;
function fail(message: string, errorCode: string, data?: Record<string, unknown>): Error {
- return Object.assign(new Error(message), { errorCode, ...(data ?? {}) });
+ // `data` is duplicated so IPC wrap can forward it as `details` while existing
+ // callers still read `error.stderr` / `error.code` as own properties.
+ return Object.assign(new Error(message), { errorCode, ...(data ?? {}), data });
+}
+
+/** Last non-empty line of ssh stderr; that is what the Settings toast shows. */
+function lastSshDiagnostic(stderr: string): string {
+ const lines = stderr
+ .split(/\r?\n/)
+ .map((line) => line.trim())
+ .filter((line) => line.length > 0);
+ return lines.at(-1) ?? "";
}
/**
@@ -130,8 +141,11 @@ export function sshCommonArgs(target: SshTarget): string[] {
if (password) {
// The helper answers every prompt with the same secret, so a retry could
// only repeat a wrong password — and repeated failures are what trip a
- // server's own lockout. One prompt, one answer.
- args.push("-o", "NumberOfPasswordPrompts=1");
+ // server's own lockout. One prompt, one answer. Default identities are
+ // skipped: an encrypted `~/.ssh/id_rsa` would consume that single prompt
+ // as a key passphrase and never try the login password. Password mode in
+ // Settings replaces a key; users with both pick key mode.
+ args.push("-o", "NumberOfPasswordPrompts=1", "-o", "PubkeyAuthentication=no");
}
if (target.port !== undefined) args.push("-p", String(target.port));
if (target.identityFile) args.push("-i", target.identityFile);
@@ -366,13 +380,17 @@ export function createSystemSshTransport(
await releaseEnv();
}
if (result.code !== 0) {
+ const stderr = redactBootstrapOutput(result.stderr).slice(-2000);
+ const diagnostic = lastSshDiagnostic(stderr);
throw fail(
- `ssh command failed with exit code ${result.code}`,
+ diagnostic
+ ? `ssh command failed with exit code ${result.code}: ${diagnostic}`
+ : `ssh command failed with exit code ${result.code}`,
ErrorCodes.HOST_BOOTSTRAP_FAILED,
{
command,
code: result.code,
- stderr: redactBootstrapOutput(result.stderr).slice(-2000),
+ stderr,
// The bootstrap script reports *where* it failed on stdout, so the
// caller can turn a bare exit code into a named step.
stdout: redactBootstrapOutput(result.stdout).slice(-4000),
diff --git a/apps/desktop/test/remote-host-ssh-bootstrap.test.mjs b/apps/desktop/test/remote-host-ssh-bootstrap.test.mjs
index 1f1e67e70..78dd09b4e 100644
--- a/apps/desktop/test/remote-host-ssh-bootstrap.test.mjs
+++ b/apps/desktop/test/remote-host-ssh-bootstrap.test.mjs
@@ -198,10 +198,22 @@ test("a failed remote script reports the step it failed at", async () => {
const error = await catchError(() => bootstrap.bootstrap(request()));
assert.equal(error.errorCode, "HOST_BOOTSTRAP_FAILED");
assert.equal(error.step, "checksum-mismatch");
+ assert.match(error.message, /did not match the published SHA-256/);
assert.deepEqual(transport.calls.forwards, []);
assert.equal(transport.calls.disposeCount, 1);
});
+test("a missing remote Node.js is reported as a Node version requirement", async () => {
+ const transport = fakeTransport({
+ stdout: "PI_HOST_FAILED {\"code\":\"HOST_BOOTSTRAP_FAILED\",\"step\":\"missing-node\"}\n",
+ });
+ const { bootstrap } = harness({ transport });
+ const error = await catchError(() => bootstrap.bootstrap(request()));
+ assert.equal(error.errorCode, "HOST_BOOTSTRAP_FAILED");
+ assert.equal(error.step, "missing-node");
+ assert.match(error.message, /no Node\.js.*22/);
+});
+
test("a failed pairing exchange closes the forward it can no longer use", async () => {
const transport = fakeTransport();
const { bootstrap } = harness({
diff --git a/apps/desktop/test/remote-host-ssh-password.test.mjs b/apps/desktop/test/remote-host-ssh-password.test.mjs
index c9e959cbb..e15ea1576 100644
--- a/apps/desktop/test/remote-host-ssh-password.test.mjs
+++ b/apps/desktop/test/remote-host-ssh-password.test.mjs
@@ -114,6 +114,7 @@ test("sshCommonArgs keeps a key-authenticated target on BatchMode", () => {
assert.notEqual(index, -1, "the default path must still fail instead of prompting");
assert.equal(args.includes("BatchMode=no"), false);
assert.equal(args.includes("NumberOfPasswordPrompts=1"), false);
+ assert.equal(args.includes("PubkeyAuthentication=no"), false);
// No password means no askpass plumbing at all.
assert.equal(args.includes("-o"), true);
assert.equal(args.some((arg) => arg.includes("NumberOfPasswordPrompts")), false);
@@ -128,6 +129,9 @@ test("sshCommonArgs relaxes BatchMode only for a password target", () => {
const index = args.indexOf("NumberOfPasswordPrompts=1");
assert.notEqual(index, -1);
assert.equal(args[index - 1], "-o");
+ // Password mode replaces a key: default identities must not consume the
+ // single askpass answer as a passphrase.
+ assert.equal(args.includes("PubkeyAuthentication=no"), true);
// The secret is nowhere in the argv, in any form.
for (const arg of args) {
assert.equal(arg.includes(PASSWORD), false, "the password must never be an ssh argument");
diff --git a/apps/desktop/test/remote-host-ssh-transport.test.mjs b/apps/desktop/test/remote-host-ssh-transport.test.mjs
index 9efa300d0..29e937c3d 100644
--- a/apps/desktop/test/remote-host-ssh-transport.test.mjs
+++ b/apps/desktop/test/remote-host-ssh-transport.test.mjs
@@ -264,6 +264,11 @@ test("a non-zero exit becomes a typed error carrying both streams", { timeout: T
assert.equal(error.command, "bootstrap");
assert.match(error.stderr, /STDERR-MARKER-connection reset by peer/);
assert.match(error.stdout, /STDOUT-MARKER-the remote step failed/);
+ assert.match(
+ error.message,
+ /exit code 3: STDERR-MARKER-connection reset by peer/,
+ "the toast-facing message must carry ssh's last diagnostic",
+ );
return true;
},
);
diff --git a/docs/adr/0293-ssh-password-authentication.md b/docs/adr/0293-ssh-password-authentication.md
index 6028fc203..ce2504755 100644
--- a/docs/adr/0293-ssh-password-authentication.md
+++ b/docs/adr/0293-ssh-password-authentication.md
@@ -55,11 +55,13 @@ answer:
a `0700` directory created by `mkdtemp`, a `0600` secret, a `0700` helper.
3. **`BatchMode=yes` becomes `BatchMode=no` only when a password is supplied,
- together with `NumberOfPasswordPrompts=1`.** The helper answers every prompt
- with the same secret, so a retry could only repeat a wrong password, and
- repeated failures are what trip a server's own lockout. One prompt, one
- answer. An encrypted key whose passphrase is not that password falls through
- to password authentication, which is the behaviour a user with both expects.
+ together with `NumberOfPasswordPrompts=1` and `PubkeyAuthentication=no`.**
+ The helper answers every prompt with the same secret, so a retry could only
+ repeat a wrong password, and repeated failures are what trip a server's own
+ lockout. One prompt, one answer. Default identities are skipped: an encrypted
+ `~/.ssh/id_rsa` would consume that single prompt as a key passphrase and the
+ login password would never be tried. Password mode in Settings replaces a
+ key; a user with both picks key mode.
4. **The credential is short-lived.** Material is written when a child is about
to authenticate and deleted once it cannot still be prompting: after an
@@ -147,9 +149,10 @@ answer:
make an SSH host the only paired host that needs a human at startup, so a
restart would silently leave it offline. Encrypting it in the same store as
the device token keeps one credential model instead of two.
-- **`ssh -o PreferredAuthentications=password`.** Rejected: forcing the method
- breaks the fall-through a user with both a key and a password relies on, and
- it turns a working agent login into a failure.
+- **`ssh -o PreferredAuthentications=password`.** Rejected as a *key-path*
+ default: forcing the method would turn a working agent login into a failure.
+ Password mode (a secret supplied) instead sets `PubkeyAuthentication=no`,
+ which is the exclusive Settings choice rather than a fall-through.
## Testing
diff --git a/docs/spec/05-security/02-remote-control-security.md b/docs/spec/05-security/02-remote-control-security.md
index d3c627a1c..404e75aad 100644
--- a/docs/spec/05-security/02-remote-control-security.md
+++ b/docs/spec/05-security/02-remote-control-security.md
@@ -176,6 +176,10 @@ password for a host the user paired that way, under these rules:
- A password containing a line break cannot survive the askpass round trip and
is rejected before any remote command runs. Windows OpenSSH cannot execute
the helper and is refused with a remedy instead.
+- Password mode is exclusive: `PubkeyAuthentication=no` and
+ `NumberOfPasswordPrompts=1`. Default identities are not tried, because an
+ encrypted local key would consume the single askpass answer as a passphrase.
+ A user with both a key and a password picks key mode.
## 4. Authorization model
@@ -526,5 +530,5 @@ credentials.
D454 (2026-09-19) added SSH password authentication for the bootstrap (§3.4,
ADR 0293): the credential-handling rules above and gate 21. It relaxes
-`BatchMode=yes` for a password target only, with `NumberOfPasswordPrompts=1`,
-and keeps a key or agent as the default path.
+`BatchMode=yes` for a password target only, with `NumberOfPasswordPrompts=1`
+and `PubkeyAuthentication=no`, and keeps a key or agent as the default path.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index e37105946..3f878276d 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -11820,7 +11820,9 @@ browser milestones are scheduled.
resumes from the replay ring; the remote catalog lists the relayed MCP tool
but not the workspace-requiring plugin tool; the non-loopback peer and the
reused pairing token are rejected; the tampered bundle is refused before
- start; the version mismatch returns `PROTOCOL_MISMATCH` and offers the
+ start with a Settings toast that names the checksum failure rather than a
+ bare SSH exit code; a refused SSH login surfaces ssh's last stderr line in
+ that toast; the version mismatch returns `PROTOCOL_MISMATCH` and offers the
re-download; and the local session is untouched throughout.
- **Specs linked**: `02-architecture/05-remote-agent-control.md` §§5.2 and
6.3, `03-runtime/19-remote-agent-control-protocol.md` §§6.2, 9.4, and
@@ -11856,12 +11858,14 @@ browser milestones are scheduled.
and pairs. After the relaunch the host reconnects with no prompt, proving the
saved credential is used. The wrong password yields exactly one failed attempt
per connect (no helper-driven retry storm) and the host shows as offline rather
- than crashing the app or showing a rejected-login dialog. The key-only machine
- still authenticates with the key. No `ssh` argument contains the password, no
- askpass file or directory remains after the connect completes, and the on-disk
- record stores the password only as keychain ciphertext — never in cleartext.
- A password containing a newline is refused with `INVALID_ARGUMENT` before any
- remote command runs.
+ than crashing the app or showing a rejected-login dialog. The Settings toast
+ carries ssh's last stderr line (for example `Permission denied`), not a bare
+ exit code 255. The key-only machine fails under password mode because that
+ mode sets `PubkeyAuthentication=no`; a user with a key picks key mode. No
+ `ssh` argument contains the password, no askpass file or directory remains
+ after the connect completes, and the on-disk record stores the password only
+ as keychain ciphertext — never in cleartext. A password containing a newline
+ is refused with `INVALID_ARGUMENT` before any remote command runs.
- **Specs linked**: `05-security/02-remote-control-security.md` §§3.4 and 13
(gate 21), `02-architecture/05-remote-agent-control.md` §5.2,
`06-delivery/07-remote-control-rollout.md` §2
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index af168e277..6a610da64 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -6172,9 +6172,11 @@ that was sitting at the bottom — including after the turn had finished.
(after an exec child closes, after a forward's port is up, or on `dispose`),
so nothing lingers between operations.
- `BatchMode=yes` becomes `BatchMode=no` only for a password target, together
- with `NumberOfPasswordPrompts=1`: the helper answers every prompt with the
- same secret, so a retry could only repeat a wrong password, and repeated
- failures are what trip a server's own lockout.
+ with `NumberOfPasswordPrompts=1` and `PubkeyAuthentication=no`: the helper
+ answers every prompt with the same secret, so a retry could only repeat a
+ wrong password, and repeated failures are what trip a server's own lockout.
+ Default identities are skipped so an encrypted local key cannot consume that
+ single prompt as a passphrase; password mode in Settings replaces a key.
- The password is persisted encrypted through the same OS-keychain
`EncryptionPort` the device token uses, as a new optional
`encryptedSshSecret` in `remote-hosts.json`; the descriptor gains