Skip to content

sessions: fix Worktree Cleanup safety and usability - #351264

Open
Megan Rogge (meganrogge) wants to merge 4 commits into
mainfrom
agents/fix-worktree-cleanup-safety-ux-issues
Open

Megan Rogge (meganrogge) wants to merge 4 commits into
mainfrom
agents/fix-worktree-cleanup-safety-ux-issues

Conversation

@meganrogge

Copy link
Copy Markdown
Collaborator

Summary

Fix Worktree Cleanup safety and usability in the Agents window, preserving the shared cleanup editor's behavior in editor windows.

  • Require evidence of ownership in the connected agent host's session, detached-worktree, or pending-removal records before listing or accepting unlinked cleanup. Sharing a repository directory and an agent branch prefix is not sufficient. Recheck ownership when accepting cleanup, including force removal.
  • Protect running sessions before treating the open session as eligible, and recheck live status after confirmation and asynchronous preparation, before archiving.
  • Keep failed cleanup visible with its reason and allow normal retry when safety checks pass. Preserve failures across reopening and include work needing attention in the batch summary.
  • Use provider-supplied machine names in a new Machine column, screen-reader labels, and confirmation instead of encoded authorities in titles. Add an accessible machine filter and Refresh Worktrees toolbar action.
  • Keep row order stable during activity and measurement updates, retaining explicit sorting and refresh. Keep docked cleanup open when cleaning the current session changes the layout owner.
  • Explain background scheduling, retain overall removal counts, show determinate measurement progress, and process up to two host removals concurrently while retaining the existing removal locks and safety checks.
  • Update accessibility help for filtering, refresh, retries, running-session protection, and progress.

Conservative product choices

Worktrees without ownership evidence in this host are not offered or accepted, even with force. This can leave older, truly ownerless leftovers for manual investigation rather than risk deleting another host's checkout. The machine filter defaults to All Machines and clears selection when changed. Refresh discards confirmed removal rows but preserves pending and failed requests. No new settings or automatic cleanup policy are introduced.

Validation

Validated after rebasing onto current main, using the Node version required by the repository.

  • pnpm run build-fast --client-only — passed.
  • Focused unit tests below — 395 passed. Coverage includes unowned-host rejection even with force, ownership changes after inventory, open-running-session races, parallel removal/restoration, failure retry/reopening, remote routing and human host names, machine filtering, refresh, stable rows, keyboard-accessible controls, and layout transitions.
  • pnpm run typecheck-client — passed.
  • git diff HEAD~2 --name-only -z -- '*.ts' | xargs -0 pnpm run oxlint — passed, no warnings.
  • pnpm run valid-layers-check — passed.
  • git diff --check — passed.
./scripts/test.sh \
  --run src/vs/platform/agentHost/test/node/agentHostWorktreeCleanupService.test.ts \
  --run src/vs/workbench/contrib/sessions/test/browser/sessionInputBanners/sessionWorktreeCleanupService.test.ts \
  --run src/vs/workbench/contrib/sessions/test/browser/sessionInputBanners/sessionWorktreeCleanupEditor.test.ts \
  --run src/vs/sessions/contrib/layout/test/browser/baseSessionLayoutController.test.ts \
  --grep 'AgentHostWorktreeCleanupService|SessionWorktreeCleanup|BaseLayoutController' \
  --reporter dot

Not run: live SSH/multiple-agent-host end-to-end testing, manual screen-reader testing, or full integration/smoke suites.

Manual testing

  1. Connect a named SSH host, open Worktree Cleanup, and verify human machine names in rows and confirmation. Filter to that machine and refresh using the toolbar with the keyboard.
  2. Keep a session running, including the open session, and verify it cannot be selected for cleanup.
  3. Cause a cleanup failure, reopen the editor, and verify the reason remains visible and the row can be selected for retry once safe.
  4. Dock cleanup, clean up the currently open idle session, and verify cleanup remains open with progress.
  5. Update session activity while cleanup is open and verify existing rows do not reshuffle; use explicit sort or refresh to reorder.
  6. With separate agent hosts on one machine, verify a host does not offer another host's unowned worktrees.

Fixes #349800
Fixes #349801
Fixes #349803
Fixes #349799
Fixes #349940
Fixes #349985
Fixes #349966
Fixes #349983
Fixes #349984

Protect host ownership and running sessions, retain failed cleanup for retry, and add stable rows, host filters, refresh, and background progress.

Co-authored-by: Copilot <[email protected]>
Preserve upstream remote capability checks and open-session classification, and cover human machine labels, refresh, live status changes, and retry behavior.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 17:37
@meganrogge Megan Rogge (meganrogge) added this to the 1.150.0 milestone Nov 30, 2026

Copilot AI 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.

🟡 Changes recommended

Switching sessions while Cleanup is active skips working-set restoration and can overwrite the destination session’s saved editors with the previous session’s editors.

3 open issues
What changed in this PR

This PR improves Worktree Cleanup safety and usability in the Agents window, with updates to the shared cleanup editor used in editor windows.

Changes:

  • Require host ownership evidence, recheck running sessions before archiving, and allow two concurrent host removals.
  • Keep failures visible and retryable; add machine names, filtering, refresh, stable row ordering, and clearer progress.
  • Preserve docked Cleanup during session transitions and expand accessibility guidance and regression coverage.
File Description
src/​vs/​workbench/​contrib/​sessions/​test/​browser/​sessionInputBanners/​sessionWorktreeCleanupService.test.ts Tests running-session protection and machine names in confirmations.
src/​vs/​workbench/​contrib/​sessions/​test/​browser/​sessionInputBanners/​sessionWorktreeCleanupEditor.test.ts Covers filtering, refresh, retries, progress, stable rows, and keyboard controls.
src/​vs/​workbench/​contrib/​sessions/​browser/​sessionInputBanners/​sessionWorktreeCleanupService.ts Resolves provider machine names and rechecks live session status.
src/​vs/​workbench/​contrib/​sessions/​browser/​sessionInputBanners/​sessionWorktreeCleanupEditor.ts Adds machine controls, visible failures, stable ordering, and progress updates.
src/​vs/​workbench/​contrib/​sessions/​browser/​sessionInputBanners/​sessionWorktreeCleanupAccessibilityHelp.ts Updates instructions for filtering, refresh, retries, and cleanup progress.
src/​vs/​sessions/​contrib/​layout/​test/​browser/​baseSessionLayoutController.test.ts Tests keeping docked Cleanup open across layout-owner changes.
src/​vs/​sessions/​contrib/​layout/​browser/​baseSessionLayoutController.ts Adds a Cleanup-specific working-set restoration guard.
src/​vs/​platform/​agentHost/​test/​node/​agentHostWorktreeCleanupService.test.ts Tests ownership rejection, acceptance rechecks, and concurrent removal/restoration.
src/​vs/​platform/​agentHost/​node/​agentHostWorktreeCleanupService.ts Enforces ownership evidence and limits concurrent removals to two.

Review effort: Balanced

Defer working-set restores while Cleanup is active without saving outgoing editors over an incoming owner's snapshot. Resume on editor activation and retain already-settled owners on return.\n\nClear remembered checkbox choices on machine changes and refresh machine cells after host renames.

Co-authored-by: Copilot <[email protected]>
Apply the repository formatter to the three cleanup files rejected by hygiene.

Co-authored-by: Copilot <[email protected]>
@meganrogge
Megan Rogge (meganrogge) marked this pull request as ready for review November 30, 2026 19:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants