fix(desktop): preserve pane layout when removing a workspace from the sidebar

Draft
GI
4mo ago
+57-2

What the bug is

Issue #5881 reports two symptoms after using Remove from Sidebar on a workspace:

  1. The "Workspaces" nav item is missing from the left sidebar.
  2. Reopening the workspace via Search → Workspaces shows it without the attached live Claude session.

This PR fixes symptom #2 (the reproducible, clearly-scoped defect). See the note below on #1.

Root cause

"Remove from Sidebar" is a headless intent consumed by RemoveFromSidebarMount, which calls hideWorkspaceInSidebar → tombstoneSidebarWorkspaceRecord. That function set isHidden = true and wiped the persisted pane layout:

draft.paneLayout = createEmptyPaneLayout(); // tabs: []

The runtime cleanup it runs (terminalRuntimeRegistry.release) is non-destructive — it persists runtime state and keeps the host-side session alive (only dispose() kills a session). So the Claude terminal keeps running; the problem is purely that its pane layout was erased.

On reopen, useV2WorkspacePaneLayout reads v2WorkspaceLocalState.paneLayout — now empty — so the workspace renders with no panes and the still-alive Claude session is orphaned. This contradicts the documented contract that unpinning is "reversible — the workspace itself is not deleted and can be re-pinned."

The fix

Stop wiping paneLayout in the tombstone's update branch. The layout is preserved, so re-pinning/reopening restores the panes and the released runtime reattaches to the live session. The row-less insert branch is unchanged (a row-less workspace has no persisted layout to keep). Runtime release still happens, so renderer resources are freed while the workspace is hidden.

Tests

sidebarMutations.test.ts gains a reproduction test asserting that hiding a workspace with a live terminal pane keeps its persisted paneLayout. It failed before the fix (layout reset to { tabs: [] }) and passes after. All 25 nearby sidebar tests pass; bun run lint is clean.

Note on symptom #1 (nav item missing)

The top-level "Workspaces" nav item is gated behind a hardcoded flag in DashboardSidebarHeader.tsx:

// Temporarily hidden, not removed — flip to true to restore the Workspaces tab.
const SHOW_WORKSPACES_TAB = false;

It is unconditionally hidden in this version and is not affected by "Remove from Sidebar", so it looks like a deliberate product decision rather than a bug. Left untouched here pending product intent — flipping it is a one-line change if desired.

Closes #5881


Summary by cubic

Preserves a workspace’s pane layout when using Remove from Sidebar so reopening or re‑pinning restores panes and reattaches the live Claude session. Addresses the reproducible part of #5881.

  • Bug Fixes
    • Stop clearing paneLayout in tombstoneSidebarWorkspaceRecord; only release renderer runtimes so host sessions persist for reattach.
    • Add a test in sidebarMutations.test.ts to assert the layout is preserved when hiding a workspace.