Repository navigation
Conversation
… transient PTY gap The hide-sleeping sweep is the only sidebar membership filter reading volatile state. A workspace with an open-but-idle session hangs on ptyIdsByTabId alone, so a single commit where a rebinding remote pane's entry is empty swept the row out and back in one frame. Delay removal instead of keying on an in-flight flag: direct-SSH panes expose one, but remote-runtime recovery lives outside the store where no selector can see it. Fixes stablyai#15996 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughAdded sleeping-sweep retention state with a 1.5-second grace period for previously active workspaces. Integrated activity detection, expiry scheduling, retained worktree IDs, and sleeping-workspace visibility filtering. Added tests for retention transitions, expiry, cleanup, transient PTY gaps, and repository filtering. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change keeps a recently active workspace visible for up to 1.5 seconds when its terminal binding briefly empties, which fixes the flickering sidebar rows. No merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: ⚪ Minimal · up to The change temporarily preserves recently active sidebar rows without adding privileged actions. Retention remains separate from other workspace filters, and its state and timers are confined to the displayed list. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 2 | ❌ 1 | ❓ 2❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (2 passed)
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
🧹 Nitpick comments (2)
src/renderer/src/components/sidebar/sleeping-sweep-retention.ts (1)
1-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the module comment.
Keep one concise comment that states the transient-PTY purpose and issue reference. The current block repeats implementation details and timing rationale.
As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."
Source: Coding guidelines
src/renderer/src/components/sidebar/hide-sleeping-transient-pty-gap.test.ts (1)
22-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse platform-independent fixture paths.
These fixture paths hardcode
/. Build them withpath.join, such aspath.join(tmpdir(), id), so the test data uses native paths on Windows.As per coding guidelines: "Use
path.joinor Electron/Node path utilities for file paths; never assume/or\."Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5a9516ad-e364-4bff-9e7f-1dc0304d0b19
📒 Files selected for processing (5)
src/renderer/src/components/sidebar/hide-sleeping-transient-pty-gap.test.tssrc/renderer/src/components/sidebar/sleeping-sweep-retention.test.tssrc/renderer/src/components/sidebar/sleeping-sweep-retention.tssrc/renderer/src/components/sidebar/visible-worktrees.tssrc/renderer/src/components/sidebar/worktree-list/listing/use-visible-worktrees.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
|
Thank you @mmarabel for the careful diagnosis and the hysteresis approach. Main had moved on a lot since this branch, so I rebuilt it on current main in #29325 with you credited as co-author. It's now merged. The rebuild also sweeps a workspace right away when it's deliberately slept or its last tab is closed. Closing this one in favour of it. |
Fixes #15996.
What this changes
With Hide sleeping workspaces on, a remote workspace's sidebar row could vanish for a single frame when a different workspace was activated. Every row below it — including the next project group header — jumped up by one row height and snapped back. The reporter measured it frame by frame on a 30 fps capture: seven workspace rows on every frame except one, where the row count read six and the
msn-studioheader moved 750 px → 659 px → 750 px.After this change the row stays put.
Why it happened
The hide-sleeping sweep is the only sidebar membership filter that reads volatile runtime state; every other filter is static configuration. It keeps a row visible when
hasActiveWorkspaceActivityholds, which needs one of a live PTY (tabHasLivePty(ptyIdsByTabId, tab.id)), an open browser tab, or an agent whose status is fresh and non-done.A workspace with an open-but-idle session satisfies none of those except the first, so it hangs on
ptyIdsByTabIdalone. That map is emptied and refilled whenever a pane rebinds its PTY, and a single commit where the entry is empty is enough to sweep the row out and back.worktree-activity-state.tsalready anticipates this class of gap:…but that mitigation only covers workspaces whose agent is currently working. An idle session falls through.
Approach
Removal hysteresis, not an in-flight flag.
Direct-SSH panes do expose an in-flight signal (
directSshPaneRetryByTabId), but remote-runtime panes keep their recovery state inRemoteRuntimePtyRecoveryState, a class held outside the zustand store, so no sidebar selector can observe a rebind in progress. Since the reported case is a runtime host rather than direct SSH, keying on a flag would not have covered it. Delaying removal covers every rebind path without requiring the producer to advertise itself.sidebar/sleeping-sweep-retention.ts— a pure state machine. A workspace that was observed active and now reads inactive gets aSLEEPING_SWEEP_SETTLE_MS(1.5 s) grace window; a workspace that was already asleep when the sidebar first saw it gets none, so this never resurrects a row that should have been hidden from the start. It reports the soonest expiry so the caller can wake.visible-worktrees.ts— newsleepingSweepExemptWorktreeIdsoption, applied only inside the!showSleepingWorkspacesblock. Deliberately not folded into the existingforcedVisibleWorktreeIds, which bypasses the repo, host and kind filters as well — a grace window must never outrank a filter the user set. Pinned by a test.worktree-list/listing/use-visible-worktrees.ts— derives the retained set from the samehasActiveWorkspaceActivitypredicate the sweep uses, so there is no second copy of the liveness logic to drift. A timer wakes the sweep at expiry; without it the final grace window would hold its row until some unrelated store change happened to recompute.Only removal is delayed. A workspace appearing is still immediate.
Trade-off
Closing a workspace's last session now leaves its row visible for up to 1.5 s before it sweeps. That direction was chosen deliberately: overshooting costs a row that lingers a beat, undershooting reproduces the jitter this fixes. It is a single exported constant if it wants tuning.
Tests
sleeping-sweep-retention.test.ts— the state machine: single-pass drop is retained; a sustained drop sweeps at the deadline; a workspace asleep on first sight gets no grace; the update is idempotent across a double-invoked render; the soonest of several open windows is reported; grace state is dropped when a workspace leaves the candidate set.hide-sleeping-transient-pty-gap.test.ts— the issue's scenario end to end throughcomputeVisibleWorktrees: the row survives a one-commit gap inptyIdsByTabId, still sweeps once the workspace is genuinely asleep, and a grace window does not survive the repo filter.Both new tests were confirmed to fail against the unpatched sweep before being committed.
pnpm lint,pnpm typecheck,pnpm testandpnpm buildall pass.Agent review notes
metaKey/ctrlKeyor accelerator surface is touched.live/unverifiable/exitedverdict vocabulary is not involved: an emptyptyIdsByTabIdentry is explicitly not treated as evidence the session died — that is precisely the misreading being corrected.isSleepingSweepExemptWorkspaceentry-point exemption is untouched.forcedVisibleWorktreeIdspath used by the agent send target is untouched and composes with the new option rather than replacing it.Setand oneMapkeyed by worktree id, both pruned to the candidate set each pass, so memory is bounded by workspace count. The retention pass is O(workspaces) and runs inside the memo that already recomputes on the same inputs. The wake timer is at most one outstandingsetTimeout, cleared on change and on unmount, and it stops arming as soon as no grace window is open.docs/STYLEGUIDE.mdhas no bearing here.Follow-up
#15999 tracks the producer side — identifying which commit empties
ptyIdsByTabIdfor a remote pane mid-session. This PR makes the sidebar robust to it; it does not explain it.