Skip to content

gh pr checks exits 1 for "no checks reported", the same code as failed checks #14882

Open

Agent suggestions

Public preview

Description

@konard

Describe the bug

gh pr checks <pr> on a pull request whose head commit has no check runs or statuses prints no checks reported on the '<branch>' branch and exits 1. Failed checks also exit 1, so a script or an AI coding agent that runs gh pr checks just to look at CI state cannot tell "nothing ran" from "something failed" without parsing the message.

This was asked for in #9390, but #9452 closed that issue by documenting only exit code 8 (pending). The "no checks" case still exits 1 in gh 2.102.0, and gh pr checks --help doesn't document it. #9682 covers only the --required variant ("no required checks reported").

Steps to reproduce the behavior

On any pull request without checks, for example a merged PR in a repository whose Actions did not run for it:

$ gh --version
gh version 2.102.0 (2026-09-30)
$ gh pr checks 414 --repo G-Ivan-A/mango_ba_prompts; echo "exit=$?"
no checks reported on the 'issue-413-e424ca2a7c62' branch
exit=1
$ gh pr view 414 --repo G-Ivan-A/mango_ba_prompts --json statusCheckRollup --jq '.statusCheckRollup | length'; echo "exit=$?"
0
exit=0

A PR with a failing check gives the same exit=1.

Expected vs actual behavior

  • Expected: "no checks" can be told apart from "checks failed" by exit code, and the code is documented under "Additional exit codes" in gh pr checks --help.
  • Actual: both exit 1, and only the message text tells them apart.

Impact

In link-assistant/hive-mind#3922, an AI agent ended a successful session with …; gh pr checks 414 --repo … to look at the PR state. Because the shell exited 1, the orchestrator treated the last tool call as a failed verification and marked the whole session as failed. electron/electron#49630 hit the same problem in CI scripts.

Workarounds

  • gh pr view <pr> --json statusCheckRollup --jq '.statusCheckRollup | length' returns 0 with exit 0 when there are no checks.
  • Match the exact text no checks reported on the '<branch>' branch on exit 1. This is what hive-mind now does.

Suggested fix

In pkg/cmd/pr/checks/checks.go, populateStatusChecks returns a plain error:

if len(statusCheckRollup.Nodes) == 0 {
    return nil, checkCounts{}, fmt.Errorf("no checks reported on the '%s' branch", pr.HeadRefName)
}

Either of these would fix it:

  1. Return cmdutil.NewNoResultsError(fmt.Sprintf("no checks reported on the '%s' branch", pr.HeadRefName)). internal/ghcmd/cmd.go already maps NoResultsError to exit 0 and prints the message on a TTY, as gh label list, gh workflow list and others do. The --watch loop would need to keep treating "no checks yet" as "keep waiting" (see handle "no checks" races in pr checks --watch #7401).
  2. If changing exit 1 → 0 is too breaking for scripts that rely on it, return a distinct, documented code for "no checks". This mirrors exit 8 for pending, and the same code could serve the --required case in gh pr checks <pr> --required should not fail when there are no required checks #9682.

In both cases, add the code to the "Additional exit codes" help text.

Activity

  1. cli-triage commented on Oct 31, 2026

    @cli-triage

    Thanks for the detailed report and investigation. I verified the current source: populateStatusChecks in pkg/cmd/pr/checks/checks.go#L303 returns a plain fmt.Errorf("no checks reported on the '%s' branch", ...) when the status check rollup is empty, which propagates as a generic error and exits 1 — the same as counts.Failed > 0 returning cmdutil.SilentError. By contrast, the pending case at L250-251 uses the documented cmdutil.PendingError, mapped to exit code 8, and the help text's "Additional exit codes" section (L73-74) only documents that one. So the hypothesis — that "no checks" and "checks failed" are indistinguishable by exit code because the former isn't routed through a distinct sentinel error — matches the code. I didn't find an exact duplicate; a related issue (#9682) asked for a similar distinction but only for the --required variant and its linked fix was closed without merging. I'm suggesting bug, priority-3 (a workaround exists via message-matching or gh pr view --json statusCheckRollup), and gh-pr for the affected command.

    Generated by Issue Triage (skills-driven) for #14882 · copilot · auto · 80.2 AIC · ⊞ 4.5K · ◷

  2. Tidehyc commented on Nov 2, 2026

    @Tidehyc

    Hi, before writing a patch I'd like to confirm the intended contract here, since #9682 is still open with related acceptance criteria. When gh pr checks finds no checks at all on the target branch, should it: (1) exit with a new distinct non-zero code, (2) exit 0, or (3) keep exit 1 but signal the empty case some other way? And how should 'no checks' be distinguished from 'checks not yet registered' (a just-created PR whose CI hasn't attached yet)? Happy to implement once the direction is confirmed.

  3. added
    enhancement
    gh-pr
    on Nov 2, 2026
  4. removed
    needs-triage
    on Nov 2, 2026
  5. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgh-pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions