fix(github): action branch detection and 422 handling#14322
Merged
rekram1-node merged 2 commits intoanomalyco:devfrom Feb 19, 2026
Merged
fix(github): action branch detection and 422 handling#14322rekram1-node merged 2 commits intoanomalyco:devfrom
rekram1-node merged 2 commits intoanomalyco:devfrom
Conversation
272c7a8 to
39cb450
Compare
detect when agent switches branches during chat and skip infrastructure push/PR creation to avoid pushing stale refs. also handle 422 'No commits between' gracefully in createPR and verify commits exist via rev-list before PR creation.
39cb450 to
d48ea5d
Compare
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.
When the agent creates its own branch, commits, and pushes during
chat(), the infrastructure's post-chat flow pushes a stale branch ref (still pointing atmain's HEAD) and tries to create a PR — which GitHub rejects with 422 "No commits between main and ".The sequence that triggers this:
opencode/issue127-...frommainHEAD, captures HEAD SHAfix/...), commits, pushes, and creates a PR viagh pr createbranchIsDirtysees HEAD changed →dirty=true, but we're now on the agent's branch, notopencode/issue127-...pushToNewBranchpushesopencode/issue127-...which still points tomain→ 422Changes:
branchIsDirtynow checks whether the agent switched branches during chat viagit rev-parse --abbrev-ref HEAD. Returnsswitched: truewhen the current branch doesn't match the expected one.switchedby skipping infrastructure push/PR — the agent already handled it.createPRverifies commits exist between base and head viagit rev-list --countbefore calling the GitHub API, with a fetch fallback for shallow clones.createPRcatches 422 "No commits between" and returnsnullinstead of throwing — callers fall back to commenting.example failure