Skip to content

Wire up agent worktree creation, cleanup, and integration tests - #49145

Closed
rtfeldman wants to merge 8 commits into
mainfrom
richard/ai-35-agent-worktree-orchestration-cleanup-lifecycle
Closed

Wire up agent worktree creation, cleanup, and integration tests#49145
rtfeldman wants to merge 8 commits into
mainfrom
richard/ai-35-agent-worktree-orchestration-cleanup-lifecycle

Conversation

@rtfeldman

Copy link
Copy Markdown
Contributor

Summary

Wire up the full agent worktree orchestration layer: creation flow, failure handling with rollback, and cleanup lifecycle.

Creation flow

When a user starts a new thread with the NewWorktree target:

  1. Create a git worktree via the GitWorktreeStore proto API
  2. Trust the worktree path
  3. Open it as a new workspace in the MultiWorkspace
  4. Start an agent thread in the new workspace

If any post-creation step fails, the git worktree is rolled back automatically.

Cleanup lifecycle

When a worktree thread is deleted:

  1. Remove the workspace from MultiWorkspace
  2. Clean up the git worktree via the proto API

Supports both single thread and bulk deletion.

Tests

13 new tests covering the full lifecycle:

  • test_new_worktree_thread_creation_flow
  • test_thread_target_local_project
  • test_create_agent_worktree_failure
  • test_create_agent_worktree_rollback
  • test_cleanup_agent_worktree
  • Branch naming and path resolution unit tests

Dependencies

This PR depends on all 4 prior PRs in the stacked diff series:

Once PRs 1-4 land, this PR's diff will reduce to just the orchestration layer.

Closes AI-35

Release Notes:

  • N/A

Add remove_worktree() and rename_worktree() to the GitRepository trait with
RealGitRepository implementations that shell out to git worktree remove/move.

Implement all 4 worktree methods (worktrees, create_worktree, remove_worktree,
rename_worktree) on FakeGitRepository backed by FakeGitRepositoryState, with
simulated_create_worktree_error for test-time fault injection.

Add set_create_worktree_error() helper on FakeFs.

Tests: test_parse_worktrees_from_str, test_create_and_list_worktrees,
test_remove_worktree, test_remove_worktree_force, test_rename_worktree,
test_create_worktree (real git), test_fake_worktree_lifecycle (fake).
Add GitRemoveWorktree and GitRenameWorktree proto messages (envelope fields
423, 424) with request handlers in GitStore for both local and remote
execution. Register RPC handlers in collab.

Tests: test_repository_remove_worktree_local, test_repository_rename_worktree_local,
test_repository_remove_worktree_remote_roundtrip,
test_repository_rename_worktree_remote_roundtrip.
Add agent_worktree_directory to GitSettings for configuring where agent
worktrees are stored (default: Zed data dir).

Remove Copy derive from GitSettings/GitContentSettings (incompatible with
String field) and fix downstream .as_ref().unwrap() call sites.

Define AgentGitWorktreeInfo (branch, worktree_path, base_ref) and add it
to DbThread + DbThreadMetadata for persistence and session list display.

Tests: test_git_worktree_info_roundtrip, test_session_list_includes_worktree_meta.
… main

Restore disable_ai field on ProjectSettingsContent and search_on_input
on SearchSettings. Add .as_ref() before .unwrap() on Option<GitSettings>
in project_panel and outline_panel since GitSettings no longer derives Copy.
Add 'Start Thread In...' dropdown to the agent panel toolbar, gated behind
AgentV2FeatureFlag, with 'Local Project' and 'New Worktree' options. The
'New Worktree' option is disabled when there's no git repo or in collab.

Add WorktreeCreationStatus enum for displaying creation progress/errors.

Render worktree branch labels on ACP history rows using thread metadata.

Tests: test_worktree_branch_from_meta, test_history_row_displays_worktree.
… into richard/ai-35-agent-worktree-orchestration-cleanup-lifecycle
Implement the full worktree creation flow: on NewThread with NewWorktree
target, create a git worktree, trust the path, open it as a new workspace
in the MultiWorkspace, and start an agent thread there. Roll back the
git worktree if any post-creation step fails.

Implement cleanup: when a worktree thread is deleted, remove the workspace
from MultiWorkspace and clean up the git worktree. Support both single
thread and bulk deletion.

Tests: test_new_worktree_thread_creation_flow, test_thread_target_local_project,
test_create_agent_worktree_failure, test_create_agent_worktree_rollback,
test_cleanup_agent_worktree, plus branch name and path resolution unit tests.
@rtfeldman rtfeldman self-assigned this Feb 13, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Feb 13, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Feb 13, 2026
- Add ToggleAgentPane action to zed_actions::agent module
- Fix borrow checker: clone active_thread entity before updating
- Fix type mismatch: use .map() instead of .and_then() for title_editor
@rtfeldman rtfeldman closed this Mar 5, 2026
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.

1 participant