Repository navigation
Conversation
…mselves Sleep kills a workspace's PTYs but leaves it in the terminal workbench's mounted set, which is only pruned when a worktree is deleted. Its panes then cold-park like any hidden workspace, and when the park verdict flips back they remount, reattach to the preserved session ids, miss, and fall through to a fresh cold-restore spawn that re-runs the agent's --resume. The row un-sleeps minutes later with no user action. Sleeping now latches the on-demand park, which holds until the workspace is revealed or background-woken. The on-demand eligibility gates are skipped for that reason: a workspace with no surviving PTY can never satisfy them, and refusing would leave it mounted and re-spawnable.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds reason-aware manual terminal worktree parking. Workspace sleep requests parking with the Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The workspace sleep parking changes have no supported unresolved merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Park reason plumbing —
requestManualTerminalWorktreeParkand the pending queue now carry a'manual' | 'workspace-sleep'reason end-to-end, withtakePending/takeAllreturning the reason instead of a bare boolean/string list. - Sleep latch —
runSleepWorktreesparks the workspace ('workspace-sleep') only after the final teardown step succeeds, so a partially-slept workspace never earns the latch. - Gate bypass —
useManualTerminalWorktreeParkingskips the on-demand eligibility gates for the sleep reason (a dead-PTY workspace can never pass them) while preserving the gates and toast for manual parks. - Latch release — released on reveal (existing effect) and on
BACKGROUND_MOUNT_TERMINAL_WORKTREE_EVENT. - Tests — a new 4-case latch test plus extended sleep-flow tests covering latch ordering and the no-park-on-failure parameterization.
ℹ️ On the two reviewer questions
1. Should the latch survive a renderer reload? In-memory is correct. After a reload nothing auto-mounts a hidden workspace, so there is no re-wake path to defend against; persisting would add a storage/schema surface for no benefit.
2. Is releasing on any background mount too broad? No, for the cases that matter. Every requestBackgroundTerminalWorktreeMount caller is a genuine "this worktree's terminals are needed" signal (mobile wake, agent launch, CLI reveal, browser-automation bootstrap). The residual per-worktree-vs-per-tab granularity — a single-tab mount releases the whole worktree's latch — is already scoped by the pre-existing restoreOnTabOpenOnly filtering in wake-sleeping-agents-in-background.ts, which keeps a phone tap from respawning an explicitly-slept workspace's finished agents. The one case that does release the latch (a phone resuming a still-working agent of a slept workspace) is the intended behavior, since that agent should wake. No change required; the current design holds.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Superseded by #18051 (and its design source #13343 by @mmarabel). Converting to draft rather than closing, so it isn't lost if those stall. I opened this before finding the two existing PRs for the same bug. Having reviewed both, #18051 fixes it at the better seam and I'd rather help land that than compete with it. Why theirs wins. I gated the remount (latch the on-demand terminal park on sleep, so the panes never come back). @Jinwoo-H gates the connect. Verifying my own change, I found the park gate leaks where theirs doesn't — What I'm contributing instead, posted on #18051:
No code taken from either PR, so no co-authorship is owed here — the credit that matters is on those PRs. Possibly still worth salvaging, separately from this bug: sleep's stated purpose in |
|
Closing in favour of #20075, which is @Jinwoo-H's #18051 rebased onto current main and verified (their regression test still fails on main, passes there). My park-latch approach is not being merged — the connect-entry gate covers remount paths the park gate cannot. Field evidence and review notes from here are carried into #20075. |

ELI5
You put a workspace to sleep. Twenty minutes later it's awake again, with your agent relaunched, and you never touched it. Sleep killed the terminals but forgot to tell the UI to stop re-opening them — so the next time Orca shuffled hidden workspaces in the background, it tried to reconnect to the terminals sleep had just killed, failed, and started fresh ones. Now sleeping also tells the UI "leave this one alone until I come back."
What Changed
requestManualTerminalWorktreeParktakes areason('manual' | 'workspace-sleep').'workspace-sleep'park skips the on-demand eligibility gates. A slept workspace has no surviving PTY, socanManuallyParkTerminalWorktreeRendererscan never pass (isParkRestorableTerminalPtyis false for a dead local PTY, and the gate is off entirely whenterminalHiddenViewParkingis disabled) — and it would toast "These terminals cannot be parked safely." on every sleep. Manual parks keep the gates and the warning.runSleepWorktreeslatches that park after the last teardown step, so only a workspace that fully slept earns it.BACKGROUND_MOUNT_TERMINAL_WORKTREE_EVENT— a navigation-free wake (mobile, CLI reveal) only suspends the park for its 3s measure window, so a latch left set would unmount the panes it just woke.Why
Fixes the "no durable stay-dead-until-Wake gate" this issue identifies.
Sleep kills the workspace's PTYs but keeps the tab records and layout pty ids (
keepIdentifiers: true), and leaves the workspace inmountedWorktreeIdsRef— whichterminal-cold-activation.tsonly prunes when a worktree leavesworkspaceSurfaceIds, i.e. when it is deleted. The panes then cold-park like any hidden workspace. When the park verdict flips back, they remount,runDeferredSessionReattachChoicereattaches to the restored session id, misses, andhandleReattachResultfalls through tostartFreshColdRestoreAgentResume— a fresh spawn under the same deterministic session id, re-running the agent's--resume. Live PTYs reappear,hasActiveWorkspaceActivitygoes true, and the sidebar row un-sleeps.From my own daemon log — every respawn trails another hidden workspace's pane remounting in the same sweep by ~100ms.
crash-closerattaches (its PTY is alive); the slept workspace spawns (sleep killed its PTY):Three sleeps (04:03, 04:31, 04:59) produced three self-wakes (04:27, 04:59, 05:15) at irregular 16–28 min gaps matching park-verdict churn, with no sidebar activation for that workspace in between.
Why park rather than block the spawn: the reattach→cold-restore fallback is correct behaviour for a real wake — it is how waking a slept workspace restores its agents. The bug is that the panes remount at all. Keeping them parked leaves the existing, tested wake path untouched; reveal releases the latch and wake proceeds normally.
Linked Issue
Fixes #10205
Visual Proof
N/A — the change has no visual delta to capture. What it fixes is the absence of an event: a slept row that previously re-appeared after 16–28 minutes now stays slept. The daemon-log evidence above is the observable signal;
tests/e2e/terminal-sleep-wake-restore.spec.tscovers the visible sleep→wake path and still passes.Testing
Tested on macOS (local execution host). Not exercised on Windows/Linux/SSH — the change is renderer-only with no platform-dependent code (no paths, processes, shells, or native modules).
Added
terminal-worktree-sleep-park-latch.test.tsx(4 cases): the sleep reason parks a workspace the gates would refuse; a manual park still refuses and warns; the latch releases on reveal; the latch releases on a background wake. Extendedsleep-worktree-flow.test.tswith the latch, its ordering, and a parameterised case that no park is latched when terminal shutdown or host suspension fails.pnpm tc— cleanpnpm test src/renderer/src/components src/renderer/src/lib— 2949 files / 24 656 tests passpnpm test src/renderer/src/components/sidebar src/renderer/src/components/terminal-pane— 745 files / 6790 tests passtests/e2e/terminal-sleep-wake-restore.spec.ts(electron-headless) — passes: slept terminal output restores and accepts fresh input after wakeVerified while reviewing, not just assumed:
subscribeToPtyData— they never connect or spawn, so parking a slept workspace cannot itself start a process.handlePtyExitbails onconsumeSuppressedPtyExitbefore any parked-exit tab-close logic, so the sleep kill cannot close the slept tabs.terminalHiddenViewParkingoff — which is exactly the configuration where the eligibility gate would have refused.Residual risk: the latch is component state, so it is lost on renderer reload; after a restart nothing mounts a hidden workspace anyway, so this is not a re-wake path. Stale ids for deleted worktrees are never pruned from the set — inert (membership is only tested against live surfaces) and bounded by worktree count. As before this PR, a worktree-level park bypasses
terminalSshViewParking; for a slept SSH workspace there is no scrollback to lose, since sleep already captured buffers intobuffersByLeafId.AI Disclosure
Investigated and implemented with Claude Opus 4.6 in Claude Code.
Review
Reviewed against
readiness-checklist(two passes). The first pass caught a real defect in the first draft of this fix: the latch was only released on reveal, so a mobile/CLI background wake would have re-parked the panes ~3s later, once the measure window closed. That is theBACKGROUND_MOUNT_TERMINAL_WORKTREE_EVENTrelease above, with a test. Second pass: no candidate findings.Reviewer questions worth a second opinion: