fix(foreman): anchor recovery soft-reset at merge-base branch point#1044
Merged
Merged
Conversation
repo.BaseBranchSHA (defilantech#995) returns the CURRENT upstream tip at recovery time, but the task branch was cut from the upstream tip at branch-cut time (defilantech#813). If upstream advanced between those points, SoftResetToBase's `git reset --soft <baseBranchSHA>` re-staged the intervening upstream delta into the recovered commit (squashed alongside the model's edits). Anchor the reset at the true branch point instead: merge-base(base, HEAD), the lowest common ancestor of the current upstream tip and the task branch = exactly where the branch was cut. The commits-ahead count is anchored there too, keeping the two consistent. Only the model's own commits are re-staged; the upstream delta between branch point and tip is preserved on the branch, never re-staged. Closes defilantech#1002 Signed-off-by: Jory Irving <jory.irving@stackadapt.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Defilan
approved these changes
Jul 10, 2026
Defilan
left a comment
Member
There was a problem hiding this comment.
Clean fix, Jory. Verified the reasoning: anchoring the soft-reset at merge-base(base, HEAD) instead of the current tip means a mid-run upstream advance can't drag the intervening delta into the recovered commit — same stale-base family as #813/#1042, on the mid-run axis. Real-git tests reproduce it well and pass locally. Approving.
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.
What
Anchor the recovery soft-reset at the true branch point —
merge-base(base, HEAD)— instead of the current upstream tip, so intervening upstream delta is never squashed into a recovered self-commit.Why
Fixes #1002
repo.BaseBranchSHA(#995) returns the current upstream tip at recovery time, but the branch point was captured at task-branch-cut time inCreateBranchFromUpstream(#813). If upstream advances between those two points,SoftResetToBase'sgit reset --soft <baseBranchSHA>reverts the intervening upstream delta into the index andrepo.Commitsquashes it into the recovered commit. Same class as the #982/#813 stale-base bug, along the mid-run-advance axis.How
SoftResetToBasenow resolvesbranchPoint := git merge-base <base> HEAD— the lowest common ancestor of the current upstream tip and the task branch, i.e. exactly where the branch was cut — and soft-resets there. The commits-ahead count is anchored at the samebranchPoint, so the guard and the reset stay consistent. The intervening upstream delta stays on the branch and is never re-staged; only the model's own commits are recovered. Matches how the normal commit path already behaves (it never re-anchors).Contained to
pkg/foreman/agent/repo/commit.go— the executor caller is unchanged (it already passesBaseBranchSHA). No CRD/API change.Checklist
TestSoftResetToBase_AnchorsAtBranchPointNotUpstreamTip(upstream advances mid-run → only the model's file is staged, the upstream delta is not re-staged);TestSoftResetToBase_NoSelfCommitIsNothingToCommit(no self-commit + advanced upstream →ErrNothingToCommit). ExistingTestRecoverSelfCommitsOrNoChange_*still pass.make testpasses locally (full suite; envtest included)make lintpasses locally (0 issues)git commit -s) per DCOSoftResetToBaseupdated)