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): close the remaining pause-session gaps from a second review pass

Mina Samehe0398360a18c
diff --git a/CLAUDE.md b/CLAUDE.md
index 5aa35d2b5..279ef1f40 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -466,8 +466,9 @@ Lifecycle, by intent:
process. (2) **Fire-time re-asks**: still-offscreen, remote, eligibility — a plan-time verdict
is stale by seconds. (3) `hibernated` **self-heals** on live hook states + SessionStart (never
on `done` — a late Stop POST must not undo a just-performed hibernate); cold restore (`fresh`)
- clears it and lets the normal auto-resume own the node — **UNLESS the node is also `paused`**
- (see below), which is the one deliberate exception to that rule. (4) **Ordering with offscreen
+ clears `hibernated` UNCONDITIONALLY and normally lets auto-resume own the node — **`paused` (see
+ below) is what makes that auto-resume itself conditional**, the one deliberate exception: the
+ flag it gates is still cleared, only the relaunch is skipped. (4) **Ordering with offscreen
release**:
Eco defers the Phase-2 viewer release until the node hibernates (hard cap idle+offscreen), but
ONLY when the idle clock is known (`idleKnown` — `lastEventAt` is transient, so after an app
@@ -490,9 +491,14 @@ Lifecycle, by intent:
which reuses the SAME `wakeHibernatedNode` trigger the SLEEPING/PAUSED chip's click uses, so it
gets the same `WakeInputBuffer` splice protection and retry budget). Pausing an already-hibernated
node skips the exit phase entirely (`alreadyExited` in the closure) — asking an idle CLI-less
- shell to quit would type `/exit` into it as a real command. Node menu only today (canvas
- right-click + the sessions sidebar row menu, which shares the same `selectionItems` builder, plus
- a read-only kanban card badge and a clickable one in the card modal); no command palette entry.
+ shell to quit would type `/exit` into it as a real command. `paused` is ALSO excluded from Eco's
+ own candidate plan and its exit closure's fire-time re-ask (`HibernationCandidate.paused`,
+ `hibernationCandidates.ts`) — a deep-paused node has `hibernated` unset (its tmux was recycled,
+ not exited), so `!hibernated` alone would still admit it to a sweep whose dropped SessionEnd hook
+ POST left a stale `done` behind: the same `/exit`-into-a-bare-shell mistake `alreadyExited` closes
+ on the manual path, closed here on the automatic one. Node menu only today (canvas right-click +
+ the sessions sidebar row menu, which shares the same `selectionItems` builder, plus a read-only
+ kanban card badge and a clickable one in the card modal); no command palette entry.
The node id is the `persistKey` (passed to `transport.create`), so it must stay stable.
If tmux is unavailable, `PtyManager` falls back to a plain shell (no cross-restart
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 0e272d1d8..0a31e93be 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -5550,14 +5550,24 @@ export function Canvas() {
)
}, [setNodes, markDirty])
- // Manual "Pause session" (node context menu — canvas right-click and the sessions sidebar row
- // menu, which reuses the same `selectionItems` builder; no command palette entry or kanban-card
- // button yet, deliberately deferred): quit the CLI
- // (and, when `deep`, also recycle the tmux session) and mark the node PAUSED — see
- // `registerAgentPause` for why this is its own closure rather than `agentHibernateFns.exit()`.
+ // Manual "Pause session" (the PAUSE action itself: node context menu only — canvas right-click
+ // and the sessions sidebar row menu, which reuses the same `selectionItems` builder; no command
+ // palette entry, no kanban-card pause button, deliberately deferred. RESUME is wider — see
+ // `resumeAgentNode` below and `CardModal`'s own clickable PAUSED chip): quit the CLI (and, when
+ // `deep`, also recycle the tmux session) and mark the node PAUSED — see `registerAgentPause` for
+ // why this is its own closure rather than `agentHibernateFns.exit()`.
const pauseAgentNode = useCallback(async (nodeId: string, deep: boolean) => {
const fns = agentPauseFns(nodeId)
- if (!fns) return // node unmounted between opening the menu and clicking
+ if (!fns) {
+ // Same "not attached" case `resumeAgentNode` covers — most often an offscreen-RELEASED node
+ // (its lifecycle effect torn down the registration in place, but the row is still reachable
+ // from the sidebar menu). A silent no-op here reads as a broken button.
+ setNotice({
+ kind: 'error',
+ text: 'Pause skipped: this terminal is not attached right now.'
+ })
+ return
+ }
let outcome: Awaited<ReturnType<typeof fns.pause>>
try {
outcome = await fns.pause(deep)
@@ -7108,10 +7118,17 @@ export function Canvas() {
},
{
label: 'Pause & end session',
- disabled: !!pauseWhy,
+ // The deep depth recycles the tmux session, which — like the "Restart
+ // agent and shell" recycle it shares the mechanism with — the closure
+ // refuses on a relay session's core (the shell env belongs to the HOST).
+ // Named here rather than left to the closure's generic "busy / not
+ // attached" notice, which would be a wrong reason for a right refusal.
+ disabled: !!pauseWhy || session.source === 'relay',
hint:
pauseWhy ??
- 'Quits the CLI and ends its tmux session too, for a fuller memory reclaim. Resume starts a fresh session with the same conversation.',
+ (session.source === 'relay'
+ ? 'Ends the tmux session on the machine hosting this relay session, not here.'
+ : 'Quits the CLI and ends its tmux session too, for a fuller memory reclaim. Resume starts a fresh session with the same conversation.'),
onClick: () => void pauseAgentNode(ids[0], true)
}
]
diff --git a/src/renderer/lib/hibernationCandidates.test.ts b/src/renderer/lib/hibernationCandidates.test.ts
index 4767a2ea5..a2d720d44 100644
--- a/src/renderer/lib/hibernationCandidates.test.ts
+++ b/src/renderer/lib/hibernationCandidates.test.ts
@@ -28,6 +28,7 @@ describe('buildHibernationCandidates', () => {
wired: true,
offscreen: true,
hibernated: false,
+ paused: false,
remote: false,
recurring: false,
liveSubagents: false,
@@ -158,6 +159,16 @@ describe('buildHibernationCandidates', () => {
expect(planHibernation(rows, NOW, { enabled: true, idleMinutes: 30 })).toEqual([])
})
+ it('marks a PAUSED node (hibernated unset — the deep pause case) so the sweep never types /exit into its already-bare shell', () => {
+ const rows = buildHibernationCandidates(
+ inputs({
+ statusById: { a: { state: 'done', sessionId: 'sid-a', lastEventAt: IDLE, paused: true } }
+ })
+ )
+ expect(rows[0]).toMatchObject({ hibernated: false, paused: true })
+ expect(planHibernation(rows, NOW, { enabled: true, idleMinutes: 30 })).toEqual([])
+ })
+
it('an idle, offscreen, wired agent node with none of the guards IS planned', () => {
// The positive control: without it, every refusal above could be passing for the wrong reason.
expect(planHibernation(buildHibernationCandidates(inputs()), NOW, { enabled: true, idleMinutes: 30 })).toEqual(['a'])
diff --git a/src/renderer/lib/hibernationCandidates.ts b/src/renderer/lib/hibernationCandidates.ts
index 83136be00..f9c71c5dd 100644
--- a/src/renderer/lib/hibernationCandidates.ts
+++ b/src/renderer/lib/hibernationCandidates.ts
@@ -41,6 +41,10 @@ export interface HibernationStatusInput {
state?: string
sessionId?: string
hibernated?: boolean
+ /** See `HibernationCandidate.paused` — a deep "pause & end session" node has `hibernated` unset
+ * (its tmux was recycled, not exited), so this is the ONLY thing that excludes it from a sweep
+ * whose SessionEnd hook POST for the manual exit was dropped. */
+ paused?: boolean
lastEventAt?: number
/** Present = this node has a `/loop`, `/schedule` or `/cron` on it. Its `dismissed` flag is
* deliberately NOT consulted — see the header. */
@@ -88,6 +92,7 @@ export function buildHibernationCandidates(
wired: inputs.isWired(n.id),
offscreen: inputs.isOffscreen(n.id),
hibernated: !!st?.hibernated,
+ paused: !!st?.paused,
remote: inputs.isRemote(n.id),
recurring: !!st?.loop,
liveSubagents: liveParents.has(n.id),
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index b9c394aa7..cfa08cb58 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -3363,6 +3363,12 @@ export function TerminalNode({
// Read at CALL time — a local project can BECOME an SSH project long after this mount.
if (offscreenRemoteRef.current) return 'not-eligible'
const st = useAgentStatus.getState().byId[id]
+ // Already paused (shallow OR deep — deep has `hibernated` unset, so this is the only
+ // thing that catches it): the plan already excludes this via `HibernationCandidate.paused`,
+ // but a dropped SessionEnd hook POST could otherwise leave a deep-paused node reading as
+ // an ordinary idle `done` candidate between the plan and this fire-time re-ask. The pane is
+ // already bare — see `alreadyExited` in the manual pause closure for the same rule.
+ if (st?.paused) return 'not-eligible'
const agentSessionId = st?.sessionId
// Re-asked here, not trusted from the plan: a node that started working between the sweep's
// decision and its turn must keep its turn (BUSY_STATES — an exit line typed into a
@@ -3472,12 +3478,13 @@ export function TerminalNode({
})
})
- // Manual "Pause session" (node context menu — shared by the canvas right-click and the
- // sessions sidebar row menu, which reuses this same `selectionItems` builder; no command
- // palette entry or kanban-card-modal button yet, deliberately deferred): quit the CLI
- // and mark the node PAUSED so it does NOT auto-resume on the next reveal or cold restart — an
- // explicit Resume (which reuses `agentHibernateFns(id).resume()` above, unchanged) is the only
- // way back. Deliberately its OWN closure rather than a call into `agentHibernateFns(id).exit()`:
+ // Manual "Pause session" (the PAUSE action: node context menu only — shared by the canvas
+ // right-click and the sessions sidebar row menu, which reuses this same `selectionItems`
+ // builder; no command palette entry, no kanban-card pause button, deliberately deferred): quit
+ // the CLI and mark the node PAUSED so it does NOT auto-resume on the next reveal or cold
+ // restart — an explicit Resume (which reuses `agentHibernateFns(id).resume()` above, and now
+ // has a THIRD surface too — `CardModal`'s own clickable PAUSED chip) is the only way back.
+ // Deliberately its OWN closure rather than a call into `agentHibernateFns(id).exit()`:
// that one refuses a node the user is currently WATCHING (`isNodeWatched`) — exactly right for
// Eco's own sweep, exactly wrong for a manual pause of the node the user is looking at right now.
const unregisterPause = registerAgentPause(id, {
diff --git a/src/renderer/state/agentStatus.persist.test.ts b/src/renderer/state/agentStatus.persist.test.ts
index e3cd8f646..c9da6f4c2 100644
--- a/src/renderer/state/agentStatus.persist.test.ts
+++ b/src/renderer/state/agentStatus.persist.test.ts
@@ -247,6 +247,22 @@ describe('loop persistence (cron/schedule survive an app restart)', () => {
}
})
+ it('the LIVE-state self-heal drops `hibernatedPane` alongside a paused-only flag (deep pause), but NOT when `hibernated` still owns it', async () => {
+ const { useAgentStatus } = await import('./agentStatus')
+ // paused-only (the deep "pause & end session" shape): the pane record goes with it.
+ useAgentStatus.getState().setPaused('n30', true)
+ useAgentStatus.getState().setHibernatedPane('n30', 'nu')
+ useAgentStatus.getState().setState('n30', 'working', 'claude')
+ expect(useAgentStatus.getState().byId['n30'].hibernatedPane).toBeUndefined()
+ // hibernated AND paused together (shallow pause): the shared `hibernated` clear already drops
+ // it — this is not a NEW case, just confirming the paused-only branch doesn't double-clear.
+ useAgentStatus.getState().setHibernated('n31', true)
+ useAgentStatus.getState().setPaused('n31', true)
+ useAgentStatus.getState().setHibernatedPane('n31', 'nu')
+ useAgentStatus.getState().setState('n31', 'working', 'claude')
+ expect(useAgentStatus.getState().byId['n31'].hibernatedPane).toBeUndefined()
+ })
+
it('keeps `paused` through a `done` event — same as `hibernated`, and through a cold restart (this store never clears it on its own)', async () => {
vi.stubGlobal('localStorage', memStorage())
const { useAgentStatus } = await import('./agentStatus')
diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.ts
index 655a14feb..54348ad42 100644
--- a/src/renderer/state/agentStatus.ts
+++ b/src/renderer/state/agentStatus.ts
@@ -436,7 +436,15 @@ export function createAgentStatusSession(
// Same self-heal, same reasoning: a live hook event is proof the CLI is running, whatever
// brought it back (our own resume, or the user typing the launch line by hand) — a standing
// `paused` would be wrong, and (unlike a cold restart) this IS evidence, not a guess.
- if (alive && prev.paused) next.paused = undefined
+ if (alive && prev.paused) {
+ next.paused = undefined
+ // Goes with the flag, UNLESS `hibernated` still owns it (shallow pause clears both flags
+ // together above, in which case this is already undefined) — the deep-pause case has no
+ // `hibernated` to protect it, so without this an in-memory record describing a pane that
+ // is now demonstrably running something else would linger, and stand as permission for
+ // the next deep pause to be typed into recognizing a pane it never measured.
+ if (!next.hibernated) next.hibernatedPane = undefined
+ }
const byId = { ...s.byId, [id]: next }
// `state` itself is transient, so a plain transition writes nothing — but dropping a
// PERSISTED flag has to reach disk, or a relaunch would restore a hibernated/paused node
diff --git a/src/renderer/terminal/hibernation-policy.test.ts b/src/renderer/terminal/hibernation-policy.test.ts
index ba62b88c0..5e8c5d51e 100644
--- a/src/renderer/terminal/hibernation-policy.test.ts
+++ b/src/renderer/terminal/hibernation-policy.test.ts
@@ -14,6 +14,7 @@ const base = (id: string, over: object = {}) => ({
wired: true,
offscreen: true,
hibernated: false,
+ paused: false,
remote: false,
recurring: false,
liveSubagents: false,
@@ -110,6 +111,14 @@ describe('planHibernation', () => {
expect(planHibernation([base('a', { hibernated: true })], NOW, cfg)).toEqual([])
})
+ it('excludes an already-PAUSED node even with `hibernated` unset — the deep "pause & end session" case, whose tmux was recycled rather than merely exited', () => {
+ // `hibernated: false` here on purpose: this is exactly the shape a deep-paused node has, and
+ // `!c.hibernated` alone would still admit it — `paused` is the only field that catches it.
+ expect(
+ planHibernation([base('a', { hibernated: false, paused: true })], NOW, cfg)
+ ).toEqual([])
+ })
+
it('excludes REMOTE sessions here, not only at the exit — the batch is a slice', () => {
expect(planHibernation([base('a', { remote: true })], NOW, cfg)).toEqual([])
// The reason it must be excluded at PLAN time: two remote nodes at the head of the oldest-idle
diff --git a/src/renderer/terminal/hibernation-policy.ts b/src/renderer/terminal/hibernation-policy.ts
index 0fae4d8e6..25aacbe9a 100644
--- a/src/renderer/terminal/hibernation-policy.ts
+++ b/src/renderer/terminal/hibernation-policy.ts
@@ -85,6 +85,17 @@ export interface HibernationCandidate {
liveBackgroundTask: boolean
/** When this node's last hook event landed. Absent = never seen ⇒ never eligible. */
lastEventAt?: number
+ /**
+ * Already `paused` (agentStatus.paused). Excluded for the same reason `hibernated` is: nothing
+ * left to reclaim — but ALSO because a deep "pause & end session" node has `hibernated` UNSET
+ * (its tmux session was recycled, not merely exited), so `!c.hibernated` alone would still admit
+ * it. Without this field, an offscreen deep-paused node whose SessionEnd hook POST was dropped
+ * (a server hiccup, a downed tunnel) could sit at `state: 'done'` with a stale `lastEventAt`,
+ * pass every other filter, and have Eco's sweep KILL_LINE + `/exit` typed into its already-bare
+ * shell — the exact class of mistake `alreadyExited` (the manual pause closure's own skip) exists
+ * to prevent, reachable here through the automatic sweep instead.
+ */
+ paused: boolean
}
export interface HibernationConfig {
@@ -145,6 +156,7 @@ export function planHibernation(
.filter(
(c) =>
!c.hibernated &&
+ !c.paused &&
!c.remote &&
c.wired &&
c.offscreen &&