Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

perf(ssh): skip the host session listing when nothing is working, and ask decideFromPane directly

enes1d7ee4755673
diff --git a/src/main/remote-ssh/agent-resync.test.ts b/src/main/remote-ssh/agent-resync.test.ts
index 0d223ff79..87bce2c8f 100644
--- a/src/main/remote-ssh/agent-resync.test.ts
+++ b/src/main/remote-ssh/agent-resync.test.ts
@@ -123,6 +123,16 @@ describe('resyncProjectAgents', () => {
expect(d.emitted).toEqual([])
})
+ it('does not list the host sessions when nothing is working', async () => {
+ // "Nothing working" is the common case on a reconnect, and the listing is an ssh exec: paying
+ // for one per reconnect per SSH project would buy nothing at all.
+ const hostSessionNames = vi.fn(async () => new Set<string>())
+ const d = deps({ workingNodes: () => [], hostSessionNames })
+
+ expect(await resyncProjectAgents(d)).toEqual([])
+ expect(hostSessionNames).not.toHaveBeenCalled()
+ })
+
it('lists the host sessions once, however many nodes are working', async () => {
// One ssh round trip for the whole project: the list is a project-level fact, and paying for it
// per node would multiply the reconnect's remote traffic by the size of the canvas.
diff --git a/src/main/remote-ssh/agent-resync.ts b/src/main/remote-ssh/agent-resync.ts
index 4b2ba6fd6..de057b092 100644
--- a/src/main/remote-ssh/agent-resync.ts
+++ b/src/main/remote-ssh/agent-resync.ts
@@ -9,7 +9,7 @@
// orchestration only: the judgement is the pure `decideNode` (core/remote-ssh/agent-resync-decide),
// and every side effect is an injected dep.
-import { decideNode } from '../../core/remote-ssh/agent-resync-decide'
+import { decideFromPane, decideNode } from '../../core/remote-ssh/agent-resync-decide'
import { sessionName } from '../../core/tmux-naming'
import type { NormalizedAgentEvent } from '@shared/agents/normalize'
import type { AgentId } from '@shared/agents/config'
@@ -67,6 +67,11 @@ export async function resyncProjectAgents(deps: AgentResyncDeps): Promise<string
return ended // no list ⇒ nothing to repair, and still not a rejection for the reconnect path
}
+ // Nothing believed working ⇒ nothing to repair, and the listing below is an ssh exec. "Nothing
+ // working" is the COMMON case on a reconnect, so asking the host first would spend a remote round
+ // trip per reconnect per SSH project to learn something we already knew.
+ if (working.length === 0) return ended
+
// ONE listing for the whole project, and a failed listing repairs nothing: an empty set matches
// no node, which is the same safe direction as every other failed probe here.
let hostSessions: Set<string>
@@ -132,7 +137,11 @@ async function probe(run: () => Promise<string | null>): Promise<string | null>
}
}
-/** Did the pane probe settle it by itself? Mirrors decideFromPane's 'ended' branch. */
+/**
+ * Did the pane probe settle it by itself? Asks `decideFromPane` directly — that IS the question,
+ * and going through `decideNode` would make the answer depend on an internal ordering (its
+ * pane-first short circuit) rather than on the pane verdict itself.
+ */
function isDecisivePane(pane: string | null): boolean {
- return decideNode(pane, null) === 'ended'
+ return decideFromPane(pane) === 'ended'
}