[Repo Assist] Fix gh stack add: use last active branch index for top-of-stack check - #21
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
Previously, the middle-of-stack guard compared idx against len(s.Branches)-1 (the absolute last branch), which caused two bugs: 1. Blocked when on the last ACTIVE branch if merged branches sit above it. Example: trunk -> a -> b(merged), user on a β wrongly blocked with "switch to b" (a merged branch). 2. Allowed adding from a MERGED branch that happened to be last. Example: trunk -> a -> b(merged), user on b β not blocked, leading to a new branch created from a merged-branch position. Fix: compute lastActiveIdx (the index of the last non-merged branch) and use it for both the guard and the error message. The error message now points to the correct active branch instead of potentially a merged one. Note: IsQueued() is transient (set only by syncStackPRs, which runAdd does not call), so only IsMerged() (persisted) is checked here. Two new tests cover both scenarios. Co-authored-by: Copilot <[email protected]>
This was referenced Apr 26, 2026
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.
π€ This is an automated pull request from Repo Assist, an AI assistant.
Summary
Two related bugs in
gh stack add's middle-of-stack guard:Bug 1 β Blocked from adding at last active branch when merged branches sit above it
Before: With
trunk β a β b(merged)and on brancha:bis already merged β switching to it and adding makes no sense.After: Allowed.
ais the last active branch, so adding on top of it is correct.Bug 2 β Not blocked when on a merged branch that is the last overall branch
Before: With
trunk β a β b(merged)and on branchb:After: Blocked with a message pointing to
a(the last active branch).Root Cause
The guard compared
idxagainstlen(s.Branches)-1(absolute last branch index), which is wrong when the last branch is merged.Fix
Compute
lastActiveIdxβ the index of the last non-merged branch β and use it for both the guard condition and the error message.Note on queued branches
IsQueued()is a transient field populated bysyncStackPRs, whichrunAdddoes not call. Queued branches are therefore treated the same as active branches in this check. This is documented in a code comment.Tests Added
TestAdd_AllowedOnLastActiveBranchWithMergedAbove: verifies bug 1 is fixedTestAdd_BlockedOnMergedBranch: verifies bug 2 is fixed; also asserts the error message names the correct last active branchAll existing
TestAdd_*tests continue to pass with the new logic (verified by manual trace).Test Status
Tests could not be executed locally due to Go toolchain version requirements (
go.modrequiresgo 1.25.7) and network restrictions. CI (test.yml) will run the full test suite. The change is a targeted two-line condition replacement with a supporting loop; all edge cases are traced against the existing test scenarios above.Warning
The following domain was blocked by the firewall during workflow execution:
sum.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.