Skip to content

Clean up orphaned files on git worktree creation failure#53287

Merged
rtfeldman merged 9 commits intomainfrom
focal-arrow
Apr 9, 2026
Merged

Clean up orphaned files on git worktree creation failure#53287
rtfeldman merged 9 commits intomainfrom
focal-arrow

Conversation

@rtfeldman
Copy link
Copy Markdown
Contributor

@rtfeldman rtfeldman commented Apr 7, 2026

Update await_and_rollback_on_failure in agent_panel.rs to comprehensively clean up both git metadata and filesystem artifacts when worktree creation fails.

Release Notes:

  • Clean up files and git metadata when worktree creation fails during new agent thread setup.

Update await_and_rollback_on_failure to comprehensively clean up both
Git metadata and filesystem artifacts when worktree creation fails:

1. Track all attempted worktree paths (not just successful ones) so
   rollback covers the failed creation too.
2. After git-level removal, force filesystem cleanup via Fs::remove_dir
   to catch orphan directories that git didn't know about.
3. Prune empty parent (branch name) directories left behind by
   create_dir_all.
4. Accept Arc<dyn Fs> instead of using smol::fs directly, making the
   code testable with FakeFs.

Add five tests covering: all-succeed happy path, failure rolls back all
worktrees, canceled receiver handling, orphan directory cleanup, and
preservation of non-empty parent directories.
@rtfeldman rtfeldman self-assigned this Apr 7, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 7, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Apr 7, 2026
@rtfeldman rtfeldman marked this pull request as ready for review April 7, 2026 11:24
# Conflicts:
#	crates/agent_ui/src/agent_panel.rs
- Ensure every path gets an entry in rollback_futures even when
  cx.update fails to dispatch, preventing leaked directories on disk
- Wrap fs.remove_dir fallback in an if git_remove_failed condition
  so it only runs when git worktree remove actually failed
- Log an explicit error when cx.update dispatch fails instead of
  silently swallowing the error
@rtfeldman rtfeldman merged commit e7ba171 into main Apr 9, 2026
31 checks passed
@rtfeldman rtfeldman deleted the focal-arrow branch April 9, 2026 17:54
rtfeldman added a commit that referenced this pull request Apr 10, 2026
Update `await_and_rollback_on_failure` in `agent_panel.rs` to
comprehensively clean up both git metadata and filesystem artifacts when
worktree creation fails.

Release Notes:

- Clean up files and git metadata when worktree creation fails during
new agent thread setup.
maxbrunsfeld pushed a commit that referenced this pull request Apr 10, 2026
Update `await_and_rollback_on_failure` in `agent_panel.rs` to
comprehensively clean up both git metadata and filesystem artifacts when
worktree creation fails.

Release Notes:

- Clean up files and git metadata when worktree creation fails during
new agent thread setup.
maxbrunsfeld added a commit that referenced this pull request Apr 10, 2026
Cherry-picked PRs (in order applied):

1. #53386
2. #53400
3. #53396
4. #53428
5. #53356
6. #53215
7. #53429
8. #53458
9. #53436
10. #53451
11. #53454
12. #53419
13. #53287
14. #53521
15. #53463
16. #52848
17. #53544
18. #53556
19. #53566
20. #53579
21. #53575
22. #53550
23. #53585
24. #53510
25. #53599
26. #53099
27. #53662
28. #53660
29. #53657
30. #53654


Release Notes:

- N/A

---------

Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Anthony Eid <anthony@zed.dev>
Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: Eric Holk <eric@zed.dev>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Cameron Mcloughlin <cameron.studdstreet@gmail.com>
Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Mikayla Maki <mikayla@zed.dev>
Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
Co-authored-by: Katie Geer <katie@zed.dev>
Co-authored-by: ojpro <contact@ojpro.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants