Skip to content

Worktree reuse: pull origin/main and create new branch instead of deleting previous worktree #20

Description

@Christiantyemele

Problem

When a FORGE worker finishes a task and gets assigned a new ticket, the current WorkspaceManager deletes the existing worktree branch and recreates it from scratch. This destroys the previous branch and forces a full re-clone of the worktree, which is slow and loses history.

Expected Behaviour

When spawning a FORGE worker for a new task on the same slot (e.g. forge-1 gets ticket T-010 after completing T-005):

  1. Pull the latest origin/main into the existing worktree.
  2. Create a new branch (e.g. forge-1/T-010) from the updated origin/main.
  3. Reuse the existing worktree directory instead of deleting and recreating it.

This preserves previous branches (useful for audit/rollback) and is significantly faster.

Suggested Approach

  • In WorkspaceManager::create_worktree, check if the worktree directory already exists for the given pair ID.
  • If it does, run git fetch origin && git checkout origin/main && git pull instead of removing and re-creating.
  • Create the new branch from the fetched origin/main.
  • Optionally keep old branches around (pruned by age or on-demand).

Related Code

  • crates/pair-harness/src/workspace.rsWorkspaceManager::create_worktree / remove_worktree
  • crates/agent-forge/src/lib.rs — worktree lifecycle in batch handler

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions