workspace: Handle unsaved scratch buffers when opening recent projects (#51611)

Fixes #51456

## Problem

When opening a recent project with an unsaved scratch buffer (untitled
file), the project switch silently fails. The log shows:

```
failed to save contents of buffer
Caused by: FOREIGN KEY constraint failed
```

## Root Cause

When a user creates a new file from the welcome screen and edits it
without saving, the buffer is dirty but has no file path. When opening a
recent project, `prepare_to_close` calls
`save_all_internal(SaveIntent::Close)`, which tries to serialize dirty
items to the database for hot-exit functionality.

The serialization fails with a FOREIGN KEY constraint error because
workspace serialization is throttled - the workspace row may not exist
in the database yet when the editor tries to INSERT into the editors
table referencing that workspace_id.

The previous code used `try_join_all` on all serialize tasks, so a
single serialization failure would abort the entire close flow,
preventing the project switch.

## Fix

Replace `try_join_all` with individual task awaiting. If a serialize
task fails, the item is moved back to the `remaining_dirty_items` list
so the user gets a proper save/discard prompt instead of the action
silently failing.

This is a minimal change (7 insertions, 2 deletions) that:
- Handles the FOREIGN KEY error gracefully
- Preserves the save/discard prompt UX for items that fail serialization
- Logs the serialization error for debugging via `.log_err()`
- Does not change behavior for items that serialize successfully

## Test Plan

- [ ] Open Zed with no active workspace
- [ ] Create a new file from the welcome screen
- [ ] Edit the buffer to make it dirty (do not save)
- [ ] Open a recent project via `projects: open recent`
- [ ] Verify the project opens (previously it silently failed)
- [ ] Verify a save/discard prompt appears for the dirty scratch buffer

Release Notes:

- Fixed opening a recent project silently failing when an unsaved
scratch buffer is present (#51456).

---

This PR was written with the assistance of AI (Claude).

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
7ab425665dMatt Van Horn committed on 4/21/2026, 7:10:24 PM· committed by GitHubparent57d9e1f
1 file changedLine totals unavailable