Skip to content

feat(#1380): ensureWorktree "recreating fresh" rebuilds a PR branch from base and drops its commits; qa re-run reviews the wrong tree - #1403

Merged
admarble merged 6 commits into
mainfrom
feature/1380-ensureworktree-recreating-fresh-rebuilds-a-pr-bran
Oct 10, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/1380-ensureworktree-recreating-fresh-rebuilds-a-pr-bran

Conversation

@admarble

@admarble admarble commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a PR's worktree was more than 5 commits behind base and had nothing uncommitted or unpushed, ensureWorktree deleted the local branch and cut a new one from base, ignoring origin/<branch>. A qa re-run then reviewed base without the PR's commits.

Now:

  • resolveRecreateStartRef fetches the branch and picks origin/<branch> when the remote has it, otherwise the run's base ref.
  • Containment guard: the recreate proceeds only if that start ref already contains the worktree's HEAD (merge-base --is-ancestor). If it doesn't (an offline fetch, or a local-only branch with commits of its own), sequant prints a warning in the existing "commits behind" style and keeps the worktree.
  • The recreate uses git worktree add -B <branch> <path> origin/<branch>, so the branch keeps its commits and its upstream tracking.
  • The recorded base (sequantBaseRef) stays the run's base, not origin/<branch>.

ADR-0013 records the design choice. It was numbered 0011 in the exec, then renumbered: 0011 is taken by open PR #1370, and 0012 merged in #1392.

Fixes #1380

Acceptance criteria

  • AC-1: a pushed branch is recreated from origin/<branch> with all its commits. worktree-manager.test.ts › 1380 AC-1, which the runner extended to assert that branch.<b>.remote/merge still track the PR branch.
  • AC-2: with no origin/<branch>, recreate cuts from the base as before, for a local-only branch whose HEAD is on base (1380 AC-2 recreates a local-only branch…). A local-only branch with commits of its own is kept, as on main (1380 AC-2 keeps a local-only branch…, added by the runner). The spec and QA said ensureWorktree "recreating fresh" rebuilds a PR branch from base and drops its commits; qa re-run reviews the wrong tree #1380's guard changed this case. It doesn't: with the guard disabled the test still passes, and it passes against main's worktree-manager.ts, because the existing hasUnpushedCommits check ("Keeping existing worktree with WIP commits") already keeps it. AC-2's text was clarified on ensureWorktree "recreating fresh" rebuilds a PR branch from base and drops its commits; qa re-run reviews the wrong tree #1380 to match.
  • AC-3: a recreate that would drop commits warns and keeps the worktree (1380 AC-3).
  • AC-4 / graph OQ-2: the spec answered OQ-2 from main @ afc37bd0. The recreate uses the run's resolved base through computeWorktreeBaseRef(baseBranch, …), the same value ResolvedRun.baseBranch feeds, and records it (1380 AC-4).

Mutation-verified: AC-1 — recreate path changed to worktree add -B <branch> <path> <baseRef> (base instead of origin/<branch>); src/lib/workflow/worktree-manager.test.ts > #1380 ensureWorktree recreate keeps the branch's commits > 1380 AC-1 recreates a pushed branch from origin/<branch>, keeping its commits failed alone (1 of 4); restored.

Mutation-verified: AC-3 — containment guard disabled (if (false && contained.status !== 0)); src/lib/workflow/worktree-manager.test.ts > #1380 ensureWorktree recreate keeps the branch's commits > 1380 AC-3 keeps the worktree when the start ref lacks the branch's commits failed alone; restored.

Mutation-verified: AC-4 — recordWorktreeBaseRef given recreateFrom ?? baseRef; src/lib/workflow/worktree-manager.test.ts > #1380 ensureWorktree recreate keeps the branch's commits > 1380 AC-4 records the run's base, not origin/<branch>, after a recreate failed alone; restored.

Follow-up ledger

Runner verification (graph-2026-10-freeze, wave 2)

🤖 Generated with Claude Code

…pping its commits

Entire-Checkpoint: cf3f53d5ba35
…rktree-recreating-fresh-rebuilds-a-pr-bran

# Conflicts:
#	docs/adr/README.md
@admarble
admarble merged commit 0f2a24c into main Oct 10, 2026
8 checks passed
@admarble
admarble deleted the feature/1380-ensureworktree-recreating-fresh-rebuilds-a-pr-bran branch October 10, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ensureWorktree "recreating fresh" rebuilds a PR branch from base and drops its commits; qa re-run reviews the wrong tree

1 participant