fix: fetch origin before creating worktree to prevent stale branches#488
fix: fetch origin before creating worktree to prevent stale branches#488lukeinglis wants to merge 3 commits into
Conversation
create_worktree() previously branched from the local base branch, which could be behind origin after a PR merge. This caused the CEO to research stale code and propose duplicating already-completed work. Now fetches origin/<base_branch> before creating the worktree. Falls back to the local branch for repos without a remote. Logs a warning with the commit delta when the local branch is behind. Closes #487 Signed-off-by: Luke Inglis <lukeinglis21@yahoo.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #488 +/- ##
==========================================
- Coverage 87.31% 86.97% -0.34%
==========================================
Files 61 64 +3
Lines 9339 9956 +617
==========================================
+ Hits 8154 8659 +505
- Misses 1185 1297 +112 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Prevents the factory from hanging when the remote is unreachable but not immediately refusing connections. Falls back to the local branch on timeout, same as when there is no remote. Signed-off-by: Luke Inglis <lukeinglis21@yahoo.com>
Move the git author/committer env dict to a single module-level GIT_ENV constant and use it in all four fixtures that were defining it inline. Signed-off-by: Luke Inglis <lukeinglis21@yahoo.com>
|
@ceo-review |
There was a problem hiding this comment.
✅ Factory Review: KEEP
Verdict: KEEP
Reason: Solves stale branch problem — fetch before worktree creation prevents wasted research cycles. Tests comprehensive (27/27 pass, 6 new). Minor edge case identified (should validate remote ref exists) — recommended 3-line fix but not blocking.
Guard Checks
| Check | Result |
|---|---|
| correctness | ✅ PASS |
| security | ✅ PASS |
| edge_cases | ❌ PASS_WITH_REC |
| tests | ✅ PASS |
| style | ✅ PASS |
| scope | ✅ PASS |
Posted by Factory CEO
Detailed Review FindingsEdge Case IdentifiedLocation: Issue: Missing validation that the remote ref exists before returning it. Scenario: # Local repo has a 'develop' branch, remote does not
git fetch origin develop # succeeds (returncode 0) but fetches nothing
git rev-parse origin/develop # fails (returncode 128)
# But _fetch_and_resolve_base() returns "origin/develop" regardlessImpact: If fetch succeeds but Recommended Fix (3 lines): # After line 40, before logging worktree_fetch_ok:
if remote_rev.returncode != 0:
log.warning("worktree_fetch_skipped", reason="remote_ref_missing", base=base_branch)
return base_branchSeverity: Minor — unlikely in practice (requires a branch to exist locally but not on the remote). Worst case is a clear git error, not silent failure. Test Count NotePR description says "26/26 worktree tests pass (5 new)" but actual count is 27/27 tests pass (6 new tests added). This is just documentation drift — the tests themselves are excellent. What Works Well✅ Solves the core problem — Prevents wasted research cycles when Recommendation: The PR is merge-worthy as-is. The edge case identified is minor and self-evident when it occurs. Adding the 3-line validation check would improve robustness, but is not a hard blocker. |
Summary
create_worktree()now runsgit fetch origin <base_branch>before creating the worktree, branching fromorigin/<base_branch>instead of the (possibly stale) local branchProblem
When a PR is merged to
origin/mainbut the user hasn't pulled locally, the factory creates a worktree from the stale localmain. The CEO then researches outdated code, distills an improvement spec, and proposes re-doing work that was already completed in the merged PR. The failure mode is silent and expensive: the entire research/distill/strategy cycle is wasted.Closes #487
Test plan
TestFetchAndResolveBase: verifiesorigin/mainis returned when behind, when up-to-date, and that local branch is returned when there's no remoteTestCreateWorktreeWithRemote: end-to-end test confirming the worktree contains commits from origin that the local branch doesn't haveruff checkandmypyclean