CI check reading uses `gh pr view <SHA>` which always fails — misleading "gh >= 2.50 required" parks pipeline

Author: yeungsinchunCreated Sep 29, 2026Updated Oct 1, 2026
Labelsbugexisting-pr

Summary

The CI-check-reading path builds a gh pr view <head commit SHA> invocation to read a PR's checks. gh pr view only accepts a PR number, URL, or branch name — never a bare commit SHA — so gh correctly fails with:

no pull requests found for branch <sha> (exit 1)

no-mistakes then surfaces this provider error as a misleading ask-user finding:

CI checks could not be read from the provider: … Verify that the provider CLI … For GitHub errors involving 'pr checks --json', gh >= 2.50 is required.

The installed gh here is 2.100.0 (well beyond 2.50) and works fine when queried correctly (gh pr checks 123 / gh pr view 123 succeeds against the same PR). This parked a real pipeline run for over 12 hours before a human noticed and manually skipped the broken step.

Installed no-mistakes version: v1.79.0 (reproduced there) Latest available at time of filing: v1.84.0 — checked changelog and current source (internal/scm/github/github.go, internal/pipeline/steps/ci_checks.go) — not yet fixed: both versions still route through the same gh pr view-based head resolution and the same generic ConsecutiveCheckErrorLimit → ciCheckReadFailureOutcome path that blames the gh version for any persistent GetChecks failure, including a SHA-as-selector misuse. No changelog entry between v1.79.0 and v1.84.0 mentions this (checked CHANGELOG.md 1.84.0, 1.83.x, 1.80.x — feature/bugfix lists show no SHA/selector fix). The fix therefore needs to handle a SHA-only identifier sensibly (resolve the correct PR number/ref first, e.g. via gh pr list --search <sha> or the repos/.../commits/<sha>/pulls API, then use that PR number/ref for the checks-reading call) and make the failure message identify the actual malformed selector rather than implying a gh version problem.

Exact malformed command

gh pr view <40-char head SHA> --repo <owner/name> --json headRefOid --jq .headRefOid
# or equivalent: gh pr view <sha> --json state / --json mergeable etc. when the pipeline
# passes the run's HeadSHA as the positional PR selector instead of the PR number/URL.

Expected gh behavior (correct):

gh: no pull requests found for branch <sha>

gh pr view help confirms it accepts [<number> | <url> | <branch>] — never a commit SHA. A SHA is not a branch and not a PR identifier.

Observed no-mistakes behavior:

  • internal/scm/github.GetChecks / getPRHeadSHA ultimately invoke gh pr view <selector> where <selector> is derived from the PR identity; if that identity is accidentally the commit SHA (e.g. sctx.Run.HeadSHA used as selector, or a SHA-only scm.PR stored without number/URL), the command fails deterministically.
  • internal/pipeline/steps.CIStep retries GetChecks up to ConsecutiveCheckErrorLimit (6) times, then parks with ciCheckReadFailureOutcome whose description unconditionally appends gh >= 2.50 is required, even though the error has nothing to do with gh version.

Environment

  • no-mistakes: v1.79.0 (reproduced), v1.84.0 checked — same behavior
  • gh: 2.100.0 (gh version 2.100.0 (2026-09-03) — gh pr checks 123 --json … succeeds)
  • Forge: GitHub (github.com), scm.ProviderGitHub via gh CLI
  • Pipeline step: CI monitor (internal/pipeline/steps/ci.go → scm.Host.GetChecks → internal/scm/github)

Minimal reproduction (without a live pipeline)

You can reproduce the underlying gh behavior with any repo that has a PR:

bash
gh --version                 # 2.100.0
gh pr view --help | head -n 20  # shows [<number> | <url> | <branch>]

# Pick a real head SHA from a PR (or any 40-char sha):
SHA=$(git rev-parse HEAD)  # or the PR's head SHA

# Malformed call (what no-mistakes currently does in the broken path):
gh pr view "$SHA" --json state --jq .state
# → gh: no pull requests found for branch <sha>   (exit 1)

# Correct calls (what it should do):
PR=123  # the PR number for that SHA
gh pr view "$PR" --json headRefOid --jq .headRefOid   # succeeds
gh pr checks "$PR" --json name,state,bucket            # succeeds (gh >=2.50 path)
gh pr list --search "$SHA" --state open --json number,url  # alternative: resolve SHA → PR first
# or: gh api repos/{owner}/{repo}/commits/$SHA/pulls

Inside no-mistakes unit-test harness this can be simulated by constructing an scm.PR with only HeadSHA (or with Number = headSHA) and calling Host.GetChecks against a fake gh that emulates real gh behavior:

go
pr := &scm.PR{Number: headSHA /* 40-char sha, not a number */, HeadSHA: headSHA}
_, err := host.GetChecks(ctx, pr)
// err contains "no pull requests found for branch <sha>"
// currently surfaced as "gh >= 2.50 required" after 6 retries

Or, more directly, call GetPRState / getPRHeadSHA with Number set to the SHA — the fake gh in internal/pipeline/fakecli will mimic the real failure if not mocked as success.

Expected fix

  • Do not pass a commit SHA as the positional argument to gh pr view / gh pr checks. Resolve the correct PR number/ref first:
    • If only a SHA is known, look up the PR via gh pr list --search <sha> (filter --state open and match headRefOid / head SHA) or via the API GET /repos/{owner}/{repo}/commits/<sha>/pulls or GET /repos/{owner}/{repo}/pulls?head=owner:branch, then use that PR number/URL for the subsequent gh pr view / gh pr checks calls.
    • If a PR number/URL is already known (the normal CI step case: scm.PR{Number: "123", URL: ".../pull/123", HeadSHA: "<sha>"}), keep using it — only add the SHA→PR lookup as a fallback when the selector would otherwise be a SHA or when prSelector would fail.
  • Make the parked finding actionable: when GetChecks fails persistently, surface the underlying gh stderr (no pull requests found for branch …) and, if the error looks like a SHA-as-branch misuse, suggest the correct invocation (gh pr view <number> / gh pr checks <number> or gh pr list --search <sha>) rather than unconditionally blaming gh >= 2.50. The version hint should remain only for actual --json / pr checks support errors.

Impact

  • Affects any GitHub run where the PR identity degrades to a SHA (e.g. a code path that stores HeadSHA where Number is expected, or a recovery that reconstructs scm.PR from the SHA alone). The CI monitor then spins for ConsecutiveCheckErrorLimit * pollInterval (~3 min at 30s poll, but with backoff up to hours before timeout) and then parks as ask-user with the wrong diagnostic, hiding the real cause.
  • Workaround today: manual axi respond --action fix or skip after noticing the parked run.

Checklist

  • gh pr view <sha> path eliminated or guarded with a SHA→PR lookup
  • ciCheckReadFailureOutcome no longer misattributes a selector error to gh version
  • Existing tests (go test ./..., especially internal/scm/github and internal/pipeline/steps) still pass

Fix PR to follow (fork → branch fm/no-mistakes-gh-pr-view-sha-fix-c1 → PR against main with Fixes #<this-issue>).