Skip to content

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

feat(switchdash): expose the per-host terminal cap in settings

amaudruzc6c8343da6de
diff --git a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.test.ts b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.test.ts
index 8e79acbf4..6ab5ba285 100644
--- a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.test.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.test.ts
@@ -266,6 +266,23 @@ describe('RemoteAttachmentPool', () => {
expect(a.attachCalls).toBe(1);
});
+ it('attaches a session that is focused before its runtime is registered', async () => {
+ // The renderer reports focus on navigation, which can beat provisioning.
+ // Without the catch-up in register(), the click would open nothing.
+ pool.setFocused('a');
+ const a = add('a');
+
+ await vi.waitFor(() => expect(a.attached).toBe(true));
+ });
+
+ it('does not attach an unfocused session on registration', async () => {
+ pool.setFocused('other');
+ const a = add('a');
+
+ await Promise.resolve();
+ expect(a.attachCalls).toBe(0);
+ });
+
it('keeps a live session attached when its runtime re-registers', async () => {
const a = add('a');
await pool.requestAttach('a', 'user');
diff --git a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.ts b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.ts
index 0cb20570c..2909c4b60 100644
--- a/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/agent-runtime/attachment/remote-attachment-pool.ts
@@ -67,6 +67,17 @@ export class RemoteAttachmentPool {
// A re-provisioned runtime for a live session keeps its state.
state: existing?.state ?? (runtime.isAttached() ? 'attached' : 'detached'),
});
+
+ // Focus can arrive before the runtime exists — the renderer reports it on
+ // navigation while provisioning is still running — and a `setFocused` for an
+ // unknown session has nothing to attach. Catch up here, or clicking a
+ // not-yet-provisioned session would leave its terminal closed with nothing
+ // to retry it.
+ if (sessionId === this.focusedSessionId && !runtime.isAttached()) {
+ void this.requestAttach(sessionId, 'focus').catch(() => {
+ // requestAttach already recorded and published the failure.
+ });
+ }
}
unregister(sessionId: string): void {
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/settings/components/RemoteAttachmentSettingsCard.tsx b/dash/apps/switchdash-desktop/src/renderer/features/settings/components/RemoteAttachmentSettingsCard.tsx
new file mode 100644
index 000000000..7aac94e61
--- /dev/null
+++ b/dash/apps/switchdash-desktop/src/renderer/features/settings/components/RemoteAttachmentSettingsCard.tsx
@@ -0,0 +1,61 @@
+import React, { useCallback } from 'react';
+import { useAppSettingsKey } from '@renderer/features/settings/use-app-settings-key';
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from '@renderer/lib/ui/select';
+import { SettingRow } from './SettingRow';
+
+/**
+ * Sessions on one remote host share a single SSH connection. Past a handful of
+ * open terminals the slower tunnels (IAP, SSM) stop answering channel opens and
+ * the connection is torn down and rebuilt in a loop, so this is capped. Raising
+ * it is safe on a fast host and risky on a slow one, which is why it is a
+ * choice rather than a constant.
+ */
+const CHOICES = [2, 4, 6, 8, 12] as const;
+
+const RemoteAttachmentSettingsCard: React.FC = () => {
+ const {
+ value: remote,
+ update,
+ isLoading: loading,
+ isSaving: saving,
+ } = useAppSettingsKey('remote');
+
+ const cap = remote?.maxAttachedSessionsPerHost ?? 4;
+
+ const applyCap = useCallback(
+ (next: string | null) => {
+ if (next === null) return;
+ update({ maxAttachedSessionsPerHost: Number(next) });
+ },
+ [update]
+ );
+
+ return (
+ <SettingRow
+ title="Open remote terminals per host"
+ description="How many sessions on the same remote host keep a live terminal. Others stay detached — their agents keep running and their status stays live, and a terminal opens when you view them."
+ control={
+ <Select value={String(cap)} onValueChange={applyCap} disabled={loading || saving}>
+ <SelectTrigger className="w-[183px] shrink-0 gap-2">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {CHOICES.map((choice) => (
+ <SelectItem key={choice} value={String(choice)}>
+ {choice} sessions
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ }
+ />
+ );
+};
+
+export default RemoteAttachmentSettingsCard;
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/settings/components/SettingsPage.tsx b/dash/apps/switchdash-desktop/src/renderer/features/settings/components/SettingsPage.tsx
index d712ae002..7cc00b0ca 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/settings/components/SettingsPage.tsx
+++ b/dash/apps/switchdash-desktop/src/renderer/features/settings/components/SettingsPage.tsx
@@ -8,6 +8,7 @@ import HiddenToolsSettingsCard from './HiddenToolsSettingsCard';
import InterfaceSettingsCard from './InterfaceSettingsCard';
import KeyboardSettingsCard from './KeyboardSettingsCard';
import NotificationSettingsCard from './NotificationSettingsCard';
+import RemoteAttachmentSettingsCard from './RemoteAttachmentSettingsCard';
import ResourceMonitorSettingsCard from './ResourceMonitorSettingsCard';
import {
AutoGenerateSessionNamesRow,
@@ -68,6 +69,7 @@ function InterfaceSettingsPage() {
<TerminalSettingsCard />
<SidebarMetadataSettingsCard />
<ResourceMonitorSettingsCard />
+ <RemoteAttachmentSettingsCard />
<InterfaceSettingsCard />
<div className="flex flex-col gap-3">
<h3 className="text-sm font-normal text-foreground">Keyboard shortcuts</h3>