Skip to content

List unsaved files before deleting a workspace, and refuse removals that would lose them silently - #31641

Merged
nwparker merged 2 commits into
mainfrom
nwparker/worktree-removal-dirty-confirm
Oct 21, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/worktree-removal-dirty-confirm

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​503 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​493
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​582 $\color{#cf222e}{\Huge{\mathbf{−}}}$​112 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​470

ELI5

Deleting a workspace could silently throw away unsaved edits in files that were only open in that workspace. Now Orca lists those files before you delete, and refuses (with "Save or close N unsaved files first") where the files would otherwise be lost without any dialog.

What Changed

  • Delete Workspace dialog lists "Unsaved edits in N files will be discarded:" with the files, when the delete would close the last open tab of a file with unsaved edits. Focus no longer jumps to the Delete button while that list is shown. "Don't ask again" no longer skips the dialog when such files exist.
  • The same list appears in the other removal confirms: Forget SSH workspace, SSH host removal, nested-worktree delete, Remove Folder, and project-group delete.
  • Removals with no dialog — deleting a folder workspace (context menu, card button, keyboard shortcut), Settings → Remove Project, Space's Force button and the failure toast's Force/Delete Anyway retries — refuse with a "Save or close N unsaved files in first" toast while unsaved files would close.
  • The file list comes from the removal's own decision about which tabs it closes (including host twins, detected worktrees, Markdown preview sources and unstaged diff tabs), and files still open in another workspace don't count. Pending editor text is flushed before the list is built.
  • The removal confirmation dialogs use the protected security surface.

Removals that can't show anything (CLI, automations, paired clients) are unchanged here; a follow-up handles them.

Why

Listing the files in the dialog the user already sees, and refusing elsewhere, is the smallest change that stops silent loss. An earlier version added a separate step with a Save button; it was larger and had a cancel-during-save bug, so Save was dropped — the user cancels, saves, and retries.

Linked Issue

N/A (maintainer).

Visual Proof

Before — Delete Workspace with an unsaved file open (no warning):

before

After — the same dialog lists the unsaved file:

after

After — deleting a folder workspace with an unsaved file is refused:

after toast

Testing

  • Tests for the list (host matching, shared views, diff tabs, detected worktrees, folder-workspace twins), focus, "Don't ask again", every refusal path, and each dialog's list.
  • pnpm tc, oxlint, oxfmt --check, check:code-quality:changed (design system), localization checks pass.
  • Screenshots above were captured from a background, isolated Orca build with a throwaway profile.

Known limitation: a symlink pointing into a deleted folder isn't resolved on the host.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

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

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

No wire or persisted-state change. The Forget SSH workspace dialog now uses the standard dialog padding.

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)

…ses them

Removing a workspace closed its editor tabs and threw away unsaved text
without a word, including with "Don't ask again" on.

Removal confirms now list the files whose unsaved edits the removal
discards: the tabs the purge itself would close (host twins included),
kept only when no view sharing their model or record stays open. Editable
unstaged diff tabs count; delayed rich Markdown, CSV and notebook text is
flushed first.
- Delete Workspace dialog: the list sits with the git-change warnings.
  While it is non-empty the dialog no longer starts focus on Delete, and
  "Don't ask again" no longer skips the dialog.
- The same list in Remove Project, SSH workspace forget/reconnect-and-
  delete, SSH host removal with its workspaces, nested-worktree deletion
  (rows matched by path containment under the parent) and project-group
  deletion with its contained projects.
- Removals with no dialog whose files stay on disk refuse instead, with
  "Save or close N unsaved files in <name> first": folder-workspace
  delete (card action, context menu, hovered shortcut, through one shared
  helper) and Settings > Remove Project.

Force retries with no list of their own (the failure toast's Force
Delete / Delete Anyway, Space's Force button) re-check at that moment and
refuse the same way. A folder-workspace delete that leaves a same-id
folder on another host closes no tabs, so it is not refused. Removal
confirms touched here render on the security surface.

Removals with no prompt (CLI, automations, paired clients) behave as
before; a follow-up offers their text back.

Known limitation: the list is decided by the tabs a removal closes, not
by paths; a symlink into a deleted folder is not resolved on the host.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 15 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: eb1b2166-25e3-4686-a31f-39e5a4e17105
📥 Commits

Reviewing files that changed from the base of the PR and between adeb891 and e55c9dc.

📒 Files selected for processing: 35
  • src/renderer/src/components/editor/removal-unsaved-editor-files.test.ts
  • src/renderer/src/components/editor/removal-unsaved-editor-files.ts
  • src/renderer/src/components/settings/use-settings-store-model.ts
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.test.tsx
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.unsaved-edits.test.tsx
  • src/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/HostRemoveDialog.tsx
  • src/renderer/src/components/sidebar/ProjectGroupDeleteDialog.tsx
  • src/renderer/src/components/sidebar/RemovalUnsavedFilesNotice.tsx
  • src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
  • src/renderer/src/components/sidebar/delete-worktree-flow.test.ts
  • src/renderer/src/components/sidebar/delete-worktree-flow.ts
  • src/renderer/src/components/sidebar/folder-workspace-delete.test.ts
  • src/renderer/src/components/sidebar/folder-workspace-delete.ts
  • src/renderer/src/components/sidebar/hovered-workspace-delete.test.ts
  • src/renderer/src/components/sidebar/hovered-workspace-delete.ts
  • src/renderer/src/components/sidebar/removal-unsaved-files.ts
  • src/renderer/src/components/sidebar/run-worktree-delete-with-toast.ts
  • src/renderer/src/components/sidebar/use-delete-worktree-dialog-targets.ts
  • src/renderer/src/components/sidebar/use-worktree-card-controller.ts
  • src/renderer/src/components/sidebar/use-worktree-card-workspace-actions.ts
  • src/renderer/src/components/sidebar/worktree-context-menu-delete-intent.ts
  • src/renderer/src/components/sidebar/worktree-list/rows/ProjectGroupDialogs.tsx
  • src/renderer/src/components/sidebar/worktree-list/rows/use-project-group-dialogs.ts
  • src/renderer/src/components/status-bar/use-workspace-space-manager-panel.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-closed-files.ts
📝 Walkthrough

The change identifies unsaved editor files that worktree purges would close, flushes pending edits, and adds checks to selected workspace and worktree deletion paths. Removal dialogs can display affected file names and counts. The changes also update deletion tests and add translated warning and blocking messages.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to adeb8

If one editor flush fails, later unsaved edits may be discarded without a warning. Contain failures per file before relying on the new removal protection.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 38.24% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 27 files. (7 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the primary change: listing unsaved files and blocking removals that could silently discard them.
Description check Passed The description covers the required sections, explains the user-visible behavior and implementation, includes visual proof, testing details, limitations, and checklist status. The maintainer-specific …
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.
Full details: Description check

Explanation

The description covers the required sections, explains the user-visible behavior and implementation, includes visual proof, testing details, limitations, and checklist status. The maintainer-specific Linked Issue exception is addressed with N/A.

Full details: Docstring Coverage

Explanation

Docstring coverage is 38.24% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 27 files. (7 skipped: 7 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch nwparker/worktree-removal-dirty-confirm
  • 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.

@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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98e7b160-9674-4f52-b2ec-3041d62cc833
📥 Commits

Reviewing files that changed from the base of the PR and between 6788612 and adeb891.

📒 Files selected for processing: 35
  • src/renderer/src/components/editor/removal-unsaved-editor-files.test.ts
  • src/renderer/src/components/editor/removal-unsaved-editor-files.ts
  • src/renderer/src/components/settings/use-settings-store-model.ts
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.test.tsx
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.unsaved-edits.test.tsx
  • src/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/HostRemoveDialog.tsx
  • src/renderer/src/components/sidebar/ProjectGroupDeleteDialog.tsx
  • src/renderer/src/components/sidebar/RemovalUnsavedFilesNotice.tsx
  • src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
  • src/renderer/src/components/sidebar/delete-worktree-flow.test.ts
  • src/renderer/src/components/sidebar/delete-worktree-flow.ts
  • src/renderer/src/components/sidebar/folder-workspace-delete.test.ts
  • src/renderer/src/components/sidebar/folder-workspace-delete.ts
  • src/renderer/src/components/sidebar/hovered-workspace-delete.test.ts
  • src/renderer/src/components/sidebar/hovered-workspace-delete.ts
  • src/renderer/src/components/sidebar/removal-unsaved-files.ts
  • src/renderer/src/components/sidebar/run-worktree-delete-with-toast.ts
  • src/renderer/src/components/sidebar/use-delete-worktree-dialog-targets.ts
  • src/renderer/src/components/sidebar/use-worktree-card-controller.ts
  • src/renderer/src/components/sidebar/use-worktree-card-workspace-actions.ts
  • src/renderer/src/components/sidebar/worktree-context-menu-delete-intent.ts
  • src/renderer/src/components/sidebar/worktree-list/rows/ProjectGroupDialogs.tsx
  • src/renderer/src/components/sidebar/worktree-list/rows/use-project-group-dialogs.ts
  • src/renderer/src/components/status-bar/use-workspace-space-manager-panel.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-closed-files.ts
💤 Files with no reviewable changes: 1
  • src/renderer/src/components/sidebar/use-worktree-card-controller.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +37 to +46
export function flushRemovalPendingEdits(state: AppState, fileIds: Iterable<string>): void {
try {
for (const fileId of fileIds) {
flushPendingEditorBuffer(state, fileId)
}
} catch (error) {
// Why: a view's flush failing must not block the removal that asked.
console.error('[editor] flushing pending edits before a removal failed', error)
}
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Move the try/catch inside the loop so one failing flush does not skip the remaining files.

The try wraps the whole for loop. If flushPendingEditorBuffer throws for one file, the loop stops. The delayed views of the later file ids are never committed to editorDrafts or isDirty. lastViewUnsavedFiles then does not list those files. A removal dialog can omit them, and the skip-confirm and block paths can allow the removal. The user loses the edits without a warning.

The comment says one failing flush "must not block the removal". The test name says "keeps going". Both imply that the remaining flushes still run.

🐛 Proposed fix
--- "a/src/renderer/src/components/editor/removal-unsaved-editor-files.ts"
+++ "b/src/renderer/src/components/editor/removal-unsaved-editor-files.ts"
@@ -34,16 +34,16 @@
 }
 
 /** Commits text delayed views (rich Markdown, CSV, notebook) still hold for these tabs. */
 export function flushRemovalPendingEdits(state: AppState, fileIds: Iterable<string>): void {
-  try {
-    for (const fileId of fileIds) {
+  for (const fileId of fileIds) {
+    try {
       flushPendingEditorBuffer(state, fileId)
+    } catch (error) {
+      // Why: a view's flush failing must not block the removal that asked, nor skip other files.
+      console.error('[editor] flushing pending edits before a removal failed', error)
     }
-  } catch (error) {
-    // Why: a view's flush failing must not block the removal that asked.
-    console.error('[editor] flushing pending edits before a removal failed', error)
   }
 }
 
 /** Unsaved files a removal of `targets` would close, after flushing their delayed views. */
 export function collectRemovalUnsavedFiles(

Add a test with two registered flushes where the first throws. Assert that the second flush still runs.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function flushRemovalPendingEdits(state: AppState, fileIds: Iterable<string>): void {
try {
for (const fileId of fileIds) {
flushPendingEditorBuffer(state, fileId)
}
} catch (error) {
// Why: a view's flush failing must not block the removal that asked.
console.error('[editor] flushing pending edits before a removal failed', error)
}
}
export function flushRemovalPendingEdits(state: AppState, fileIds: Iterable<string>): void {
for (const fileId of fileIds) {
try {
flushPendingEditorBuffer(state, fileId)
} catch (error) {
// Why: a view's flush failing must not block the removal that asked, nor skip other files.
console.error('[editor] flushing pending edits before a removal failed', error)
}
}
}

…oval-dirty-confirm

# Conflicts:
#	src/renderer/src/components/sidebar/HostRemoveDialog.tsx
#	src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
@nwparker
nwparker merged commit 50f72bd into main Oct 21, 2026
40 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.

1 participant