I think I can explain the "it knows the branch is missing, then forgets" part. The two groups don't check the same thing.
- Create or update the pull request branch uses git.
git fetch origin automated/pnpm fails with couldn't find remote ref, so the action correctly sees that the branch doesn't exist.
- Pushing pull request branch, with
sign-commits: true, doesn't use git push. It creates the commit through the API and then calls createOrUpdateRef (src/github-helper.ts#L432-L463 at v8.1.1). That function decides whether the branch exists with repos.getBranch (GET /repos/{owner}/{repo}/branches/{branch}). Any successful response counts as "exists". Then it calls git.updateRef on heads/automated/pnpm.
GET /branches/{branch} follows branch renames. If a branch was ever renamed from a name, the endpoint returns 301 to the new name, and Octokit follows the redirect. You can see this on this repository, whose master was renamed to main:
$ curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" https://api.github.com/repos/peter-evans/create-pull-request/branches/master
301 https://api.github.com/repos/peter-evans/create-pull-request/branches/main
$ curl -s -o /dev/null -w "%{http_code}\n" https://api.github.com/repos/peter-evans/create-pull-request/git/ref/heads/master
404
So with branch: master and sign-commits: true, this action would log Branch master exists; Updating ref and then fail with Reference does not exist, which is your log. It would also explain the other details:
- Only one repo is affected: the redirect is per repository.
- The failure isn't transient: the redirect is permanent.
- Creating the branch first fixes it: a real branch takes precedence over the redirect.
- The
latest job (automated/pnpm-latest) in the same run worked.
My guess is that a branch in alveusgg/alveusgg was renamed from automated/pnpm at some point. I can't confirm it from outside, because automated/pnpm exists again since the rerun. The check: before the next scheduled run, delete automated/pnpm and run
gh api repos/alveusgg/alveusgg/branches/automated/pnpm --jq .name
If it prints a different name instead of a 404, that's the cause. Until there's a fix, keep the branch in place or use a branch name that was never renamed.
A possible fix in the action: base the existence check on the ref rather than the branch endpoint, for example git.getRef({ ...repository, ref: \heads/${branch}` }), which returns 404 for heads/masterabove. Or keepgetBranchand treat it as "exists" only whendata.name === branch. Either way, a renamed name falls through to createRef`.