gh-aw icon indicating copy to clipboard operation
gh-aw copied to clipboard

create_pull_request: extend #48900's non-fatal workflows-scope-timeout handling to the initial branch push

Open ekbritecore opened this issue 2 months ago • 1 comments

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

  1. Add error classification (actions/setup/js/create_pull_request_helpers.cjs or inline in create_pull_request.cjs, mirroring isNonFatalUpdateBranchError in update_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).
  2. Wrap the initial branch push in a retry (create_pull_request.cjs, the try/catch around the push -- see core.error(\Git push failed: ...`)`):

    • On catching a push error, check isTransientPushError(pushError).
    • If transient, retry via the existing withRetry/RATE_LIMIT_RETRY_CONFIG pattern 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.
  3. Add a test (actions/setup/js/create_pull_request.test.cjs), mirroring update_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_request push that fails once with the workflows-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).

ekbritecore avatar Sep 17 '26 17:09 ekbritecore

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:

  1. Apply isWorkflowsScopeRejection (or the equivalent transient-error check) to the primary pushSignedCommits catch block, not just the review-branch/fallback-branch paths.
  2. Wrap that push in the same withRetry/RATE_LIMIT_RETRY_CONFIG pattern already used elsewhere.
  3. 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.

ekbritecore avatar Sep 17 '26 19:09 ekbritecore