diff --git a/apps/web/app/settings/executors/new/[type]/ssh-config.ts b/apps/web/app/settings/executors/new/[type]/ssh-config.ts index 91fdb6a5cf..1b456694cc 100644 --- a/apps/web/app/settings/executors/new/[type]/ssh-config.ts +++ b/apps/web/app/settings/executors/new/[type]/ssh-config.ts @@ -29,12 +29,16 @@ export function parseSSHExecutorConfig( ): Partial { const c = config ?? {}; const portRaw = c.ssh_port; + // A missing ssh_port intentionally stays `undefined` so the backend's + // resolver can apply ~/.ssh/config Port inheritance for the configured + // alias. Substituting 22 here would silently redirect connections that + // relied on the alias' Port. const port = portRaw ? Number.parseInt(portRaw, 10) : undefined; return { name, host_alias: c.ssh_host_alias ?? "", host: c.ssh_host ?? "", - port: Number.isFinite(port) ? (port as number) : 22, + port: port != null && Number.isFinite(port) ? port : undefined, user: c.ssh_user ?? "", identity_source: (c.ssh_identity_source as "agent" | "file") || "agent", identity_file: c.ssh_identity_file ?? "", diff --git a/apps/web/components/settings/ssh-sessions-card.tsx b/apps/web/components/settings/ssh-sessions-card.tsx index b6b736e464..aaf06bb684 100644 --- a/apps/web/components/settings/ssh-sessions-card.tsx +++ b/apps/web/components/settings/ssh-sessions-card.tsx @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { Badge } from "@kandev/ui/badge"; import { Button } from "@kandev/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@kandev/ui/card"; @@ -19,24 +19,39 @@ export function SSHSessionsCard({ executorId }: SSHSessionsCardProps) { const [sessions, setSessions] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); + // Monotonic sequence used to ignore stale poll responses: a slow request + // that resolves after a newer one (or after executorId changes) would + // otherwise overwrite the fresh row set. + const seqRef = useRef(0); const refresh = useCallback(async () => { + const seq = ++seqRef.current; setLoading(true); setError(null); try { const rows = await listSSHSessions(executorId); + if (seq !== seqRef.current) return; // a newer call (or executor switch) won the race setSessions(rows); } catch (e) { + if (seq !== seqRef.current) return; setError(e instanceof Error ? e.message : "Failed to load sessions"); } finally { - setLoading(false); + if (seq === seqRef.current) setLoading(false); } }, [executorId]); useEffect(() => { + // Reset sequence so a previous executor's pending response can't land + // here and pollute the new executor's data. + seqRef.current = 0; refresh(); const id = setInterval(refresh, REFRESH_INTERVAL_MS); - return () => clearInterval(id); + return () => { + clearInterval(id); + // Bump the sequence to invalidate any in-flight response from the + // unmounted instance. + seqRef.current = -1; + }; }, [refresh]); return ( diff --git a/apps/web/e2e/fixtures/ssh-image.ts b/apps/web/e2e/fixtures/ssh-image.ts index d561c9f2b0..4b5caa2142 100644 --- a/apps/web/e2e/fixtures/ssh-image.ts +++ b/apps/web/e2e/fixtures/ssh-image.ts @@ -50,8 +50,15 @@ fi # Optional second authorized_keys for a different user (passphrase-protected # key tests load a second key into ssh-agent and want it accepted too). +# Make sure the destination exists when only /authorized_keys.extra is mounted +# (otherwise "set -e" aborts the entrypoint on the >> redirect). if [ -f /authorized_keys.extra ]; then + mkdir -p /home/kandev/.ssh + touch /home/kandev/.ssh/authorized_keys cat /authorized_keys.extra >> /home/kandev/.ssh/authorized_keys + chown -R kandev:kandev /home/kandev/.ssh + chmod 700 /home/kandev/.ssh + chmod 600 /home/kandev/.ssh/authorized_keys fi # Run sshd in the foreground so docker logs and exit-codes propagate.