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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(restart): a rejected restart is a counted failure, not a lost bulk run
enes744f4fbda516
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 35de66af3..1278cd4b7 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -119,6 +119,7 @@ import {agentRestartFn,planBulkRestart,restartEligibility,+ settleRestart,summarizeBulkRestart,type BulkRestartPlan,type RestartOutcome@@ -3610,7 +3611,20 @@ export function Canvas() {const restartAgentNode = useCallback(async (nodeId: string) => {const fn = agentRestartFn(nodeId)if (!fn) return // node unmounted between opening the menu and clicking- const outcome = await fn()+ let outcome: RestartOutcome+ try {+ outcome = await fn()+ } catch {+ // The transport under the restart threw (a relay socket still CONNECTING rejects the very+ // first write). Unhandled, this rejection made the action a silent no-op — the user clicked+ // and nothing at all came back. The exit command may or may not have reached the pane, so+ // the message sends them to look rather than claiming either.+ setNotice({+ kind: 'error',+ text: 'Restart failed: this session could not be reached. Check the pane before retrying.'+ })+ return+ }// 'info' fades itself out; anything that did NOT restart is left on screen to be read and// dismissed — the pane is untouched either way (nothing is ever killed).setNotice(@@ -3623,10 +3637,13 @@ export function Canvas() {}: {kind: 'error',- // 'not-eligible' covers all three: the gate re-checked and refused, the pane went- // away, or a restart of this node was already in flight (the per-node action and the- // bulk one can reach the same node).- text: 'Restart skipped: this session is busy, already restarting, or has nothing to resume.'+ // 'not-eligible' is every "not a target right now": the gate re-checked and refused,+ // the tmux session is closed / ended / gone (which the menu row cannot see — only the+ // node knows its session state), or a restart of this node was already in flight (the+ // per-node action and the bulk one can reach the same node).+ text:+ 'Restart skipped: this session is busy, already restarting, or no longer attached ' ++ '(closed, ended, or nothing to resume). Nothing was written to the pane.'})}, [])@@ -3684,10 +3701,17 @@ export function Canvas() {for (const id of plan.runnable) {const fn = agentRestartFn(id)// Unmounted since the plan was made: 'not-eligible' is folded into the no-session- // skips by summarizeBulkRestart, so it is still counted.- outcomes.push(fn ? await fn() : 'not-eligible')+ // skips by summarizeBulkRestart, so it is still counted. `settleRestart` turns a+ // REJECTED restart into a counted failure — an escaping rejection here would abandon+ // every node after it and swallow the summary the user confirmed this run for.+ outcomes.push(fn ? await settleRestart(fn) : 'not-eligible')}- setNotice({ kind: 'info', text: summarizeBulkRestart(outcomes, plan.skipped) })+ // A line reporting failures must not fade itself out from under the user; a clean run+ // may. Same rule as the per-node notices above.+ setNotice({+ kind: outcomes.some((o) => o === 'exit-timeout') ? 'error' : 'info',+ text: summarizeBulkRestart(outcomes, plan.skipped)+ })})()}})@@ -4053,7 +4077,11 @@ export function Canvas() {: 'Nothing to resume yet — this session has not reported an id.': !agentRestartFn(ids[0])? 'This terminal is not attached right now.'- : undefined+ : // Not every dead end is visible from here: the closure ALSO refuses a tmux+ // session that is closed / ended / gone, and only the node itself knows that. So+ // that case reaches the user through `restartAgentNode`'s skip notice, which+ // names it, rather than through a hint this row cannot compute.+ undefinedreturn [{label: 'Restart agent (resume)',diff --git a/src/renderer/terminal/agent-restart.test.ts b/src/renderer/terminal/agent-restart.test.tsindex ea2e18ea2..287583754 100644--- a/src/renderer/terminal/agent-restart.test.ts+++ b/src/renderer/terminal/agent-restart.test.ts@@ -9,6 +9,7 @@ import {planBulkRestart,registerAgentRestart,restartEligibility,+ settleRestart,summarizeBulkRestart,summarizeOutcomes,type BulkRestartCandidate,@@ -420,6 +421,39 @@ describe('planBulkRestart', () => {})})+describe('settleRestart', () => {+ it('passes a resolved outcome through untouched', async () => {+ await expect(settleRestart(async () => 'restarted')).resolves.toBe('restarted')+ await expect(settleRestart(async () => 'exit-timeout')).resolves.toBe('exit-timeout')+ await expect(settleRestart(async () => 'not-eligible')).resolves.toBe('not-eligible')+ })++ it('turns a thrown restart into a counted failure', async () => {+ await expect(+ settleRestart(async () => {+ // what a CONNECTING relay websocket does to the very first write+ throw new DOMException('Still in CONNECTING state.', 'InvalidStateError')+ })+ ).resolves.toBe('exit-timeout')+ })++ it('lets a bulk run keep going, and reach its summary, past a throwing node', async () => {+ const fns: (() => Promise<RestartOutcome>)[] = [+ async () => 'restarted',+ async () => {+ throw new Error('ws send failed')+ },+ async () => 'restarted'+ ]+ const outcomes: RestartOutcome[] = []+ for (const fn of fns) outcomes.push(await settleRestart(fn))+ expect(outcomes).toEqual(['restarted', 'exit-timeout', 'restarted'])+ expect(summarizeBulkRestart(outcomes, { working: 0, noSession: 0 })).toBe(+ '2 restarted · 1 failed (exit timeout)'+ )+ })+})+describe('summarizeBulkRestart', () => {it("folds 'not-eligible' outcomes into the no-session skips (the line stays four parts)", () => {expect(diff --git a/src/renderer/terminal/agent-restart.ts b/src/renderer/terminal/agent-restart.tsindex 1af622530..aec04a41c 100644--- a/src/renderer/terminal/agent-restart.ts+++ b/src/renderer/terminal/agent-restart.ts@@ -253,6 +253,30 @@ export function planBulkRestart(candidates: BulkRestartCandidate[]): BulkRestartreturn plan}+/**+ * Run one node's restart closure and always come back with an outcome — a REJECTION becomes+ * `'exit-timeout'`.+ *+ * The choreography's writes are unguarded all the way down to the socket+ * (`io.write` → `transport.write` → the relay client's `ws.send`, which throws `InvalidStateError`+ * on a CONNECTING socket), so one unlucky node can reject. In a bulk loop that rejection would+ * abandon every node after it AND lose the summary the user is waiting for, which is far worse than+ * whatever went wrong on the one node.+ *+ * `'exit-timeout'` — the "N failed" bucket — rather than the uncounted `'not-eligible'`: a throw+ * means the restart was attempted and did not complete, possibly leaving a stray `/exit` in the+ * pane, so it needs the same "go look at that node" reading a timeout gets. Filing it as a skip+ * would tell the user nothing happened there, which is exactly what we do not know. (A fifth+ * outcome is not an option — the summary line is spec-frozen at four parts.)+ */+export async function settleRestart(fn: () => Promise<RestartOutcome>): Promise<RestartOutcome> {+ try {+ return await fn()+ } catch {+ return 'exit-timeout'+ }+}+/*** The bulk run's one line. `'not-eligible'` outcomes are folded into the no-session skips: the* closure re-checks at call time and reports it for a node that stopped being a target between the