Skip to content

Offer back unsaved edits when a workspace is removed without a prompt - #31738

Merged
nwparker merged 15 commits into
mainfrom
nwparker/worktree-removal-reopen-toast
Oct 22, 2026
Merged

nwparker merged 15 commits into
mainfrom
nwparker/worktree-removal-reopen-toast

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​700 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​695
Prod 39 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​581 $\color{#cf222e}{\Huge{\mathbf{−}}}$​75 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​506

ELI5

When a workspace disappears without Orca being able to ask first — removed from the command line, by an automation or a paired device, by git outside Orca, or because its remote host went away — any unsaved edits in its open files used to vanish. Now Orca catches them and shows "Closed N files with unsaved edits from " with a Reopen button, which puts the text back in a new file so nothing is lost.

What Changed

  • Before a no-prompt removal closes tabs, Orca writes any pending editor text (rich Markdown, notebooks, CSV, split panes) into drafts, for the files being closed only.
  • It then captures the unsaved text of each closed file — the live editor text if an editor is showing it, otherwise the draft — and shows one toast per removal.
  • Reopen creates a new <name> (recovered)<ext> file (or (recovered 2), …) in the active workspace and opens it. It never overwrites an existing file and never writes to the original path. If no workspace is open, the toast keeps the text so you can retry.
  • A delete you confirmed in the delete dialog doesn't toast for the files it listed, as long as their text is unchanged; anything edited after you confirmed is still offered back. Every other removal path always offers the text back.
  • The recovered text is released when you dismiss the toast or reopen the files.

Why

Follow-up to #31641, which warns before deletions that can show a dialog. Removals that can't prompt now keep the text recoverable instead of dropping it. Writing a new file, rather than reattaching the text to the original path or another tab, avoids writing to the wrong file or host and needs no new editor mode.

Linked Issue

Follow-up to #31641.

Visual Proof

The toast after a worktree was removed outside Orca with an unsaved file open:

toast

After Reopen, the recovered text in a new file:

reopened

Testing

  • Tests for every removal path (direct teardown, host announcements, startup, stale remote hosts, folder reconcile, project and host removal): capture, one toast per removal, confirmed-and-unchanged files staying quiet, edits after confirmation still toasting, all panes flushed, editor text vs draft, an oversized CSV cell edit preserved, recovery naming and never overwriting.
  • pnpm tc, changed-code quality gate, oxfmt, oxlint and localization checks pass.
  • Screenshots captured from a background, isolated Orca build with a throwaway profile.

Known limitations: on older remote hosts, writing the recovered file isn't fully atomic against another writer at the same moment; the recovered file lands in the active workspace, which may be a different repository.

  • 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 recovered text is held in memory only until the toast is dismissed.

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)

nwparker and others added 13 commits October 21, 2026 12:40
…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]>
A workspace removed with no dialog (CLI, automations, paired clients,
removal outside Orca, listing and runtime-host purges) still closed its
editor tabs and dropped their unsaved text.

Those removals now flush delayed rich Markdown, CSV and notebook text,
then show one toast, "Closed N files with unsaved edits from <workspace>",
whose Reopen action reopens each file as an unsaved tab: in its own
workspace if it is still open, else the active one, only when that
resolves to the same host. The next save is guarded against the disk
version the edits came from. Dismissing the toast drops the text and
logs it. The captured entries belong to that removal alone.

Removals confirmed in a dialog that listed their unsaved files pass
unsavedEditsConfirmed through removeWorktree, deleteFolderWorkspace,
removeProject, project-group deletion and the purge builders, so they
discard without a toast. Folder-workspace and Settings project removals
refuse while files are unsaved, so they never reach the toast.

Co-Authored-By: Claude <[email protected]>
…oval-dirty-confirm

# Conflicts:
#	src/renderer/src/components/sidebar/HostRemoveDialog.tsx
#	src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
…worktree-removal-reopen-toast

# Conflicts:
#	src/renderer/src/store/slices/worktrees/session/worktree-slice-lookups.ts
#	src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts
…oval-reopen-toast

# Conflicts:
#	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
Preserve recovered text through a missing-file read, retaining previous content and rename state. Cover empty drafts and keep unrelated failures on the existing error path.

Co-Authored-By: Claude <[email protected]>
Create collision-safe recovered files in the active workspace using the existing untitled flow. Capture delayed edits across host twins as one removal, match stale-host flushes to purge selection, honor host-qualified confirmations during announcements, and release retained toast text.

Co-Authored-By: Claude <[email protected]>
…ce recovery

A removal dialog now records the exact text it listed when the user
confirms. Every purge path (worktrees:changed, announcements, removal
teardown, runtime host retirement, repo removal, nested children) skips a
closed file only while its text still equals that snapshot, so edits made
after confirming are offered back instead of dropped.

- One flushAllPendingEditorBuffers() before each purge replaces per-id
  flushing and the getState threading; idle CSV cells stay open.
- Captures merge into one toast per microtask, deduped by file id; the
  per-call options, scope ref-counting and announcement wrapper are gone.
- Capture reads a shared model's live text, else any sharing tab's draft.
- Recovery writes through a guarded write that only fills the empty file
  it created, moves to the next name on conflict, and never deletes it.
- Reopen resolves the destination path from the provenance owner host.

Co-Authored-By: Claude <[email protected]>
…sh only closing panes

- No lingering allowlist: a dialog's confirm returns a snapshot that rides
  the confirmed removal (removeWorktree, removeProject, project groups, SSH
  host clear) to its own teardown capture. Every other purge path offers
  unsaved text back, even if it races a confirmed delete.
- The pre-purge flush covers only the closing files and views sharing their
  records, and flushes every pane registered for them, so split rich and
  notebook panes all commit while other workspaces' CSV cells keep editing.
- Listing announcements flush the files they will remove before the purge.
- Capture reads a model's text only while it is attached to an editor;
  otherwise it prefers the drafts.

Co-Authored-By: Claude <[email protected]>
… tab closes

A pending cell over the table size limit fails commit(), so the closing
flush now falls back to the view's preserve hook, which writes the cell
through the same limit-free serialization the unmount path uses. Recovery
then captures the typed text instead of an older draft.

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

coderabbitai Bot commented Oct 22, 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 6 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: 631a0932-cf32-475c-9253-362bfbb58612
📥 Commits

Reviewing files that changed from the base of the PR and between 5fdecf6 and fd25099.

📒 Files selected for processing: 50
  • src/renderer/src/components/editor/closed-unsaved-files-toast.test.ts
  • src/renderer/src/components/editor/closed-unsaved-files-toast.ts
  • src/renderer/src/components/editor/csv/useCsvPendingCell.test.tsx
  • src/renderer/src/components/editor/csv/useCsvPendingCell.ts
  • src/renderer/src/components/editor/editor-pending-flush.test.ts
  • src/renderer/src/components/editor/editor-pending-flush.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/removal-unsaved-editor-files.ts
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.test.tsx
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.test.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.tsx
  • src/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/HostRemoveDialog.tsx
  • src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
  • src/renderer/src/components/sidebar/delete-worktree-dialog-force-delete.ts
  • src/renderer/src/components/sidebar/delete-worktree-lineage-delete-all.ts
  • src/renderer/src/components/sidebar/run-worktree-delete-with-toast.ts
  • src/renderer/src/components/sidebar/ssh-host-remove-workspaces.ts
  • src/renderer/src/components/sidebar/worktree-delete-request.ts
  • src/renderer/src/components/sidebar/worktree-list/rows/use-project-group-dialogs-owner-host.test.tsx
  • src/renderer/src/components/sidebar/worktree-list/rows/use-project-group-dialogs.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/lib/create-untitled-markdown.test.ts
  • src/renderer/src/lib/create-untitled-markdown.ts
  • src/renderer/src/store/project-groups/project-group-mutations.ts
  • src/renderer/src/store/repos/repo-removal.ts
  • src/renderer/src/store/repos/repo-state.ts
  • src/renderer/src/store/slices/project-removal-host-twin-state.test.ts
  • src/renderer/src/store/slices/purge-stale-runtime-host-state.test.ts
  • src/renderer/src/store/slices/worktree-removal-options.ts
  • src/renderer/src/store/slices/worktrees/listing/fetch-all-worktrees.ts
  • src/renderer/src/store/slices/worktrees/listing/fetch-worktrees.ts
  • src/renderer/src/store/slices/worktrees/listing/fetched-worktree-merge.ts
  • src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts
  • src/renderer/src/store/slices/worktrees/session/worktree-slice-lookups.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts
  • src/renderer/src/store/slices/worktrees/teardown/purge-stale-runtime-host-state.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-workspace-unsaved-files.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-workspace-unsaved-files.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-worktree-renderer-teardown.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7fe8b26e-d055-4a7f-9fe7-85473bacf3ce
📥 Commits

Reviewing files that changed from the base of the PR and between 9738dc6 and 5fdecf6.

📒 Files selected for processing: 50
  • src/renderer/src/components/editor/closed-unsaved-files-toast.test.ts
  • src/renderer/src/components/editor/closed-unsaved-files-toast.ts
  • src/renderer/src/components/editor/csv/useCsvPendingCell.test.tsx
  • src/renderer/src/components/editor/csv/useCsvPendingCell.ts
  • src/renderer/src/components/editor/editor-pending-flush.test.ts
  • src/renderer/src/components/editor/editor-pending-flush.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/removal-unsaved-editor-files.ts
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.test.tsx
  • src/renderer/src/components/sidebar/DeleteNestedWorktreesDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.test.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.tsx
  • src/renderer/src/components/sidebar/ForgetSshWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/HostRemoveDialog.tsx
  • src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
  • src/renderer/src/components/sidebar/delete-worktree-dialog-force-delete.ts
  • src/renderer/src/components/sidebar/delete-worktree-lineage-delete-all.ts
  • src/renderer/src/components/sidebar/run-worktree-delete-with-toast.ts
  • src/renderer/src/components/sidebar/ssh-host-remove-workspaces.ts
  • src/renderer/src/components/sidebar/worktree-delete-request.ts
  • src/renderer/src/components/sidebar/worktree-list/rows/use-project-group-dialogs-owner-host.test.tsx
  • src/renderer/src/components/sidebar/worktree-list/rows/use-project-group-dialogs.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/lib/create-untitled-markdown.test.ts
  • src/renderer/src/lib/create-untitled-markdown.ts
  • src/renderer/src/store/project-groups/project-group-mutations.ts
  • src/renderer/src/store/repos/repo-removal.ts
  • src/renderer/src/store/repos/repo-state.ts
  • src/renderer/src/store/slices/project-removal-host-twin-state.test.ts
  • src/renderer/src/store/slices/purge-stale-runtime-host-state.test.ts
  • src/renderer/src/store/slices/worktree-removal-options.ts
  • src/renderer/src/store/slices/worktrees/listing/fetch-all-worktrees.ts
  • src/renderer/src/store/slices/worktrees/listing/fetch-worktrees.ts
  • src/renderer/src/store/slices/worktrees/listing/fetched-worktree-merge.ts
  • src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts
  • src/renderer/src/store/slices/worktrees/session/worktree-slice-lookups.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts
  • src/renderer/src/store/slices/worktrees/teardown/purge-stale-runtime-host-state.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-workspace-unsaved-files.test.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-workspace-unsaved-files.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-worktree-renderer-teardown.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.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.

📝 Walkthrough

The change adds pending-editor flushing and unsaved-text capture to workspace removal and purge flows. Removal dialogs pass confirmed-discard text to teardown operations. Teardown reports remaining unsaved files through a localized toast. The toast can reopen files as recovered Markdown documents, using collision-safe names and guarded writes. Tests cover flushing, discard confirmation, purge notices, and reopening behavior.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 5fdec

No issue was established that needs correction before merging; normal validation remains appropriate.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.68% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 59 functions across 43 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 and concisely summarizes the main change: recovering unsaved edits when a workspace is removed without a prompt.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, linked issue reference, visual proof, testing, limitations, and checklist. Some optional or minor items remain incomp…
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 is detailed and covers the user impact, implementation, rationale, linked issue reference, visual proof, testing, limitations, and checklist. Some optional or minor items remain incomplete, including manual testing, AI disclosure, and explicit local command results, but the description is mostly complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.68% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 59 functions across 43 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
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

@nwparker
nwparker merged commit 9249708 into main Oct 22, 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