fix: improve worktree sync reliability for refresh operations#361
Open
whitmo wants to merge 1 commit intodlorenc:mainfrom
Open
fix: improve worktree sync reliability for refresh operations#361whitmo wants to merge 1 commit intodlorenc:mainfrom
whitmo wants to merge 1 commit intodlorenc:mainfrom
Conversation
Fix several issues in the worktree refresh path that could cause worktrees to drift out of sync or be left in broken states: - Extract resolveGitDir() helper that properly resolves relative gitdir paths to absolute, fixing silent failures in mid-rebase/merge detection - Handle rebase --abort failures explicitly instead of silently ignoring - Detect conflicts from stash pop after successful rebase - Add RefreshWorktreePreFetched() to eliminate redundant fetch when daemon has already fetched once per repo - Add tests for rebase conflict handling, pre-fetched refresh, and gitdir resolution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
Triage ReviewPriority: P0 (Worktree sync - roadmap item) Changes:
Recommendation: Safe to merge anytime - no conflicts with any other PR. |
5 tasks
Author
Local CI Verification (2026-03-12)
CI Status: No GitHub Actions checks are running — this is expected for first-time fork PRs. GitHub requires a maintainer to approve workflow runs for PRs from forks. Branch is rebased on |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
P0 Roadmap item: Worktree sync — Keep agent worktrees in sync with main as PRs merge.
Audited
internal/worktree/and the daemon refresh path, found and fixed several issues that could cause worktrees to drift out of sync or be left in broken states:Fix relative gitdir path resolution — Both
GetWorktreeState()andRefreshWorktree()extracted gitdir from the.gitfile but didn't resolve relative paths to absolute. This causedos.Stat()checks forrebase-merge/rebase-apply/MERGE_HEADto silently fail, potentially allowing refresh attempts on worktrees in mid-rebase or mid-merge state. Extracted a sharedresolveGitDir()helper.Fix rebase abort error handling — When rebase conflicts occurred,
git rebase --abortwas called but its error was silently discarded. If abort failed, the code would then attemptgit stash popon a dirty worktree, potentially corrupting state. Now explicitly checks abort result and returns early if abort fails.Detect stash pop conflicts — After a successful rebase, if
git stash popfailed due to conflicts,HasConflictsandConflictFileswere not set, leaving the agent with an unclear error message and no conflict file list. Now checks for conflicts on stash pop failure.Eliminate double fetch in daemon path — The daemon's
refreshWorktrees()fetched once per repo, then eachRefreshWorktree()call fetched again internally. AddedRefreshWorktreePreFetched()variant that skips the fetch, used by the daemon to avoid redundant network calls.Test plan
TestRefreshWorktree_RebaseConflict— verifies conflict detection, abort, and clean worktree state after conflictTestRefreshWorktreePreFetched— verifies pre-fetched variant works correctlyTestResolveGitDir— verifies gitdir resolution for both worktrees and regular reposresolveGitDir()helpergo test ./...)Opportunities noted (not implemented)
CommitsRebasedcount silently ignoresrev-listerrors — informational only, not critical🤖 Generated with Claude Code