Skip to content

Wave 2.9 fast-path swap: 3-checkout dance for X-canonical + Y-warm case #3

@ashmitb95

Description

@ashmitb95

Background

Wave 2.9's standard switch recipe (commit 4f41c99) handles the case where Y is warm + X is canonical via:

  • worktree_remove(Y) — release Y's branch
  • evacuate(X) → stash + checkout Y in main + worktree_add X + pop in worktree

= 5 git ops per repo.

The fast-path 3-checkout swap (originally suggested by user during 2.9 design — see ~/.claude/plans/wave-2-9-switch-canonical.md "Atomicity" section, Layer 2) replaces that with:

  1. cd main && git stash push -u (if dirty)
  2. cd main && git checkout <default> — frees X
  3. cd worktree-Y && git checkout X — worktree adopts X, Y freed
  4. cd main && git checkout Y
  5. mv .canopy/worktrees/Y/<repo> .canopy/worktrees/X/<repo> — naming convention demands the dir name match the feature
  6. git worktree repair — fix gitlinks after mv
  7. cd new-X-worktree && git stash pop (if stashed)

= 7 ops per repo (more than the standard recipe!).

Why "fast" then?

The win is purely from skipping git worktree add's full-file-walk checkout. For huge repos that's 5-30 sec; for canopy's small test repos it's negligible.

Cost / risk

  • More steps = more half-flip surface, especially without the rollback walker (issue #2)
  • mv + git worktree repair are new failure modes
  • The naming-rename step is non-trivial: it has to update the .git/worktrees/ dir too
  • Conditional logic (when does fast-path apply? what if main is dirty? what if both X and Y have warm worktrees but the pre-check missed Y?) — adds branching to switch.py

Verdict (deferred)

Ship only when:

  • Real-world latency complaint from a user with a huge-repo workspace
  • Or after issue #2 (journal + rollback walker) lands so the extra steps don't increase blast radius

For now, the standard recipe is correct, predictable, and scales fine for canopy's typical workspaces.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions