create_pull_request: extend #48900's non-fatal workflows-scope-timeout handling to the initial branch push
Title
create_pull_request: extend #48900's non-fatal workflows-scope-timeout handling to the initial branch push
Body
Analysis
update_pull_request.cjs's isNonFatalUpdateBranchError (added in #48900)
treats this GitHub-side error as non-fatal/retryable on pulls.updateBranch:
Unable to determine if workflow can be created or updated due to timeout;
`workflows` scope may be required.
create_pull_request.cjs's own initial git push for a brand-new branch has
no equivalent handling. The push is wrapped in a single try { ... } catch (pushError) { ... } with no retry loop and no message-based classification --
any push failure (including this exact transient error) goes straight to
core.error("Git push failed: ...") and falls back to creating a review
issue on the very first attempt (or a hard push_failed error if
fallback-as-issue is disabled).
create_pull_request.cjs already imports withRetry and
RATE_LIMIT_RETRY_CONFIG from error_recovery.cjs (used elsewhere in the
same file for fallback-issue creation), so the retry primitive already
exists in scope -- it's just not applied to the push itself.
Reproduction
Hit repeatedly against a large private monorepo, engine: copilot,
self-hosted runners, create_pull_request configured with a fixed
base-branch, allowed-branches pattern, labels, and draft: true:
- 4 consecutive push failures within ~2 hours, identical error message, same branch name each time -- all fell back to a review issue immediately, no retry attempted
- 1 prior success against the same repo/branch-name pattern two days earlier -- rules out a permanent per-repo condition, consistent with an intermittent GitHub-side timeout
Note: the error message is byte-identical to what #48900 already handles for
pulls.updateBranch, but that's a different call site (raw git push vs.
the REST "update branch" endpoint) -- we can't confirm from outside GitHub
whether these share one internal check or just similar wording. The fix
below only depends on the message matching, same as #48900's existing
classifier, so it holds either way.
Implementation Plan
-
Add error classification (
actions/setup/js/create_pull_request_helpers.cjsor inline increate_pull_request.cjs, mirroringisNonFatalUpdateBranchErrorinupdate_pull_request.cjs):- Add
isTransientPushError(error)matching the same message fragments already recognized there (`workflows` scope may be required,unable to determine if workflow can be created or updated).
- Add
-
Wrap the initial branch push in a retry (
create_pull_request.cjs, thetry/catcharound the push -- seecore.error(\Git push failed: ...`)`):- On catching a push error, check
isTransientPushError(pushError). - If transient, retry via the existing
withRetry/RATE_LIMIT_RETRY_CONFIGpattern already imported and used elsewhere in this file, instead of immediately falling through to the fallback-issue path. - If retries are exhausted or the error isn't transient, keep the existing fallback-issue/hard-error behavior unchanged.
- On catching a push error, check
-
Add a test (
actions/setup/js/create_pull_request.test.cjs), mirroringupdate_pull_request.test.cjs's"should continue title/body updates when updateBranch gets workflows-scope-required 403"test:- Mock the push to reject once with the transient message, succeed on retry -- assert the PR is created without falling back to an issue.
- Mock the push to reject persistently -- assert it still falls back to the review issue after retries are exhausted (not an infinite loop).
Acceptance Criteria
- A
create_pull_requestpush that fails once with theworkflows-scope-timeout message and succeeds on retry results in a real PR, not a fallback issue. - A push that fails persistently with that message still falls back to a review issue after a bounded number of retries (no behavior change for genuinely broken pushes).
Found a second instance of this same gap class while building on top of create_pull_request's fix -- worth tracking here rather than a separate issue since it's the same underlying pattern.
push_to_pull_request_branch has the identical gap, one file over
push_to_pull_request_branch.cjs's main push (pushSignedCommits, which is what signed-commits: false actually resolves to -- a real git push) has zero retry and zero classification for the workflows-scope-timeout error. Confirmed by reading the file directly: isWorkflowsScopeRejection already exists in this same file and is applied to two other paths (the review-branch push and the fallback-branch push), just not to the primary pushSignedCommits call most callers actually hit.
Slightly worse than create_pull_request's gap in one respect: for a plain (non-fast-forward) push failure, this handler produces no fallback issue and no fallback PR at all -- fallback-as-pull-request only fires when isNonFastForward is true. A transient timeout here just returns a hard { success: false, error_type: "push_failed" } with nothing left behind for a caller to recover from.
Proposed fix
Same shape as the original ask, and arguably smaller since the classifier is already present in this file:
- Apply
isWorkflowsScopeRejection(or the equivalent transient-error check) to the primarypushSignedCommitscatch block, not just the review-branch/fallback-branch paths. - Wrap that push in the same
withRetry/RATE_LIMIT_RETRY_CONFIGpattern already used elsewhere. - Add a test mirroring the existing review-branch/fallback-branch coverage for this error message, but against the primary push path.
Evidence
Real, working downstream recovery for this exact gap: we now poll the target PR's HEAD commit (no fallback artifact to search for, unlike create_pull_request) and re-push from the agent's own bundle artifact when it hasn't moved after a bounded wait. Confirms the failure mode is real and reproducible, not hypothetical -- happy to share more detail if useful for a repro case.