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(agents): address pause-session review feedback
Mina Sameh01466058d8e8
diff --git a/CLAUDE.md b/CLAUDE.mdindex d55f2e114..5aa35d2b5 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -466,12 +466,33 @@ Lifecycle, by intent:process. (2) **Fire-time re-asks**: still-offscreen, remote, eligibility — a plan-time verdictis stale by seconds. (3) `hibernated` **self-heals** on live hook states + SessionStart (neveron `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. (4) **Ordering with offscreen release**:+ 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+ release**:Eco defers the Phase-2 viewer release until the node hibernates (hard cap idle+offscreen), butONLY when the idle clock is known (`idleKnown` — `lastEventAt` is transient, so after an apprestart nothing can hibernate and deferring would make Eco a memory regression). Eco isstructurally inert for sessions with no turn in the current app run — documented follow-up.+ The deferral is also unaware of `paused`: a deep-paused node's freshly recycled shell keeps its+ xterm alive until the hard cap, waiting for a hibernation that (being already exited, or having+ no CLI to exit) can never come — a second documented follow-up.Device checklist (8 items) in PR #130 — owed before recommending Eco to anyone.+- **"Pause session"** (manual, or via Eco when `settings.agentHibernationPersistAcrossRestart` is+ on) → `agentStatus.paused`, a persisted flag alongside `hibernated` with ONE job: stop a node+ from coming back on its own. Two depths, chosen per node: shallow — identical to an Eco exit+ (`registerAgentPause`'s `pause` closure reuses `performExitPhase`), plus `paused` — or "pause &+ end session" — the same recycle `restartAgentNode(…, restartShell: true)` uses+ (`transport.recycle` + a `respawnNonce` bump), so the node comes back `fresh` next time, with no+ live tmux session to hold memory. Two pure predicates in `terminal/hibernation-policy.ts` pin the+ contract: `shouldColdResume` (a `fresh` mount must not auto-relaunch a paused node — see Cold+ restore above) and `shouldAutoWake` (the mount-timer, visibility-edge, and kanban-card-modal-open+ auto-wake triggers must not fire for a paused node, hibernated or not — only an explicit Resume,+ 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.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@@ -503,7 +524,11 @@ session (you can't keep a live OS process across a reboot):renderer re-launches the agent CLI: `resumeCommand(agentId, sessionId)` (from the session idpersisted in `agentStatus` localStorage — `claude --resume`, `codex resume`, `gemini--resume`) when known, else the bare `launchCmd`. The one-shot `data.initialCommand` still wins- on the very first open, so the agent is never double-launched.+ on the very first open, so the agent is never double-launched. **The one exception: a `paused`+ node** (see "Pause session" below) skips this auto-relaunch — that is the entire point of the+ flag — and instead records the pane its fresh shell settled on (`agentStatus.hibernatedPane`),+ so a later explicit Resume can recognize it even for a default shell outside the wake's+ `isShellCommand` allowlist.### We have our own VT emulator — check it before asking tmuxdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 46c576882..0e272d1d8 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -275,7 +275,11 @@ import {type BulkRestartPlan,type RestartOutcome} from '../terminal/agent-restart'-import { planHibernation, HIBERNATE_SWEEP_MS } from '../terminal/hibernation-policy'+import {+ planHibernation,+ shouldAutoWake,+ HIBERNATE_SWEEP_MS+} from '../terminal/hibernation-policy'import { buildHibernationCandidates } from '../lib/hibernationCandidates'import { applyLoopDismiss } from '../lib/loopCard'import { prepareQuickOpenFiles, type QuickOpenIndexedFile } from '../lib/quickOpenSearch'@@ -7861,9 +7865,12 @@ export function Canvas() {// not hibernated (the node re-reads the flag itself). `paused` is excluded — same rule as// the mount-timer and visibility-edge auto-triggers: a paused node must not auto-resume on// ANY reveal, the card modal included, or "only an explicit Resume brings it back" would be- // false the moment the user opens the card. The modal shows the PAUSED chip; Resume is still- // reachable from the node menu.- if (id && !useAgentStatus.getState().byId[id]?.paused) wakeHibernatedNode(id)+ // false the moment the user opens the card (`shouldAutoWake`). The modal shows its own+ // clickable PAUSED chip for that case (CardModal.tsx); the node menu's Resume works too.+ if (id) {+ const st = useAgentStatus.getState().byId[id]+ if (shouldAutoWake(st?.hibernated, st?.paused)) wakeHibernatedNode(id)+ }}, [])const onPaletteQuery = useCallback((q: string) => {diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsxindex aee9629e6..5d8019863 100644--- a/src/renderer/components/kanban/CardModal.tsx+++ b/src/renderer/components/kanban/CardModal.tsx@@ -14,6 +14,11 @@ import {CARD_MODAL_MIN_H} from '../../state/cardModalSize'import { useSession } from '../../session/session'+// The same wake trigger the canvas node's SLEEPING/PAUSED chip and mount/visibility auto-wakes+// use — NOT a bespoke resume path, so a click here gets the same WakeInputBuffer protection and+// retries. Importing one function out of the canvas node module is safe: TerminalNode.tsx already+// imports from `components/kanban/*`, and none of those re-import CardModal.+import { wakeHibernatedNode } from '../../nodes/TerminalNode'import type { ProjectKanban } from '@shared/types'import type { KanbanSession } from './KanbanView'import { BoardLogPanel } from './BoardLogPanel'@@ -57,6 +62,7 @@ export function CardModal({ session, columnTitle, board, onChangeBoard, onClose,// StickyNode's toggle, so the canvas and the card can't disagree about how a note reads).const [editingNote, setEditingNote] = useState(false)const agentSessionId = useAgentStatus((st) => st.byId[session.id]?.sessionId)+ const paused = useAgentStatus((st) => !!st.byId[session.id]?.paused)const [naming, setNaming] = useState(false)// Comments & activity panel: OPEN by default in the modal; the header 💬 collapses it. The// choice is remembered (localStorage) — once collapsed, later cards open collapsed too.@@ -254,6 +260,20 @@ export function CardModal({ session, columnTitle, board, onChangeBoard, onClose,when the node is being driven even though the drive lands on the CANVAS webview, notthis modal's — which is what the user needs to know (Task 6.3). */}{isBrowser && <BrowserDrivingIndicator nodeId={session.id} />}+ {isTerminal && paused && (+ // Opening the card is one of the modal-open wake triggers `TerminalNode` publishes+ // (see `setKanbanModalNode`), and it deliberately skips a PAUSED node — so the modal+ // must say why the session is a bare shell instead of showing nothing. Clickable via+ // the same wake trigger the canvas chip uses.+ <button+ className="kanban-badge kanban-badge--sleeping"+ style={{ cursor: 'pointer', border: 'none' }}+ title="Session paused — click to resume"+ onClick={() => wakeHibernatedNode(session.id)}+ >+ PAUSED+ </button>+ )}{isTerminal && (<>{/* Same context-window pill + popover as the node header (null until usage data). */}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 0a8c50101..b9c394aa7 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -124,6 +124,7 @@ import {type PauseOutcome,type ResumePhaseOutcome} from '../terminal/agent-restart'+import { shouldAutoWake, shouldColdResume } from '../terminal/hibernation-policy'import { WakeInputBuffer } from '../terminal/wake-input-buffer'import { FindBar } from '../components/FindBar'import { IconSearch, IconChat, IconMic, IconReload, IconEye, IconEyeOff, IconGrid } from '../components/icons'@@ -1528,8 +1529,9 @@ export function TerminalNode({const t = setTimeout(() => {// A `paused` node never auto-wakes, mount included — the trigger published above (and the// chip's own click) remain the explicit way back. `hibernated`-only nodes are unaffected:- // this is the everyday Eco auto-resume-on-view path.- if (isNodeWatched(id) && !useAgentStatus.getState().byId[id]?.paused) wakeRef.current()+ // this is the everyday Eco auto-resume-on-view path. See `shouldAutoWake`.+ const stMount = useAgentStatus.getState().byId[id]+ if (isNodeWatched(id) && shouldAutoWake(stMount?.hibernated, stMount?.paused)) wakeRef.current()}, WAKE_MOUNT_DELAY_MS)return () => {clearTimeout(t)@@ -3072,7 +3074,7 @@ export function TerminalNode({if (data.initialCommand) {writeWhenShellReady(data.initialCommand)updateNodeData(id, { initialCommand: undefined })- } else if (fresh && agentId && canResume(agentId) && !pausedNow) {+ } else if (fresh && agentId && canResume(agentId) && shouldColdResume(pausedNow)) {// Cold restart of an agent node: the live agent is gone, so re-launch it. Resume the// prior conversation by its session id when we have one; otherwise start the agent// fresh. Plain terminals get nothing here — just the restored shell.@@ -3893,8 +3895,10 @@ export function TerminalNode({// …and the wake edge: a hibernated node the user has just panned back to gets its// conversation resumed before they can reach for the chip. No-op (one map lookup) for a// node that is not hibernated, which is every node in the default case. A `paused` node is- // excluded — see the mount-timer trigger above for why.- if (visible && !wasVisible && !useAgentStatus.getState().byId[id]?.paused) wakeRef.current()+ // excluded — see the mount-timer trigger above for why (`shouldAutoWake`).+ const stVisible = useAgentStatus.getState().byId[id]+ if (visible && !wasVisible && shouldAutoWake(stVisible?.hibernated, stVisible?.paused))+ wakeRef.current()// A visible node is not in an offscreen stretch at all — the next hidden edge starts a// fresh clock for the Eco deferral's cap.if (visible) offscreenSinceRef.current = nulldiff --git a/src/renderer/terminal/hibernation-policy.test.ts b/src/renderer/terminal/hibernation-policy.test.tsindex fc7efba9c..ba62b88c0 100644--- a/src/renderer/terminal/hibernation-policy.test.ts+++ b/src/renderer/terminal/hibernation-policy.test.ts@@ -1,5 +1,10 @@import { describe, it, expect } from 'vitest'-import { planHibernation, HIBERNATE_BATCH_MAX } from './hibernation-policy'+import {+ planHibernation,+ shouldAutoWake,+ shouldColdResume,+ HIBERNATE_BATCH_MAX+} from './hibernation-policy'const base = (id: string, over: object = {}) => ({id,@@ -127,3 +132,31 @@ describe('planHibernation', () => {expect(planHibernation([], NOW, cfg)).toEqual([])})})++describe('shouldColdResume — a fresh cold restart must not relaunch a PAUSED node', () => {+ it('refuses when paused', () => {+ expect(shouldColdResume(true)).toBe(false)+ })+ it('allows the ordinary cold-restore auto-resume when not paused', () => {+ expect(shouldColdResume(false)).toBe(true)+ expect(shouldColdResume(undefined)).toBe(true)+ })+})++describe('shouldAutoWake — the mount timer / visibility edge / kanban modal-open auto-triggers', () => {+ it('fires for an ordinary hibernated (Eco) node, unaffected by this feature', () => {+ expect(shouldAutoWake(true, false)).toBe(true)+ expect(shouldAutoWake(true, undefined)).toBe(true)+ })+ it('never fires for a PAUSED node, hibernated or not — only an explicit Resume may', () => {+ // shallow pause: hibernated AND paused+ expect(shouldAutoWake(true, true)).toBe(false)+ // deep "pause & end session": tmux recycled, hibernated never set, only paused+ expect(shouldAutoWake(false, true)).toBe(false)+ expect(shouldAutoWake(undefined, true)).toBe(false)+ })+ it('does not fire for a node that is neither hibernated nor paused (nothing to wake)', () => {+ expect(shouldAutoWake(false, false)).toBe(false)+ expect(shouldAutoWake(undefined, undefined)).toBe(false)+ })+})diff --git a/src/renderer/terminal/hibernation-policy.ts b/src/renderer/terminal/hibernation-policy.tsindex 39f40b00c..0fae4d8e6 100644--- a/src/renderer/terminal/hibernation-policy.ts+++ b/src/renderer/terminal/hibernation-policy.ts@@ -92,6 +92,41 @@ export interface HibernationConfig {idleMinutes: number}+/**+ * "Pause session" (see agentStatus.paused) is a persisted flag with exactly one job: stop a node+ * from coming back on its own. These two pure predicates are the whole of that job — extracted so+ * the promise stays pinned by a unit test instead of only by reading the inline condition at each+ * of the several call sites that must honor it (a cold restart, a mount-time reveal, a visibility+ * edge, and a kanban card modal open all ask one of these two questions before acting).+ */++/**+ * Should a `fresh` cold restore (reboot, first open, a reaped server — see TerminalNode's cold-+ * restore comment) auto-relaunch the agent CLI? The one thing `paused` exists to prevent is+ * exactly this: an ordinary cold restore always resumes, and `paused` is the deliberate exception+ * that survives it. Every OTHER fact that gates the relaunch (is this `fresh`, is there an agent,+ * can it be resumed) is unrelated to pausing and stays inline at the call site.+ */+export function shouldColdResume(paused: boolean | undefined): boolean {+ return !paused+}++/**+ * Should an AUTOMATIC wake trigger fire — the mount-time reveal, the offscreen→visible+ * IntersectionObserver edge, or opening a kanban card modal? Only for a node that is ordinarily+ * hibernated (Eco) and NOT paused: a paused node (whichever depth paused it — a warm hibernated+ * pane, or a freshly recycled shell after "pause & end session") must wait for an EXPLICIT Resume+ * on every reveal, not just the first one, or "only Resume brings it back" would be false the+ * moment the user looks at the node. The explicit paths (the SLEEPING/PAUSED chip's own click, the+ * node-menu Resume action) are NOT gated on this — they call the wake trigger directly.+ */+export function shouldAutoWake(+ hibernated: boolean | undefined,+ paused: boolean | undefined+): boolean {+ return !!hibernated && !paused+}+/** The node ids to hibernate now: oldest-idle first, at most `HIBERNATE_BATCH_MAX`. */export function planHibernation(candidates: HibernationCandidate[],