fix(worktree): use hard reset to correct file tree when branch base is wrong#1982
Open
Tibsfox wants to merge 2 commits intogsd-build:mainfrom
Open
fix(worktree): use hard reset to correct file tree when branch base is wrong#1982Tibsfox wants to merge 2 commits intogsd-build:mainfrom
Tibsfox wants to merge 2 commits intogsd-build:mainfrom
Conversation
…s wrong (gsd-build#1981) The worktree_branch_check mitigation detects when EnterWorktree creates branches from main instead of the current feature branch, but used git reset --soft to correct it. This only fixed the commit pointer — the working tree still contained main's files, causing silent data loss on merge-back when the agent's commits overwrote feature branch code. Changed to git reset --hard which safely corrects both pointer and file tree (the check runs before any agent work, so no changes to lose). Also removed the broken rebase --onto attempt in execute-phase.md that could replay main's commits onto the feature branch, and added post-reset verification that aborts if the correction fails. Updated documentation from "Windows" to "all platforms" since the upstream EnterWorktree bug affects macOS, Linux, and Windows alike. Closes gsd-build#1981 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…latform Aligns with the workflow file updates — the EnterWorktree base-branch bug affects all platforms, not just Windows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Fixes the
worktree_branch_checkmitigation that was usinggit reset --softto correct wrong worktree base branches. The soft reset only moved the commit pointer — the working tree still containedmain's files, causing silent data loss when the agent's commits overwrote feature branch code on merge-back.--softto--hardin all 4 workflow files that spawn worktree agents (execute-phase.md, quick.md, execute-plan.md, diagnose-issues.md). This is safe because the check runs as the very first action before any agent work — there are no uncommitted changes to lose.git rebase --ontoattempt in execute-phase.md that could replaymain's commits onto the feature branch if it succeeded.exit 1if the correction fails, preventing the agent from proceeding on a wrong branch base.EnterWorktreebug affects macOS, Linux, and Windows alike (as reported in Worktree isolation branches from main instead of current branch (macOS, not just Windows) #1957).Why
--softwas wronggit reset --softmoves HEAD but preserves the working tree and index. After the reset:main's files ✗main's files ✗The agent then committed diffs against
main's file state on top of the feature branch history. On merge-back, these commits overwrote the feature branch withmain's code — exactly the data loss reported in #1957.Why
--hardis safe hereThe
worktree_branch_checkruns as "FIRST ACTION before any other work" in a freshly-created worktree. At that point the agent has made zero uncommitted changes and done zero work.git reset --hardcorrectly resets the commit pointer, working tree, and index to the expected feature branch state.Closes #1981
Related: #1957
Test plan
stale-colon-refs.test.cjsunrelated to this change)reset --soft.*EXPECTED_BASEreferences in the codebase/gsd-execute-phasewithworkflow.use_worktrees: trueon a feature branch diverged from main — confirm worktree agents operate on the correct file tree🤖 Generated with Claude Code