# Wire up worktree archival on thread archive and restoration on unarchive \(\#53215\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 2169ebaf4b221ffaff358b58337134ab3dbb2413

Requested commit: 2169ebaf4b221ffaff358b58337134ab3dbb2413

Commit: 2169ebaf4b221ffaff358b58337134ab3dbb2413

Tree: a443bb5915aad85c323a4c6c9bed0853f1daae77

Author: Richard Feldman

Committer: GitHub

## Message

```
Wire up worktree archival on thread archive and restoration on unarchive (#53215)

Connect the git API and archived worktree data model to the sidebar's
archive/unarchive flow:

- Add `thread_worktree_archive` module: orchestrates the full archive
cycle (WIP commits, DB records, git refs, worktree deletion) and restore
cycle (detached worktree creation, reset to recover staged/unstaged
state, branch restoration)
- Integrate into sidebar: `archive_thread` now persists worktree state
before cleanup; `activate_archived_thread` restores worktrees via git
with targeted path replacement for multi-root threads
- Add pending worktree restore UI state with spinner and cancel button
- Show toast on restore failure instead of silent log
- Switch to surviving workspace when archiving active thread whose
workspace will be deleted
- Deserialize persisted `project_group_keys` on window restore
- Guard `cleanup_empty_workspaces` against dropped entities
- Await rollback DB operations instead of fire-and-forget

Part 3 of 3 in the persist-worktree stack. Stacked on #53214. This wires
up parts 1 and 2.

Release Notes:

- Added worktree state preservation when archiving agent threads,
automatically restoring staged and unstaged changes when the thread is
unarchived

---------

Co-authored-by: Anthony Eid <anthony@zed.dev>
```

## Parents

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

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