Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (13)
🚧 Files skipped from review as they are similar to previous changes (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change keeps sleep intent marked for successfully slept worktrees and marks background worktrees before teardown. Deferred PTY connections now suppress reattachment and fresh spawning for deliberately slept panes unless explicit startup exists. Activation, PTY binding, removal, and purge clear sleep intent. New unit and end-to-end tests validate intent lifecycle, cold remount behavior, and deliberate wake. Merge Risk: ⚪ Minimal · up to The deliberate-sleep lifecycle changes have no identified merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes address issue Full details: Description checkExplanation The description is detailed and covers the problem, implementation, rationale, linked issue, testing, compatibility, and AI disclosure. It omits the required Visual Proof section and several checklist sections, but it is otherwise substantially complete and directly related to the changes.
✨ 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.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: c791f003-c016-4e47-855e-69738b65905e
📒 Files selected for processing (13)
src/renderer/src/components/sidebar/sleep-worktree-flow.test.tssrc/renderer/src/components/sidebar/sleep-worktree-flow.tssrc/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.tssrc/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.tssrc/renderer/src/components/terminal-pane/pty-connection/deliberate-sleep-cold-start.test.tssrc/renderer/src/components/terminal-pane/pty-connection/deliberate-sleep-cold-start.tssrc/renderer/src/lib/wake-sleeping-agents-in-background.test.tssrc/renderer/src/lib/wake-sleeping-agents-in-background.tssrc/renderer/src/lib/worktree-activation-emptied-workspace-reseed.test.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/lib/worktree-sleep-intent.tssrc/renderer/src/store/slices/store-session-workspace-hydration.test.tssrc/renderer/src/store/slices/tabs-unread-and-focus.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
Important
The fix is sound and well-tested for the sidebar/wake paths, but the sleep marker's lifecycle has a gap: it is only released from four call sites, while many production activation paths call setActiveWorktree directly. Waking a slept workspace through one of those paths leaves the marker set indefinitely and silently suppresses bumpWorktreeActivity for an otherwise-live workspace.
Reviewed changes
- Persistent sleep marker —
worktree-sleep-intent.tsnow retains the per-worktree marker across a successful sleep (previously cleared infinally), andsleep-worktree-flow.tsmarks every target before teardown while clearing only failed worktrees. - Cold-start guard — new
shouldStayColdForDeliberateSleepindeferred-session-reattach-choice.tssuppresses the fresh spawn for a hidden, inactive, deliberately-slept pane; queued startups, visible panes, and the active worktree bypass it. - Explicit wake clearing —
worktree-activation.tsclears the marker on worktree and folder activation;wake-sleeping-agents-in-background.tsclears it even for record-less (plain shell) workspaces. - Tests — cold-start guard unit tests, fresh-spawn guards, background-wake release, restart hydration, and repeated-activation coverage.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found. The prior activity-suppression leak is now closed at the shared activation boundary.
Reviewed changes
- Centralized marker release —
clearWorktreeSleepIntentnow lives inside the non-nullsetActiveWorktreeboundary (set-active-worktree.ts:45) and the sharedsetActiveFolderWorkspaceboundary, so every direct activation caller (terminal-handle-links, launch-dashboard-agent, http-link-routing, file-preview, activity-thread-actions, restored-editor-owner, terminal-command-state, web-runtime selection) releases the marker. - Removed redundant per-helper clears —
activateAndRevealWorktree/activateAndRevealFolderWorkspacedropped their explicit clears, now covered by the store boundary. - Null preserved —
setActiveWorktree(null)skips the clear, keeping the marker through sleep teardown and workspace close. - Regression coverage — store-level tests for release-at-boundary and null-preservation, plus strengthened restart-hydration layout and repeated-activation identity assertions.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Scoped typecheck cache to the commit — the
typecheckjob's TypeScript incremental-state cache is now keyed on${{ github.sha }}with norestore-keys, so a fresh commit no longer restores a stale.tsbuildinfograph from an earlier commit on the same PR. The comment now explains the rationale (shared graphs across commits can retain stale symbol tables and emit diagnostics for declarations that exist on disk).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- TypeScript cache contract test —
config/scripts/pr-workflow-parallelism.test.mjsnow asserts the commit-scoped cache (keycontainsgithub.sha,restore-keysisundefined), matching the workflow change from the prior commit.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…oken Sleeping a workspace kills its PTYs but keeps its panes mounted and keeps each tab's session id as a wake hint. Any later remount of those panes (recovery, parking, portals) reattached that dead id, and the daemon's create-or-attach spawned a fresh shell, so slept workspaces revived on their own (#10205). The existing sleep-intent marker now outlives teardown and gates the deferred connect itself, so both the reattach and fresh-spawn arms stay cold. It is released by activating the workspace, by any PTY binding to one of its tabs (CLI, automation, client wake), and by purge. A queued startup still connects. Reproduces the community root cause from gatsby74 in #13343; the regression e2e remounts a slept hidden pane and fails on main. Co-authored-by: gatsby74 <[email protected]>
3e51e73 to
667d230
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Reviewed changes
This run reviewed the squashed rewrite that consolidates the sleep-intent handling into a single connect-entry gate and a bind-driven clear.
- Moved the cold-start gate to the connect entry —
run-deferred-connect.tsnow checkshasWorktreeSleepIntentimmediately beforesafeFit, so a deliberately slept pane skips both the reattach arm (its retained dead session id) and the fresh-spawn arm; a queued startup (session.paneStartup) still connects. - Clear-on-bind replaces several helper clears —
updateTabPtyId(terminal-pty-bindings.ts) releases the marker on any PTY bind; thesetActiveWorktree/setActiveFolderWorkspaceboundary clears remain. - Purge/remove clears —
removeWorktreeandbuildWorktreePurgeStaterelease the marker so a recreated worktree at the same path does not inherit a stale sleep. - Dropped
wakeSleepingAgentsForWorktreeInBackground/worktree-activationclear sites — the paired-client wake now relies on PTY bind to release the marker. - Reworked tests — a connect-guard unit suite (reattach, fresh-spawn, queued startup, released marker), a store lifecycle suite, and an e2e
slept-workspace-remount-wake.spec.tswith explicit non-vacuity assertions.
⚠️ Record-less client wakes no longer release the sleep marker
The description claims clear-on-bind "covers CLI, automation, and client wakes," but wakeSleepingAgentsForWorktreeInBackground no longer clears the marker and only produces a PTY bind when the workspace actually carries sleeping-agent records. Opening a manually-slept workspace that has no agent records (a plain shell) through a paired mobile/remote client runs activateManagedWorktree in the main process and never drives the renderer's setActiveWorktree nor binds a PTY, so the marker stays set and the desktop workspace remains cold. This diverges from the prior revision, which explicitly cleared the marker on that path.
The practical blast radius is narrow: the desktop user can still recover by clicking the workspace (activation clears the marker and the allDead branch remounts the dead panes), and a client-issued create with activate: true or a queued command still clears. But since this is exactly the wake route this PR's clear sites are meant to cover, it is worth confirming whether record-less wakes are expected to clear before merging.
Technical details
# Record-less client-wake marker release
## Affected sites
- `src/renderer/src/lib/wake-sleeping-agents-in-background.ts:167-176` — the `worktreeRecords.length === 0` early return now leaves the marker set; no `clearWorktreeSleepIntent` call remains in this module after the rewrite.
- `src/renderer/src/store/terminals/terminal-pty-bindings.ts:124-125` — the replacement clear-on-bind only fires on an actual PTY bind, which the record-less wake never produces.
## Required outcome
- Decide whether a paired client opening a manually-slept, agentless workspace should wake it. If yes, restore a `clearWorktreeSleepIntent(worktreeId)` on that wake path (before the early return), and add a lifecycle test for the record-less case. If no, state that record-less wakes are intentionally cold and nullify this section.
## Open questions for the human (optional)
- Is `resumeSleepingAgents`/`activateManagedWorktree` expected to wake agentless workspaces at all, or is it scoped to sleeping-agent records only?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
… cold A pane whose connect ran while its workspace was slept used to mark itself connected and stop; nothing re-armed it, so a wake that produced a live PTY before the user clicked (CLI create, background agent resume, split panes) left panes stranded. The connect now waits on the sleep marker and resumes when the marker clears, and a torn-down pane drops its listener. Tabs created with a live PTY clear the marker too, the sleep flow marks each workspace only when its own teardown starts, and purge forgets the marker without waking anything.
Activation clears the sleep marker after the set() that bumps dead tabs' generations, and the waiting pane only resumes its connect when its tab generation is still current. Otherwise the stale pane and its remounted successor both reattached the same session id on a deliberate wake.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Replaced the latch-cold gate with a wait-for-wake subscription —
run-deferred-connect.tsnow cancels the slept pane's scheduled connect and registers anonWorktreeSleepIntentClearedlistener that re-entersrunDeferredConnecton wake, so a remounted pane resumes its own connect instead of depending on a generation-bump remount. - Split marker release into clear vs forget —
worktree-sleep-intent.tsgainsforgetWorktreeSleepIntent(drops marker + listeners without notifying), andremove-worktree.ts/worktree-purge-state.tsnow use it so panes being unmounted are never woken by a purge. - Clear-on-
initialPtyId—terminal-tab-creation.tsreleases the marker when a tab is born with a live PTY (CLI/runtime create), closing the bind-less client-create wake route. - Moved the PTY-bind clear out of the store updater —
terminal-pty-bindings.tsnow clears afterset()(required once clear fires listeners that call back into the store), and the sleep flow marks each target per-worktree so a slow earlier teardown no longer holds later still-awake workspaces cold. - Extended tests — wake-resume, disposed-pane unsubscription, per-worktree marking, and the
WAIT FOR WAKEe2e verdict all assert the new behavior non-vacuously.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Generation guard on the wake resume — the
onWorktreeSleepIntentClearedcallback inrun-deferred-connect.tsnow re-reads the live tab and connects only when(currentTab?.generation ?? 0) === session.tabGeneration, mirroring the existingfresh-spawn-start.tsidiom, so a stale session no longer double-connects alongside the remounted pane. - Clear after the store commit —
setActiveWorktreenow callsclearWorktreeSleepIntentafter itsset(), so the activation generation bump is committed before the wake listeners fire and a waiting pane connects exactly once, in its remounted generation. - Regression test —
pty-connection-deliberate-sleep-guard.test.tsgainsdoes not connect a waiting pane whose tab was remounted by the wake, asserting non-connect after a clear plus generation bump.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
… after wake The wake listener looked the tab up by the pane's render id, which can be a unified id whose terminal tab lives under entityId, so the generation check declined forever for those panes. Mount, fresh spawn, and the wake listener now share one live resolver. The wait flag resets when the listener fires so a second sleep can hold the pane again, listener dispatch is guarded, folder activation clears after its own set(), and the sleep flow re-asserts the marker after each teardown while releasing a workspace the user activated meanwhile.
…indow A spawn resolving while shutdown was still awaiting the host bound a PTY and cleared the marker, waking every waiting pane mid-sleep; re-marking afterwards could not un-connect them. The sleep flow now scopes each teardown so binds in that window are not wakes. The e2e asserts a deliberate wake yields exactly one PTY, and the dispose test proves the listener is gone.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run reviewed the delta that resolves a waiting pane's tab by either id form, re-arms the wake wait, and re-asserts the marker after teardown.
- Shared tab resolution —
findTerminalTabForPanenow lives interminal-tab-id.ts, replacing the duplicated inline lookups thatconnect-pane-pty.ts(initialtabGeneration) andfresh-spawn-start.ts(shouldContinue) each carried, and the wake callback inrun-deferred-connect.tsresolves the live tab through the same helper by unified or terminal id. - Wake re-arm —
run-deferred-connect.tsresetswakeWaitStartedwhen the wake fires, so a pane that has already woken can be held again by a later sleep instead of being stranded with no listener. - Listener isolation —
clearWorktreeSleepIntentwraps each wake listener in try/catch so one pane's connect failure cannot strand its siblings or throw out of a store action. - Folder-workspace clear ordering —
set-active-folder-workspace.tsclears the marker after itsset(), matching the worktree path so a waiting pane wakes against the activated state. - Post-teardown re-assert —
sleep-worktree-flow.tsre-marks each workspace after suspension (or releases it if the user re-activated it mid-batch), so a PTY that binds during teardown cannot un-sleep a deliberately slept workspace. - Regression tests — unified-tab resume, re-arm after wake, post-teardown re-assert, mid-batch activation release, and sibling-listener notification are all asserted non-vacuously.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run reviewed the delta that replaces the post-teardown re-assert with a teardown-window guard.
- Teardown-window guard —
withWorktreeSleepTeardownmarks a worktree as tearing down for the duration of its shutdown, andclearWorktreeSleepIntentnow ignores any clear (PTY bind) that lands while that flag is set, so a spawn resolving mid-sleep can no longer wake the panes.forgetWorktreeSleepIntentclears the flag too, so a same-path recreation is not tainted. - Sleep flow simplification — the shutdown of browsers and terminals (plus the ephemeral-VM suspend) is wrapped in the guard, and the previous
else { markWorktreeSleepIntent(worktreeId) }re-assert branch is removed — the loop's initial mark now survives teardown because in-window clears are ignored, while the "activated mid-batch" clear is retained. - Exactly-once wake assertion — the e2e now waits 3s after the deliberate wake and asserts one live PTY and one host session, proving the waiting pane and its remounted successor do not both reattach.
- Sharpened tests — a lifecycle test proves an in-flight PTY bind is ignored during teardown (and honored after), and the disposed-pane test now also asserts the wake listener itself is torn down rather than just that connect is skipped.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Cross-review from #20039, which I opened tonight for the same bug before finding this PR. Your approach is better than mine and I'm standing mine down — details below, plus field evidence you didn't have. Independent field evidence: a third trigger that does reproduceYou noted Trigger A and Trigger B from #10205 don't repro on current Every respawn trails another hidden workspace's pane remounting in the same pass by ~100ms. Three sleeps (04:03, 04:31, 04:59) → three self-wakes (04:27, 04:59, 05:15), irregular 16–28 min gaps matching park-verdict churn, with no So: the mechanism isn't just theoretically reachable, it's the dominant trigger in a long-running session with many workspaces. Worth putting in the PR body — it answers the "is this a real user journey" question your scope note leaves open. Why your seam beats mineI fixed this by latching the on-demand terminal park on sleep, so the panes never remount. That works for the trigger above, but I verified it leaks on paths yours catches. In Gating at the connect entry is the right chokepoint. Two independent attempts converging on "the mechanism is the pane connect" is also worth something. Review notes
CreditThe design lineage is #13343 by @mmarabel, refined here. I'm not taking code from either PR — I'm closing my mechanism in favour of this one — but if any of the evidence or the park-path analysis above is useful in the PR body, please fold it in directly, no attribution needed. cc @mmarabel @gatsby74 |
|
Rebased this onto current Two things worth knowing:
If you'd rather land it yourself on |
|
Landed as #20075 — your five commits, rebased onto current For the record: the red CI here was never your change (stale localization catalog), and your regression test still discriminates on today's main — it fails on a clean Thanks for the thorough work on this one. cc @mmarabel @gatsby74 |

ELI5
Putting a workspace to sleep must keep it asleep until you open it. Before this fix, anything that re-mounted one of its terminal panes behind the scenes brought the shell back.
Scope, stated plainly: this closes the mechanism, not a reproduced user journey. The two field triggers reported in #10205 (sleeping the focused workspace revives a background-slept one; clicking an agent row or answering an agent question) do not reproduce on current
origin/main: I drove both through the sidebar against identical builds of main and this branch, and both stayed cold on main with zero connect attempts. The mechanism is still real and deterministic: any remount of a slept pane reattaches its retained dead session id and the daemon spawns a fresh shell. The e2e proves that by calling the shipping remount entry point directly.What changed
finally.tab.ptyIdas a wake hint, so a remount otherwise reattaches the dead session id and the daemon's create-or-attach spawns a fresh shell. A waiting pane resumes only if its tab generation is still current (resolved by either tab id form through one shared live lookup), so an activation that remounts the tab does not also connect the stale pane, and it re-arms so a later sleep can hold it again.setActiveWorktreeafter its generation bump,setActiveFolderWorkspace), on any PTY binding to one of the workspace's tabs (updateTabPtyId,createTabwith an initial PTY, which covers CLI, automation, and client wakes), and forgotten without waking anything on purge (removeWorktree,buildWorktreePurgeState).Why
The community root cause in #13343 by @gatsby74 is right: the wake is the renderer pane-connect path. This PR lands that design with the gate moved to the connect entry, so it covers both connect arms, and with clear-on-bind so non-activation wakes never leave a workspace stuck cold.
Linked issue
Fixes #10205 (STA-2449). Related: #13343 (source of the design, co-authored), #14705 (delete-focus fallback).
Testing
tests/e2e/slept-workspace-remount-wake.spec.ts: sleeps a workspace via the sidebar, activates another, forces a pane remount throughremountTerminalTabForRecovery(the production entry point used by terminal pane recovery: undeliverable or host-rejected input, stalled write pipeline, replay-guard wedge, the Retry button on the pane-owner-unverified toast; the direct-SSH retry chain and all-dead activation bump the tab generation the same way), and asserts zero live PTYs, zero host sessions, and no tab growth over 8s, then proves a deliberate click still wakes it. Fails onorigin/main(live PTY 1, host session 1, verdictREATTACH), passes here (verdictWAIT FOR WAKE (deliberate sleep), asserted).terminal-sleep-wake-restore,terminal-attention,terminal-cold-activation-deferral,local-cli-terminal-retentione2e pass locally.pnpm tc,check:code-quality:changedpass.origin/main. Those reports are from July builds.Compatibility and boundaries
activeWorktreeIdsOnShutdown, which excludes slept worktrees.AI disclosure
Implementation, reproduction, and review were AI-assisted; verification was run locally.