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.

fix(ssh): one node's failure is undecided for that node, not a project-wide abort

enesb05ed91ae836
diff --git a/src/main/remote-ssh/agent-resync.test.ts b/src/main/remote-ssh/agent-resync.test.ts
index f54e52235..f681da133 100644
--- a/src/main/remote-ssh/agent-resync.test.ts
+++ b/src/main/remote-ssh/agent-resync.test.ts
@@ -89,6 +89,57 @@ describe('resyncProjectAgents', () => {
expect(readTranscriptTail).not.toHaveBeenCalled()
})
+ it('a throwing workingNodes leaves nothing to repair — it never rejects', async () => {
+ const d = deps({
+ workingNodes: () => {
+ throw new Error('mirror unreadable')
+ }
+ })
+ expect(await resyncProjectAgents('/cm/p1', d)).toEqual([])
+ expect(d.emitted).toEqual([])
+ })
+
+ it('a throwing remoteFor skips that node without rejecting', async () => {
+ const d = deps({
+ remoteFor: () => {
+ throw new Error('pty manager blew up')
+ }
+ })
+ expect(await resyncProjectAgents('/cm/p1', d)).toEqual([])
+ expect(d.emitted).toEqual([])
+ })
+
+ it('a throwing emit costs only its own node — the next one is still rescued', async () => {
+ const emitted: NormalizedAgentEvent[] = []
+ const d = deps({
+ workingNodes: () => [
+ { nodeId: 'n1', agentId: 'claude', sessionId: 'sa' },
+ { nodeId: 'n2', agentId: 'claude', sessionId: 'sb' }
+ ],
+ paneCommand: async () => 'zsh',
+ emit: (e) => {
+ if (e.nodeId === 'n1') throw new Error('mirror reducer blew up')
+ emitted.push(e)
+ }
+ })
+
+ expect(await resyncProjectAgents('/cm/p1', d)).toEqual(['n2'])
+ expect(emitted.map((e) => e.nodeId)).toEqual(['n2'])
+ })
+
+ it('a probe that throws synchronously is undecided, not a lost node', async () => {
+ const d = deps({
+ paneCommand: (() => {
+ throw new Error('not even a promise')
+ }) as AgentResyncDeps['paneCommand']
+ })
+
+ // The transcript leg must still get its say: a synchronous throw is one failed probe, not the
+ // end of this node's rescue.
+ expect(await resyncProjectAgents('/cm/p1', d)).toEqual(['n1'])
+ expect(d.emitted.map((e) => e.nodeId)).toEqual(['n1'])
+ })
+
it('handles several nodes independently', async () => {
const d = deps({
workingNodes: () => [
diff --git a/src/main/remote-ssh/agent-resync.ts b/src/main/remote-ssh/agent-resync.ts
index 110b54afd..70383b054 100644
--- a/src/main/remote-ssh/agent-resync.ts
+++ b/src/main/remote-ssh/agent-resync.ts
@@ -42,36 +42,66 @@ export async function resyncProjectAgents(
deps: AgentResyncDeps
): Promise<string[]> {
const ended: string[] = []
- for (const node of deps.workingNodes()) {
- // A synthetic event carries an agentId by contract; without one we cannot emit a well-formed
- // event, and inventing an agent would misattribute the node on every surface.
- if (!node.agentId) continue
- if (deps.remoteFor(node.nodeId)?.controlPath !== controlPath) continue
+ let working: { nodeId: string; agentId?: string; sessionId?: string }[]
+ try {
+ working = deps.workingNodes()
+ } catch {
+ return ended // no list ⇒ nothing to repair, and still not a rejection for the reconnect path
+ }
- const pane = await deps.paneCommand(node.nodeId).catch(() => null)
- let tail: string | null = null
- // Only pay for the transcript read when the pane could not answer on its own.
- if (!isDecisivePane(pane) && node.sessionId) {
- tail = await deps.readTranscriptTail(node.nodeId, node.sessionId).catch(() => null)
- }
+ for (const node of working) {
+ // One node's failure is `undecided` for THAT node — never a project-wide abort. `emit` is the
+ // real risk here: it fans out into the mirror reducer, the inbox, a disk write and the HUD, and
+ // a throw there would otherwise cost every later node its rescue and reject into the reconnect.
+ try {
+ // A synthetic event carries an agentId by contract; without one we cannot emit a well-formed
+ // event, and inventing an agent would misattribute the node on every surface.
+ if (!node.agentId) continue
+ if (deps.remoteFor(node.nodeId)?.controlPath !== controlPath) continue
+
+ const pane = await probe(() => deps.paneCommand(node.nodeId))
+ let tail: string | null = null
+ // Only pay for the transcript read when the pane could not answer on its own.
+ if (!isDecisivePane(pane) && node.sessionId) {
+ const sessionId = node.sessionId
+ tail = await probe(() => deps.readTranscriptTail(node.nodeId, sessionId))
+ }
- if (decideNode(pane, tail) !== 'ended') continue
+ if (decideNode(pane, tail) !== 'ended') continue
- // `idle: true` is the existing rescue-signal flag: a done carrying it may only move a node that
- // is still `working`, so a node parked on a permission prompt can never be cleared from here.
- deps.emit({
- nodeId: node.nodeId,
- agentId: node.agentId as AgentId,
- kind: 'state',
- state: 'done',
- idle: true,
- ...(node.sessionId ? { sessionId: node.sessionId } : {})
- })
- ended.push(node.nodeId)
+ // `idle: true` is the existing rescue-signal flag: a done carrying it may only move a node
+ // that is still `working`, so a node parked on a permission prompt can never be cleared here.
+ deps.emit({
+ nodeId: node.nodeId,
+ agentId: node.agentId as AgentId,
+ kind: 'state',
+ state: 'done',
+ idle: true,
+ ...(node.sessionId ? { sessionId: node.sessionId } : {})
+ })
+ ended.push(node.nodeId)
+ } catch {
+ continue
+ }
}
return ended
}
+/**
+ * Run one probe, degrading any failure to `null` — which `decideNode` reads as no evidence.
+ *
+ * The call itself is inside the try, not just the promise: a dep that throws SYNCHRONOUSLY never
+ * returns a promise to `.catch`, so it would escape to the loop's guard and cost the node its OTHER
+ * probe leg. One failed probe must only silence that probe.
+ */
+async function probe(run: () => Promise<string | null>): Promise<string | null> {
+ try {
+ return await run()
+ } catch {
+ return null
+ }
+}
+
/** Did the pane probe settle it by itself? Mirrors decideFromPane's 'ended' branch. */
function isDecisivePane(pane: string | null): boolean {
return decideNode(pane, null) === 'ended'