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(agents): a rescue done that moved no badge fires no completion alert either

enes4b708d8938a9
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index edd96d26c..6a6a9d2f8 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -6814,9 +6814,15 @@ export function Canvas() {
const m = e.task.match(/^\s*\/(loop|schedule|cron)\b/)
if (m) cs.setLoop(e.nodeId, true, m[1] as 'loop' | 'schedule' | 'cron', { task: e.task })
}
- if (e.state === 'done' && !e.interrupted) {
+ if (e.state === 'done' && !e.interrupted && !stuckRescueSkip) {
// Interrupted turns (Esc/Ctrl-C) alert nobody: the user did it themselves, and
// the turn didn't complete, so it isn't a loop iteration either.
+ // An IGNORED rescue is silent for the same reason it moves no badge: it claims a turn
+ // ended for a node this surface never saw running, so the "finished" is unfounded —
+ // and it arrives from a second source of truth (the main-process mirror drives the SSH
+ // reconnect resync, this store drives the alert), which can legitimately disagree after
+ // a renderer reload. Gating the badge but not the sound/notification would half-enforce
+ // the flag and leave the expensive error — a false completion — fully reachable.
cs.bumpLoop(e.nodeId, e.lastMessage) // count loop iterations + summary (no-op if not looping)
alert('finished', `${agentLabel} finished its turn.`, 'done')
}
diff --git a/src/renderer/canvas/agent-status-rescue.test.ts b/src/renderer/canvas/agent-status-rescue.test.ts
new file mode 100644
index 000000000..8c0dca355
--- /dev/null
+++ b/src/renderer/canvas/agent-status-rescue.test.ts
@@ -0,0 +1,49 @@
+// An IGNORED rescue event must be silent, not just badge-less.
+//
+// `idle: true` on a `done` means "inferred; may only move a node that is still working" — the flag
+// the SSH reconnect resync and the stuck-on-working sweep both ride. Canvas computes
+// `stuckRescueSkip` for it and skips the store write; the alert (unread dot, sound, loop bump, OS
+// notification) has to be skipped for exactly the same reason, or a node the user never saw running
+// announces that it finished. That is newly reachable because the resync's candidate list comes
+// from the MAIN-process mirror while the alert fires against the renderer's transient store, and
+// the two can legitimately disagree (a renderer reload empties its map; the two stale sweeps run on
+// independent cadences).
+//
+// Canvas.tsx is a ~7k-line monolith and this listener lives inside one of its `useEffect`s — there
+// is no harness that can dispatch an `agent:status` event at it (the renderer's component tests all
+// mount small leaf components), and building one for this fix would be a far bigger change than the
+// fix. So the invariant is pinned over the source, like `core/no-electron.test.ts` pins its
+// boundary: both gates in the `state` branch must consult the same skip flag.
+
+import { describe, it, expect } from 'vitest'
+import fs from 'fs'
+import path from 'path'
+
+const src = fs.readFileSync(path.resolve(__dirname, 'Canvas.tsx'), 'utf8')
+
+/** The `case 'state':` body of the agent-status listener. */
+function stateBranch(): string {
+ const start = src.indexOf('const stuckRescueSkip')
+ expect(start, 'Canvas must still compute a stuck-rescue skip flag').toBeGreaterThan(-1)
+ const end = src.indexOf("case 'subagent-start'", start)
+ expect(end).toBeGreaterThan(start)
+ return src.slice(start, end)
+}
+
+describe('Canvas agent-status listener — ignored rescue events', () => {
+ it('skips a rescue done that cannot move the badge', () => {
+ expect(stateBranch()).toMatch(
+ /const stuckRescueSkip = e\.idle === true && cs\.byId\[e\.nodeId\]\?\.state !== 'working'/
+ )
+ expect(stateBranch()).toMatch(/if \(e\.state && !stuckRescueSkip\)/)
+ })
+
+ it('a rescue done that was skipped also fires no completion alert', () => {
+ const branch = stateBranch()
+ const m = branch.match(/if \((e\.state === 'done'[^)]*)\)\s*\{/)
+ expect(m, "the 'done' alert branch must still exist").toBeTruthy()
+ // Whatever else guards it (interrupted turns), the skip flag has to be part of the condition:
+ // an event that moved nothing must not mark unread, play a sound, bump the loop or notify.
+ expect(m![1]).toContain('!stuckRescueSkip')
+ })
+})