Skip to content

fix(github): action branch detection and 422 handling#14322

Merged
rekram1-node merged 2 commits intoanomalyco:devfrom
elithrar:opencode/fix-rev-parsing
Feb 19, 2026
Merged

fix(github): action branch detection and 422 handling#14322
rekram1-node merged 2 commits intoanomalyco:devfrom
elithrar:opencode/fix-rev-parsing

Conversation

@elithrar
Copy link
Contributor

@elithrar elithrar commented Feb 19, 2026

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 at main's HEAD) and tries to create a PR — which GitHub rejects with 422 "No commits between main and ".

The sequence that triggers this:

  • automation creates opencode/issue127-... from main HEAD, captures HEAD SHA
  • Agent runs, creates its OWN branch (fix/...), commits, pushes, and creates a PR via gh pr create
  • branchIsDirty sees HEAD changed → dirty=true, but we're now on the agent's branch, not opencode/issue127-...
  • pushToNewBranch pushes opencode/issue127-... which still points to main → 422

Changes:

  • branchIsDirty now checks whether the agent switched branches during chat via git rev-parse --abbrev-ref HEAD. Returns switched: true when the current branch doesn't match the expected one.
  • All three event paths (repo events, PR events, issue events) handle switched by skipping infrastructure push/PR — the agent already handled it.
  • createPR verifies commits exist between base and head via git rev-list --count before calling the GitHub API, with a fetch fallback for shallow clones.
  • createPR catches 422 "No commits between" and returns null instead of throwing — callers fall back to commenting.

example failure

Pushing to new branch...
remote: 
remote: Create a pull request for 'opencode/issue127-20260219011637' on GitHub by visiting:        
remote:      https://github.com/cloudflare/somerepo/pull/new/opencode/issue127-20260219011637        
remote: 
To https://github.com/cloudflare/somerepo
 * [new branch]      opencode/issue127-20260219011637 -> opencode/issue127-20260219011637
branch 'opencode/issue127-20260219011637' set up to track 'origin/opencode/issue127-20260219011637'.
Creating pull request...
POST /repos/cloudflare/somerepo/pulls - 422 with id 5818:30FF9E:37E4EA:390DFD:6996671E in 421ms
Retrying after 5000ms...
POST /repos/cloudflare/somerepo/pulls - 422 with id 5818:30FF9E:37FE3A:3927D1:6996671E in 426ms
Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between main and opencode/issue127-20260219011637"} - https://docs.github.com/rest/pulls/pulls#create-a-pull-request
Creating comment...
Removing reaction...
Error: Validation Failed: {"resource":"PullRequest","code":"custom","message":"No commits between main and opencode/issue127-20260219011637"} - https://docs.github.com/rest/pulls/pulls#create-a-pull-request
Error: Process completed with exit code 1

@github-actions github-actions bot added needs:title needs:compliance This means the issue will auto-close after 2 hours. contributor labels Feb 19, 2026
@elithrar elithrar force-pushed the opencode/fix-rev-parsing branch 2 times, most recently from 272c7a8 to 39cb450 Compare February 19, 2026 19:46
@elithrar elithrar changed the title fix github action branch detection and 422 handling fix(github): action branch detection and 422 handling Feb 19, 2026
@elithrar elithrar marked this pull request as ready for review February 19, 2026 19:48
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.
@elithrar elithrar force-pushed the opencode/fix-rev-parsing branch from 39cb450 to d48ea5d Compare February 19, 2026 19:56
@rekram1-node rekram1-node removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Feb 19, 2026
@anomalyco anomalyco deleted a comment from github-actions bot Feb 19, 2026
@anomalyco anomalyco deleted a comment from github-actions bot Feb 19, 2026
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Feb 19, 2026
@rekram1-node rekram1-node removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Feb 19, 2026
@anomalyco anomalyco deleted a comment from github-actions bot Feb 19, 2026
@anomalyco anomalyco deleted a comment from github-actions bot Feb 19, 2026
@rekram1-node rekram1-node merged commit 1a1437e into anomalyco:dev Feb 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments