From 701f142a10dfc0bfe72c6346af8aad42d76b4b5b Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Tue, 25 Aug 2026 21:20:00 -0700 Subject: [PATCH 1/4] ci(backport): surface the gh error and use the PR token for validation The manual-dispatch validation discarded gh's stderr, so an auth failure and a missing PR both reported as "not found or inaccessible" with nothing to diagnose from. It also read the PR with GITHUB_TOKEN while the PR-creation step uses PR_GH_TOKEN; validation now prefers the same token and falls back. --- .github/workflows/pr-backport.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-backport.yaml b/.github/workflows/pr-backport.yaml index 9435ad77b0f..64507c180d3 100644 --- a/.github/workflows/pr-backport.yaml +++ b/.github/workflows/pr-backport.yaml @@ -43,9 +43,11 @@ jobs: exit 1 fi - # Validate PR exists and is merged - if ! gh pr view "${{ inputs.pr_number }}" --json merged >/dev/null 2>&1; then - echo "::error::PR #${{ inputs.pr_number }} not found or inaccessible." + # Validate PR exists and is merged. The gh error is surfaced rather + # than discarded: an auth failure and a genuinely missing PR are + # indistinguishable once it is swallowed. + if ! PR_VIEW_ERR=$(gh pr view "${{ inputs.pr_number }}" --json merged 2>&1 >/dev/null); then + echo "::error::PR #${{ inputs.pr_number }} not found or inaccessible: ${PR_VIEW_ERR}" exit 1 fi @@ -61,7 +63,9 @@ jobs: exit 1 fi env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Same token the PR-creation step uses; GITHUB_TOKEN was not able to + # read the PR here even with pull-requests: write. + GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} - name: Checkout repository From 40ee9851f72428338f129f9eeee02936aea83280 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Tue, 25 Aug 2026 21:25:58 -0700 Subject: [PATCH 2/4] ci(backport): fall back to GH_TOKEN rather than the auto-provided token The repo configures GH_TOKEN and PR_GH_TOKEN; GITHUB_TOKEN is the automatic Actions token and is the one that could not read the PR here. --- .github/workflows/pr-backport.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-backport.yaml b/.github/workflows/pr-backport.yaml index 64507c180d3..9cd942c2c1b 100644 --- a/.github/workflows/pr-backport.yaml +++ b/.github/workflows/pr-backport.yaml @@ -63,9 +63,11 @@ jobs: exit 1 fi env: - # Same token the PR-creation step uses; GITHUB_TOKEN was not able to - # read the PR here even with pull-requests: write. - GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GITHUB_TOKEN }} + # PR_GH_TOKEN is what the PR-creation step below already uses, and + # GH_TOKEN is the repo's other configured PAT. The auto-provided + # GITHUB_TOKEN could not read the PR here even with + # pull-requests: write, so it is not used as a fallback. + GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GH_TOKEN }} GH_REPO: ${{ github.repository }} - name: Checkout repository From ddc8f73afbfdd9fe71dc314ea9af6c7d6c753360 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Tue, 25 Aug 2026 21:39:04 -0700 Subject: [PATCH 3/4] ci(backport): use the PR token for every PR lookup in the job gh pr view fails with the auto-provided GITHUB_TOKEN even under pull-requests: write, so fixing only the validation step left the next two lookups broken. Hoist the working token to a job-level default. --- .github/workflows/pr-backport.yaml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr-backport.yaml b/.github/workflows/pr-backport.yaml index 9cd942c2c1b..e5bc6758c7a 100644 --- a/.github/workflows/pr-backport.yaml +++ b/.github/workflows/pr-backport.yaml @@ -33,6 +33,12 @@ jobs: pull-requests: write issues: write + # `gh pr view ` fails with the auto-provided GITHUB_TOKEN even with + # pull-requests: write, which is what silently broke manual dispatch. + # Steps needing a different token still set GH_TOKEN themselves. + env: + GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GH_TOKEN }} + steps: - name: Validate inputs for manual triggers if: github.event_name == 'workflow_dispatch' @@ -63,11 +69,6 @@ jobs: exit 1 fi env: - # PR_GH_TOKEN is what the PR-creation step below already uses, and - # GH_TOKEN is the repo's other configured PAT. The auto-provided - # GITHUB_TOKEN could not read the PR here even with - # pull-requests: write, so it is not used as a fallback. - GH_TOKEN: ${{ secrets.PR_GH_TOKEN || secrets.GH_TOKEN }} GH_REPO: ${{ github.repository }} - name: Checkout repository @@ -88,7 +89,6 @@ jobs: - name: Collect backport targets id: targets env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} run: | TARGETS=() @@ -157,7 +157,6 @@ jobs: FORCE_RERUN_INPUT: >- ${{ github.event_name == 'workflow_dispatch' && inputs.force_rerun || 'false' }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: >- ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} @@ -240,7 +239,6 @@ jobs: id: backport env: PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} run: | FAILED="" @@ -545,5 +543,3 @@ jobs: - name: Remove needs-backport label if: steps.filter-targets.outputs.skip != 'true' && success() run: gh pr edit ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} --remove-label "needs-backport" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From df646dcead3cc0900402465ca367b7cdafbc3ece Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Tue, 25 Aug 2026 21:45:52 -0700 Subject: [PATCH 4/4] ci(backport): let the failure path inherit the PR-readable token Comment on failures pinned github.token, so its manual-dispatch PR lookup failed the same way and the step posted a comment with an empty author mention and merge commit. --- .github/workflows/pr-backport.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-backport.yaml b/.github/workflows/pr-backport.yaml index e5bc6758c7a..14080345886 100644 --- a/.github/workflows/pr-backport.yaml +++ b/.github/workflows/pr-backport.yaml @@ -400,7 +400,6 @@ jobs: - name: Comment on failures if: steps.filter-targets.outputs.skip != 'true' && failure() && steps.backport.outputs.failed env: - GH_TOKEN: ${{ github.token }} BACKPORT_AGENT_PROMPT_TEMPLATE: | Backport PR #${PR_NUMBER} (${PR_URL}) to ${target}. Cherry-pick merge commit ${MERGE_COMMIT} onto new branch