# Fix removed workspace resurrecting via serialization race \(\#52035\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 4049a4c91408501bb3658f3b248b5707b7fe0c87

Requested commit: 4049a4c91408501bb3658f3b248b5707b7fe0c87

Commit: 4049a4c91408501bb3658f3b248b5707b7fe0c87

Tree: 0554f45574b342d603d64484af29e65baefaf8d8

Author: Richard Feldman

Committer: GitHub

## Message

```
Fix removed workspace resurrecting via serialization race (#52035)

In `remove_workspace`, the removed `Entity<Workspace>` could still have
a pending `serialize_workspace` throttle timer (200ms). When that timer
fired, `serialize_workspace_internal` would write the old `session_id`
back to the DB — undoing the removal. On next restart, the workspace
would reappear.

The race window opens whenever any state change (worktree change,
breakpoint change, etc.) triggers `serialize_workspace` within 200ms
before `remove_workspace` is called.

**Fix**: Before the DB cleanup task, `update` the removed workspace
entity to:
1. `session_id.take()` — so any in-flight serialization writes
`session_id: None`
2. `_schedule_serialize_workspace.take()` — cancel the pending throttle
timer
3. `_serialize_workspace_task.take()` — cancel any actively running
serialization task

This mirrors what `remove_from_session` already does (clearing
`session_id`), but `remove_workspace` was missing it.

Release Notes:

- Fixed a bug where a removed workspace could reappear on next launch
due to a serialization race.
```

## Parents

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

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