# workspace: Fix recent-projects cleanup wiping active workspaces \(\#54224\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/1ea6eb4d42b871bf2cb19dbb5f0dd59f5eee349a)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 1ea6eb4d42b871bf2cb19dbb5f0dd59f5eee349a

Requested commit: 1ea6eb4d42b871bf2cb19dbb5f0dd59f5eee349a

Commit: 1ea6eb4d42b871bf2cb19dbb5f0dd59f5eee349a

Tree: 2aa6af668a01ab610b065674bab237b2502526d3

Author: allison

Committer: GitHub

## Message

```
workspace: Fix recent-projects cleanup wiping active workspaces (#54224)

The recent-projects picker, sidebar, welcome screen, and agent thread
store all called `recent_workspaces_on_disk`, which combined listing
with deleting stale rows. Its retention predicate rejected workspaces
with no on-disk directory, including empty workspaces holding unsaved
scratch buffers, and the resulting `delete_workspace_by_id` call
cascaded into `items`, `pane_groups`, and the per-editor tables. For
clarity, the method has been renamed to `recent_workspaces_for_ui`.

Meanwhile, `last_session_workspace_locations` used a slightly different
form of the same predicate. The two disagreeing on what counts as a
valid workspace caused #48799, `Workspace WorkspaceId(N) not found`
errors on repeated launches (#50409), the
`test_window_edit_state_restoring_enabled` flake (#50871), and the
foreign key constraint fail on `projects: open recent` with a dirty
scratch buffer (#51456).

Note that for the last issue mentioned (#51456) there is no save prompt
for scratch buffers. This seems out of scope for this PR so I'll fix
that after this is addressed.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #48799 
Closes #50409 
Closes #50871
Closes #51456 

Release Notes:

- Fixed unsaved scratch buffers being lost across restarts and an
occasional error when opening a recent project.
```

## Parents

- [19429026c1a20da8947ad1a7adca8d73c7f0ffce](https://git.cafe/gitcafe/zed/commit/19429026c1a20da8947ad1a7adca8d73c7f0ffce?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/1ea6eb4d42b871bf2cb19dbb5f0dd59f5eee349a?format=markdown)
