Skip to content

fix(sidebar): Hide sleeping keeps a live remote workspace row through a transient PTY gap - #29325

Merged
nwparker merged 1 commit into
mainfrom
nwparker/hide-sleeping-pty-gap
Oct 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/hide-sleeping-pty-gap

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​479 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​479
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​231 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​219

ELI5

With "Hide sleeping" on, a remote workspace that still has an open terminal could vanish from the sidebar for one frame when you clicked a different workspace, so every row below it jumped up and snapped back. The sidebar now waits a moment before deciding a workspace that was just awake has gone to sleep.

What Changed

Before: under "Hide sleeping", an idle remote workspace (open terminal, agent finished long ago) blinked out of the list for a single frame on some workspace switches. The reporter measured it on a paired orca serve host: seven rows on every frame but one.

After: the row stays put. A workspace you deliberately put to sleep, or whose last terminal tab you closed, still disappears straight away.

Mechanism: the "Hide sleeping" sweep keeps an idle workspace only while one of its tabs has a live terminal in ptyIdsByTabId. Several paths that reconnect a pane to its terminal (SSH reconnect, remote-runtime reattach, deferred session reattach, codex restart) clear that entry and then write it back in a separate store update. During that one update the workspace looked asleep and was swept out.

  • sidebar/sleeping-sweep-retention.ts: a small state machine. A workspace that was seen live and now reads inactive keeps its row for 1.5 s. A workspace that was never seen live gets no grace, so this cannot bring back a row that should have been hidden from the start. Appearing is still immediate.
  • listing/use-sleeping-sweep-retention.ts: runs that state machine with the same hasActiveWorkspaceActivity check the sweep uses, so there is no second copy of the liveness rule. The grace only applies while the gap is unverifiable, meaning a terminal tab is still open and has no binding. An explicit sleep (hasWorktreeSleepIntent) or having no tabs left is definitive and sweeps right away. The state is written only after React commits, so abandoned renders can't change it, and one timer re-runs the sweep when the window expires.
  • desktop-workspace-row-facts.ts / compute-visible-worktrees.ts: a new sleepingSweepExemptWorktreeIds option that only answers the "is sleeping" question. Unlike forcedVisibleWorktreeIds, it does not bypass the repo, host or kind filters.

Why

An empty binding on a tab that is still open doesn't prove the session is asleep or has exited. It is unverifiable for a moment, and the sweep was treating it as asleep. Fixing it where the sidebar reads the state covers every rebind path at once. The alternatives were weaker:

  • Fixing each producer: there are many paths that clear and then rebind, and remote-runtime recovery state lives outside the zustand store, so no selector can see that a rebind is in progress.
  • Producer-side retention: fix(runtime): stop a remote-typed terminal hidden on the host from reconnecting on every send #29252 (the host keeps a remounting leaf's PTY) and the existing pending-handle retention in web-session-tabs-sync/terminal-build.ts already cover the host graph and the mirrored snapshot. The client-side pane clear-then-rebind paths remain, and this change covers them.

The one trade-off is that a row whose last live terminal exits while its tab stays open lingers for up to 1.5 s before it is swept.

This rebuilds contributor PR #16001 by @mmarabel on current main, with credit. Main had moved the sweep into the shared row filters, so the exemption is now a fact-reader input. I also added the immediate-sweep rules for a deliberate sleep and for a closed last tab.

Linked Issue

Fixes #15996

Visual Proof

N/A: the fix removes a one-frame reflow that does not reproduce on demand. The hook tests cover it by driving the real store through the gap.

Testing

  • use-visible-worktrees-retention.test.tsx drives useVisibleSidebarWorktrees against the real store. It covers a one-commit PTY gap keeping the row, StrictMode and Suspense commit safety, the window expiring, and a deliberate sleep or closed last tab sweeping immediately. On the unpatched hook, 5 of these tests fail.

  • sleeping-sweep-retention.test.ts covers the state machine. hide-sleeping-transient-pty-gap.test.ts covers the issue scenario through computeVisibleWorktreeIds, including that the repo filter still wins over a grace window.

  • pnpm tc, pnpm run check:code-quality:changed, and every sidebar test suite pass (368 files).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only, with no wire, IPC or platform changes. It doesn't depend on the host type, so it applies the same way to SSH, paired orca serve/orcad, and local. Folder workspaces go through the same sweep. Cost is one O(workspaces) pass inside memos that already recompute on the same inputs, plus at most one pending timer.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…sient PTY gap

A pane that rebinds its PTY clears the tab's live binding one commit before
re-registering it. Under Hide sleeping an open-but-idle remote workspace hung on
that binding alone, so its row was swept out and back for one frame. The sweep
now treats a still-open tab with no binding as unverifiable and keeps a row that
was live for a short settle window; a deliberate sleep or a closed last tab
still sweeps immediately.

Fixes #15996

Co-authored-by: mmarabel <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e2be4023-2650-4174-9802-ee64648c986f
📥 Commits

Reviewing files that changed from the base of the PR and between ac015cd and 60cbc31.

📒 Files selected for processing: 9
  • src/renderer/src/components/sidebar/compute-visible-worktrees.ts
  • src/renderer/src/components/sidebar/desktop-workspace-row-facts.ts
  • src/renderer/src/components/sidebar/hide-sleeping-transient-pty-gap.test.ts
  • src/renderer/src/components/sidebar/sleeping-sweep-retention.test.ts
  • src/renderer/src/components/sidebar/sleeping-sweep-retention.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-sleeping-sweep-retention.ts
  • src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees-retention.test.tsx
  • src/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees.ts
  • src/renderer/src/lib/worktree-activity-state.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit a49295f into main Oct 16, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Hide sleeping transiently drops a remote workspace row from the sidebar for one frame when switching workspaces

1 participant