Skip to content

Add recursive sleep actions for workspace descendants - #11810

Merged
OrcaWin merged 4 commits into
mainfrom
sleep-ux
Jul 31, 2026
Merged

OrcaWin merged 4 commits into
mainfrom
sleep-ux

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add a conditional Sleep with Descendants (N) context-menu action that sleeps the selected workspace and every validated descendant recursively.
  • Make the existing cascading delete behavior explicit with Delete with Descendants….
  • Reuse the existing lineage projection so stale links, cycles, host boundaries, repository boundaries, and project boundaries are excluded.

Screenshots

Workspace descendant actions

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — focused Vitest coverage passed; the full matrix runs in CI.
  • pnpm build — the Electron E2E build passed; packaging runs in CI.
  • Added or updated high-quality tests that would catch regressions.

Additional validation:

  • 30 focused sidebar sleep/delete unit tests passed after the review fixes; 65 focused tests passed for the original implementation.
  • All 6 worktree-lineage.spec.ts Electron tests passed, including recursive parent/child PTY cleanup.
  • The CI-sensitive virtualized marquee case passed 10/10 locally after adding a preview-selection readiness check.
  • pnpm run check:code-quality:changed and pnpm run check:react-doctor:changed passed with zero findings.

AI Review Report

Reviewed recursive traversal boundaries, stale/cyclic lineage handling, sleepability filtering, multi-selection behavior, delete pending state, React hook dependencies, and Radix menu teardown ordering. Bot review found duplicated delayed-sleep and screenshot-evidence helpers; both were consolidated and revalidated. CI trace review also found an existing virtualized-marquee test starting on a card under slow-runner layout; the test now starts from guaranteed empty board padding and waits for observable preview state before forcing its large scroll jump.

Cross-platform review covered macOS, Linux, and Windows. This change adds no shortcuts, platform labels, filesystem paths, shell commands, or platform-specific APIs. It uses the existing Electron renderer sleep flow and validated host-aware lineage projection, preserving SSH and folder-workspace behavior.

Security Audit

No new dependency, authentication, secret, command-execution, filesystem-path, or IPC surface is introduced. Workspace IDs come from existing application state; recursive targets are restricted through the existing validated lineage projection before invoking the established sleep flow. No follow-up security work is required.

Notes

  • Screenshot evidence is attached through GitHub user attachments and is not committed to the repository.
  • An unrelated tab-menu timing failure passed on failed-job rerun; no product code was changed for it.

@OrcaWin
OrcaWin requested a review from brennanb2025 as a code owner July 31, 2026 20:23
@greptile-apps

greptile-apps Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds a Sleep with Descendants (N) context-menu action that recursively sleeps a selected workspace and all its validated descendants, and makes the pre-existing cascading delete label explicit as Delete with Descendants…. The recursive target set is computed via the already-validated getWorkspaceDeleteLineage projection, which excludes stale links, cycles, host boundaries, and cross-repo/project boundaries.

  • workspace-lineage-menu-actions.ts is a clean new module that moves hasSleepableWorkspaceActivity out of the monolithic menu component and adds getWorkspaceLineageMenuActions / useWorkspaceLineageMenuActions, delegating traversal to the existing getWorkspaceDeleteLineage helper.
  • WorkspaceSleepMenuItems.tsx extracts the sleep menu items into a focused presentational component, and the 50 ms Radix teardown guard is consolidated into a shared sleepWorktreesAfterMenuClose helper.
  • The virtualization E2E test race condition is fixed by anchoring the drag start to data-workspace-board-selection-surface and polling for at least one selected card before the scroll is forced.

Confidence Score: 5/5

Safe to merge — the new recursive sleep action is correctly scoped through the existing validated lineage projection and the 50 ms Radix teardown guard is preserved for the subtree path.

The traversal delegates entirely to the pre-existing getWorkspaceDeleteLineage, which already handles stale links, cycles, and boundary conditions. The deletion-pending guard (contextDeletePending) correctly widens from the parent-only check to parent-plus-descendants in single-context mode, and the sleep disabled logic is correctly asymmetric. Unit tests cover recursive collection, stale-lineage exclusion, and sleepability detection; the new E2E test exercises the full store-level round-trip.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/sidebar/workspace-lineage-menu-actions.ts New module extracting hasSleepableWorkspaceActivity and adding getWorkspaceLineageMenuActions/useWorkspaceLineageMenuActions; correctly reuses getWorkspaceDeleteLineage for validated lineage traversal with proper cycle/stale-link exclusion
src/renderer/src/components/sidebar/WorkspaceSleepMenuItems.tsx New presentational component cleanly wraps the single and subtree sleep menu items with tooltip guards; descendant item is conditionally hidden when count is 0
src/renderer/src/components/sidebar/WorktreeContextMenu.tsx Integrates useWorkspaceLineageMenuActions, replaces inline sleep items with WorkspaceSleepMenuItems, and correctly gates contextDeletePending for delete-pending state spanning descendants; sleepWorktreesAfterMenuClose refactored cleanly to a shared helper
src/renderer/src/components/sidebar/workspace-lineage-menu-actions.test.ts Good unit coverage for recursive descent collection, stale-lineage exclusion, and sleep-activity detection; hasSleepableWorkspaceActivity tests migrated here from WorktreeContextMenu.test.ts
tests/e2e/worktree-lineage.spec.ts Adds E2E test for sleep-with-descendants via store-state mocking; captureEvidence helper consolidated from the previously duplicate helpers
tests/e2e/workspace-board-lane-virtualization.spec.ts Race condition fix: adds data-workspace-board-selection-surface bounding-box anchor and waits for at least one selected card before forcing the large scroll, preventing flaky failures on slow CI runners
src/renderer/src/i18n/locales/en.json Adds three new i18n keys for sleepWithDescendants, sleepWithDescendantsDescription, and deleteWithDescendants

Sequence Diagram

sequenceDiagram
    participant User
    participant WorktreeContextMenu
    participant useWorkspaceLineageMenuActions
    participant getWorkspaceDeleteLineage
    participant WorkspaceSleepMenuItems
    participant runSleepWorktrees

    User->>WorktreeContextMenu: right-click workspace row
    WorktreeContextMenu->>useWorkspaceLineageMenuActions: "{enabled: !isMultiContext, parent, worktrees, lineageById, activity}"
    useWorkspaceLineageMenuActions->>getWorkspaceDeleteLineage: (parent, worktrees, lineageById)
    getWorkspaceDeleteLineage-->>useWorkspaceLineageMenuActions: "{descendants, deleteAllTargets}"
    useWorkspaceLineageMenuActions-->>WorktreeContextMenu: "{descendants, targets, sleepableTargets}"

    WorktreeContextMenu->>WorkspaceSleepMenuItems: render with descendantCount, subtreeSleepDisabled
    WorkspaceSleepMenuItems-->>User: "shows Sleep + Sleep with Descendants (N) when N > 0"

    User->>WorkspaceSleepMenuItems: click Sleep with Descendants (N)
    WorkspaceSleepMenuItems->>WorktreeContextMenu: onSleepSubtree()
    WorktreeContextMenu->>WorktreeContextMenu: setMenuOpenState(false)
    WorktreeContextMenu->>WorktreeContextMenu: window.setTimeout(..., 50ms)
    Note over WorktreeContextMenu: Radix menu tears down safely
    WorktreeContextMenu->>runSleepWorktrees: "sleepableTargets.map(t => t.id)"
    runSleepWorktrees-->>User: parent + descendants panels closed
Loading

Reviews (4): Last reviewed commit: "test(e2e): start marquee from selection ..." | Re-trigger Greptile

Comment thread tests/e2e/worktree-lineage.spec.ts Resolved
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added shared workspace lineage utilities that collect descendants and identify sleepable workspaces from terminal and browser activity. Updated the worktree context menu with descendant sleep and deletion actions, combined pending-delete state, and extracted sleep menu rendering. Added English localization strings, unit tests for lineage and activity filtering, and end-to-end coverage for descendant terminal cleanup.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: recursive sleep actions for workspace descendants.
Description check ✅ Passed The description covers the required summary, screenshots, testing status, AI review, security audit, and notes sections with relevant details.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/WorktreeContextMenu.tsx (1)

619-626: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the shared "close menu, then sleep after a delay" logic.

handleSleepSubtree (Line 619-626) repeats handleCloseTerminals (Line 608-617) exactly, except for the source array. Both close the menu, then call runSleepWorktrees inside the same window.setTimeout(..., 50). Extract a small helper that takes the worktree list and performs this sequence once. Reusing this helper keeps the 50 ms delay and its Radix-teardown rationale in one place instead of two, so a future timing fix cannot update one call site and miss the other.

♻️ Proposed refactor
+  const sleepWorktreesAfterMenuClose = useCallback(
+    (worktreeIds: string[]) => {
+      setMenuOpenState(false)
+      // Why: Sleep can remount the sidebar when it clears the active workspace.
+      // Let Radix finish closing the menu first so its focus/portal teardown
+      // cannot scroll the virtualized list during that remount.
+      window.setTimeout(() => {
+        void runSleepWorktrees(worktreeIds)
+      }, 50)
+    },
+    [setMenuOpenState]
+  )
+
   const handleCloseTerminals = useCallback(() => {
-    const worktreeIds = sleepableWorktrees.map((item) => item.id)
-    setMenuOpenState(false)
-    // Why: Sleep can remount the sidebar when it clears the active workspace.
-    // Let Radix finish closing the menu first so its focus/portal teardown
-    // cannot scroll the virtualized list during that remount.
-    window.setTimeout(() => {
-      void runSleepWorktrees(worktreeIds)
-    }, 50)
-  }, [setMenuOpenState, sleepableWorktrees])
+    sleepWorktreesAfterMenuClose(sleepableWorktrees.map((item) => item.id))
+  }, [sleepWorktreesAfterMenuClose, sleepableWorktrees])

   const handleSleepSubtree = useCallback(() => {
-    const worktreeIds = subtreeSleepableWorktrees.map((item) => item.id)
-    setMenuOpenState(false)
-    window.setTimeout(() => {
-      void runSleepWorktrees(worktreeIds)
-    }, 50)
-  }, [setMenuOpenState, subtreeSleepableWorktrees])
+    sleepWorktreesAfterMenuClose(subtreeSleepableWorktrees.map((item) => item.id))
+  }, [sleepWorktreesAfterMenuClose, subtreeSleepableWorktrees])

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a31e87f3-646b-46fd-9c20-218b5c097f8a

📥 Commits

Reviewing files that changed from the base of the PR and between e698241 and 9eb5f02.

📒 Files selected for processing (7)
  • src/renderer/src/components/sidebar/WorkspaceSleepMenuItems.tsx
  • src/renderer/src/components/sidebar/WorktreeContextMenu.test.ts
  • src/renderer/src/components/sidebar/WorktreeContextMenu.tsx
  • src/renderer/src/components/sidebar/workspace-lineage-menu-actions.test.ts
  • src/renderer/src/components/sidebar/workspace-lineage-menu-actions.ts
  • src/renderer/src/i18n/locales/en.json
  • tests/e2e/worktree-lineage.spec.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/sidebar/WorktreeContextMenu.test.ts

@OrcaWin
OrcaWin merged commit 139f756 into main Jul 31, 2026
51 of 52 checks passed
@OrcaWin
OrcaWin deleted the sleep-ux branch July 31, 2026 23:15
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

1 participant