Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

perf(switchdash): trust the persisted plan, and probe only what is stale (CHOO-1809)

Louis Amaudruz4a0bc437aeb1
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/agent-type-picker.tsx b/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/agent-type-picker.tsx
index f1046013f..dc99633bd 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/agent-type-picker.tsx
+++ b/dash/apps/switchdash-desktop/src/renderer/features/locations/components/add-agent-modal/agent-type-picker.tsx
@@ -12,6 +12,7 @@ import {
SelectTrigger,
SelectValue,
} from '@renderer/lib/ui/select';
+import { Spinner } from '@renderer/lib/ui/spinner';
import type { AgentProviderId } from '@shared/core/providers/agent-provider-registry';
/**
@@ -95,6 +96,20 @@ export function AgentTypePicker({
</div>
) : null;
+ // Asking the host what it has costs SSH round trips, and an empty dropdown
+ // during that reads as "this host offers nothing" rather than "still asking".
+ if (isPending) {
+ return (
+ <Field>
+ <FieldLabel>Agent type</FieldLabel>
+ <div className="flex items-center gap-2 text-xs text-foreground-muted">
+ <Spinner />
+ {sshHost ? `Checking what ${sshHost} has installed…` : 'Checking what is installed…'}
+ </div>
+ </Field>
+ );
+ }
+
const selected = options.find((o) => o.agent.id === value);
return (
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness-notice.tsx b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness-notice.tsx
index 3297b0b21..495399f75 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness-notice.tsx
+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness-notice.tsx
@@ -22,7 +22,7 @@ import { Spinner } from '@renderer/lib/ui/spinner';
import { log } from '@renderer/utils/logger';
import { deriveAgentTypeStatus } from '@shared/core/remote-hosts/host-status';
import { hostReachabilityStore } from './host-reachability-store';
-import { resolveReadiness, type HostReadiness } from './host-readiness';
+import { resolveReadiness, stepsNeedingObservation, type HostReadiness } from './host-readiness';
import { hostSetupStore } from './host-setup-store';
export { resolveReadiness, type HostReadiness };
@@ -40,8 +40,8 @@ export function useRemoteHostReadiness(
agentId: string | null
): HostReadiness {
const [checking, setChecking] = useState(false);
- // Probe at most once per host per mount: this costs an SSH round trip, and
- // re-running it on every render of a modal would hammer the host.
+ // One probe per host+type per mount. Two modals open on the same host would
+ // otherwise queue behind each other on a runner that takes one job at a time.
const probed = useRef(new Set<string>());
useEffect(() => {
@@ -52,14 +52,30 @@ export function useRemoteHostReadiness(
const plan = hostSetupStore.get(sshHost);
const status =
sshHost && reachability ? deriveAgentTypeStatus(reachability, plan, agentId) : null;
- const needsProbe = status?.kind === 'unchecked';
+
+ // The persisted plan answers this most of the time. Only what is missing or
+ // gone stale is re-observed, and only for this agent type.
+ const stale = sshHost ? stepsNeedingObservation(plan, agentId, Date.now()) : [];
+ // No plan at all is a different job: there is nothing to refresh, the host
+ // has to be surveyed from scratch.
+ const needsSurvey = !!sshHost && !plan;
+ const needsProbe = needsSurvey || stale.length > 0;
+ const probeKey = `${sshHost}:${agentId ?? '*'}:${stale.join(',')}`;
useEffect(() => {
- if (!sshHost || !needsProbe || probed.current.has(sshHost)) return;
- probed.current.add(sshHost);
+ if (!sshHost || !needsProbe || probed.current.has(probeKey)) return;
+ probed.current.add(probeKey);
setChecking(true);
- rpc.remoteHosts
- .recheckSetup(sshHost)
+ const run = needsSurvey
+ ? rpc.remoteHosts.recheckSetup(sshHost)
+ : // Sequentially: the runner takes one operation per host at a time, so
+ // firing these together only makes the later ones fail.
+ stale.reduce<Promise<unknown>>(
+ (queue, stepId) =>
+ queue.then(() => rpc.remoteHosts.recheckSetupStep({ sshHost, stepId })),
+ Promise.resolve()
+ );
+ run
.catch((error: unknown) => {
// A probe we could not run tells us nothing. Leaving the gate open is
// the honest outcome — the alternative blocks the user over our own
@@ -67,7 +83,10 @@ export function useRemoteHostReadiness(
log.warn('Could not check host readiness before creating an agent', { sshHost, error });
})
.finally(() => setChecking(false));
- }, [sshHost, needsProbe]);
+ // `stale` is derived from the plan and changes identity every render; the
+ // key already encodes its contents.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [sshHost, needsProbe, needsSurvey, probeKey]);
return resolveReadiness(status, plan, agentId, checking || needsProbe);
}
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.test.ts b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.test.ts
index 10ac56887..c79347c53 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.test.ts
+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.test.ts
@@ -10,7 +10,7 @@ import type {
HostSetupStepKind,
HostSetupStepState,
} from '@shared/core/remote-hosts/setup';
-import { resolveReadiness } from './host-readiness';
+import { resolveReadiness, stepsNeedingObservation } from './host-readiness';
function reachability(status: HostReachabilityStatus): HostReachability {
return {
@@ -225,3 +225,76 @@ describe('resolveReadiness — the agent-creation gate', () => {
});
});
});
+
+/**
+ * The persisted plan is the answer most of the time (CHOO-1809).
+ *
+ * The gate used to re-probe whenever a verdict read `unchecked`, and the probe
+ * it ran was a whole-host re-check: picking Codex went and looked at git, tmux,
+ * node and Claude Code too. Roughly thirty SSH commands, each opening a login
+ * shell, to answer a question about one agent type — which is what made the
+ * modal feel slow after changing machines.
+ */
+describe('stepsNeedingObservation', () => {
+ const NOW = Date.parse('2026-08-06T12:00:00.000Z');
+ const at = (iso: string, patch: Partial<HostSetupStep> = {}) => ({ ...patch, updatedAt: iso });
+
+ function observed(id: string, iso: string, kind: HostSetupStepKind = 'core-dependency') {
+ return { ...step(id, 'satisfied', kind), ...at(iso) };
+ }
+
+ it('asks for nothing when everything was seen recently', () => {
+ const p = plan([observed('git', '2026-08-06T11:58:00.000Z')]);
+
+ expect(stepsNeedingObservation(p, null, NOW)).toEqual([]);
+ });
+
+ it('asks again once an observation is older than the window', () => {
+ const p = plan([observed('git', '2026-08-06T11:00:00.000Z')]);
+
+ expect(stepsNeedingObservation(p, null, NOW)).toEqual(['git']);
+ });
+
+ it('always asks about a step nobody has ever observed', () => {
+ // A fresh timestamp on a step with no outcome is not an observation — the
+ // plan was just built.
+ const p = plan([
+ { ...step('git', 'pending'), outcome: null, updatedAt: '2026-08-06T11:59:00.000Z' },
+ ]);
+
+ expect(stepsNeedingObservation(p, null, NOW)).toEqual(['git']);
+ });
+
+ it('does not trust a timestamp it cannot read', () => {
+ const p = plan([{ ...observed('git', 'not-a-date') }]);
+
+ expect(stepsNeedingObservation(p, null, NOW)).toEqual(['git']);
+ });
+
+ it('leaves other agent types alone', () => {
+ // The point of the change: choosing Codex must not drag Claude Code's CLI
+ // and connector into the probe.
+ const p = plan([
+ observed('git', '2026-08-06T11:00:00.000Z'),
+ observed('claude', '2026-08-06T11:00:00.000Z', 'agent-cli'),
+ observed('claude:plugin', '2026-08-06T11:00:00.000Z', 'agent-plugin'),
+ observed('codex', '2026-08-06T11:00:00.000Z', 'agent-cli'),
+ observed('codex:plugin', '2026-08-06T11:00:00.000Z', 'agent-plugin'),
+ ]);
+
+ expect(stepsNeedingObservation(p, 'codex', NOW)).toEqual(['git', 'codex', 'codex:plugin']);
+ });
+
+ it('still includes the host prerequisites — they gate every type', () => {
+ const p = plan([
+ observed('git', '2026-08-06T11:00:00.000Z'),
+ observed('codex', '2026-08-06T11:59:00.000Z', 'agent-cli'),
+ ]);
+
+ expect(stepsNeedingObservation(p, 'codex', NOW)).toEqual(['git']);
+ });
+
+ it('asks for nothing when there is no plan — that is a survey, not a refresh', () => {
+ expect(stepsNeedingObservation(null, 'codex', NOW)).toEqual([]);
+ });
+});
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.ts b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.ts
index 2705bd755..ec7d44772 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.ts
+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/host-readiness.ts
@@ -9,6 +9,7 @@
import type { HostStatus } from '@shared/core/remote-hosts/host-status';
import {
agentTypeSteps,
+ hostLevelSteps,
outstandingRequiredHostSteps,
outstandingRequiredStepsFor,
type HostSetupPlan,
@@ -36,6 +37,47 @@ export type HostReadiness = {
const READY: HostReadiness = { blocked: false, checking: false, missing: [], scope: null };
+/**
+ * How long an observation is trusted before it is worth looking again.
+ *
+ * A host's dependencies do not change on their own, so re-probing on every
+ * glance buys nothing and costs an SSH round trip per step. Ten minutes is long
+ * enough that opening the modal repeatedly is free, and short enough that
+ * something installed by hand shows up without the user hunting for a re-check.
+ */
+export const OBSERVATION_TTL_MS = 10 * 60_000;
+
+/**
+ * Which steps are worth re-observing before judging this agent type.
+ *
+ * Empty means the persisted plan is good enough to answer from — which is the
+ * common case, and the whole point of persisting it.
+ *
+ * Deliberately narrow: only the host's own prerequisites plus the one agent
+ * type being created. Re-checking every type meant picking Codex probed git,
+ * tmux, node and Claude Code as well, roughly thirty SSH commands to answer a
+ * question about one of them.
+ */
+export function stepsNeedingObservation(
+ plan: HostSetupPlan | null,
+ agentId: string | null,
+ now: number,
+ ttlMs: number = OBSERVATION_TTL_MS
+): string[] {
+ if (!plan) return [];
+ const relevant = [...hostLevelSteps(plan), ...(agentId ? agentTypeSteps(plan, agentId) : [])];
+ return relevant
+ .filter((step) => {
+ // Never observed at all: nothing to go stale, everything to find out.
+ if (step.outcome === null) return true;
+ const seenAt = Date.parse(step.updatedAt);
+ // An unparseable timestamp is not evidence of freshness.
+ if (Number.isNaN(seenAt)) return true;
+ return now - seenAt > ttlMs;
+ })
+ .map((step) => step.id);
+}
+
/**
* The gate's decision, as a pure function.
*