Skip to content

Conversation

@xwang233
Copy link
Collaborator

Summary

Fixes a critical bug where the auto-merge workflow only fetched the first 30 results from GitHub API list operations, causing it to miss failed checks and incorrectly merge PRs.

Root Cause

PR #5578 had 2 failed GB200 tests that occurred early in the CI run. By the time the auto-merge action ran 4+ hours later, 27 newer successful statuses had been created. Since the workflow used unpaginated API calls (default limit: 30 items), the failed statuses were pushed beyond the first page and never detected.

Changes

Fixed 4 GitHub API calls to use github.paginate():

  1. listCommitStatusesForRef - Was only checking 30 of 57+ statuses
  2. checks.listForRef - Could miss failed checks if >30 exist
  3. issues.listComments - Could miss status comment if >30 comments
  4. pulls.list - Could miss PR if >30 open PRs on branch

Also simplified the pr_approved check logic which was deriving approval status from mergeable_state in a confusing way. The workflow now shows the actual mergeable_state value in status comments for transparency.

Impact

The auto-merge workflow will now correctly detect ALL failures regardless of how many statuses exist, preventing incorrect merges like #5578.

xwang233 and others added 2 commits November 21, 2025 21:56
This fixes a severe bug where the auto-merge workflow only checked the
first 30 commit statuses, causing it to miss failures and incorrectly
merge PRs with failing checks.

Root cause analysis:
- PR #5578 had 2 failed GB200 tests at 23:23-23:25 UTC
- By 03:29 UTC, 27+ new successful statuses pushed failures past position 30
- Workflow only fetched first page (30 items), saw 0 failures, and merged

Fixed 4 critical pagination issues:
1. listCommitStatusesForRef (line 140) - CRITICAL: Only saw 30 of 57 statuses
2. checks.listForRef (line 173) - Could miss failed checks if >30 exist
3. issues.listComments (line 349) - Wouldn't find status comment if >30 comments
4. pulls.list (line 64) - Could miss PR if >30 open PRs on branch

All API calls now use github.paginate() to retrieve complete results.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The pr_approved check was derived from mergeable_state using complex
logic that was often misleading. Some PRs showed "PR is approved" when
they weren't actually approved, because the logic conflated approval
status with other mergeable_state values.

Changes:
- Removed pr_approved and pr_approved_reason from checks object
- Removed complex approval logic based on mergeable_state interpretation
- Removed pr_approved from merge ready condition
- Removed "✅/❌ PR is approved" from status comment
- Added "ℹ️ PR mergeable_state: `value`" to status comment for transparency

The workflow now relies on GitHub's mergeable_state directly through
the pr_mergeable check, which already validates merge conflicts and
branch protection rules. Users can see the actual mergeable_state
value in the status comment to understand PR status.

This makes the logic cleaner and more reliable.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

Description

  • Fixed 4 critical GitHub API pagination bugs in auto-merge workflow

  • Changed API calls to use github.paginate() for complete results

  • listCommitStatusesForRef: was checking only 30 of 57+ statuses

  • checks.listForRef: could miss failed checks if >30 exist

  • issues.listComments: could miss status comment if >30 comments

  • pulls.list: could miss PR if >30 open PRs on branch

  • Simplified pr_approved logic and removed confusing mergeable_state interpretation

  • Added mergeable_state display in status comments for transparency

Changes walkthrough

Relevant files
Bug fix
auto-merge.yml
Fix GitHub API pagination bugs and simplify approval logic

.github/workflows/auto-merge.yml

  • Fixed 4 GitHub API calls to use github.paginate() for complete results
  • Removed confusing pr_approved check logic based on mergeable_state
    interpretation
  • Added pr_mergeable_state field and display in status comments
  • Simplified merge ready condition by removing pr_approved requirement
  • +17/-42 

    PR Reviewer Guide

    Here are some key observations to aid the review process:

    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review
    Logic Simplification

    The PR removes the complex pr_approved check logic that was deriving approval status from mergeable_state. While this simplifies the code and removes potential confusion, it should be verified that the simplified logic (checking only internal_ci_passed, no_failed_checks, and pr_mergeable) provides equivalent or better accuracy for determining when a PR is ready to merge. The removed logic was specifically handling branch protection rules and approval requirements.

            core.setFailed(`PR mergeable_state is ${pr.mergeable_state}`);
          } else {
            checks.pr_mergeable = true;
            core.info('✅ PR is mergeable');
          }
    
          // Determine if ready to merge
          const ready = checks.internal_ci_passed &&
                        checks.no_failed_checks &&
                        checks.pr_mergeable;
    
          return {
            ready: ready,
            pr_number: pr_number,
            checks: checks,
          };
    
    - name: Update auto-merge status comment
      if: always() && fromJSON(steps.pr.outputs.result).should_skip == false
      uses: actions/github-script@v7
      with:
        script: |
          const prData = ${{ steps.pr.outputs.result }};
          if (!prData || prData.should_skip) {
            core.info('PR data unavailable or should skip');
            return;
          }
          const pr_number = prData.number;
    
          // Get check results from previous step
          const checkResult = ${{ steps.check.outputs.result }};

    @greptile-apps
    Copy link
    Contributor

    greptile-apps bot commented Nov 22, 2025

    Greptile Overview

    Greptile Summary

    Fixed critical bug where auto-merge workflow only checked first 30 GitHub API results, causing it to miss failed checks and incorrectly merge PRs.

    Key Changes:

    • Added github.paginate() to 4 API calls: listCommitStatusesForRef, checks.listForRef, issues.listComments, and pulls.list
    • Removed confusing pr_approved logic that derived approval status from mergeable_state
    • Added mergeable_state display in status comments for transparency

    Impact:
    The workflow now correctly detects ALL failed checks regardless of pagination, preventing incorrect merges like #5578 where 2 failed GB200 tests were buried beyond the 30-item limit.

    Confidence Score: 5/5

    • This PR is safe to merge with minimal risk
    • The changes are straightforward pagination fixes using GitHub's official paginate() API. All 4 modified API calls follow the same pattern: wrapping existing calls with github.paginate() and adjusting response handling. The logic simplification removing pr_approved reduces complexity without affecting merge safety since mergeable_state check already validates branch protection rules including approvals.
    • No files require special attention

    Important Files Changed

    File Analysis

    Filename Score Overview
    .github/workflows/auto-merge.yml 5/5 Fixed critical pagination bugs in 4 GitHub API calls; simplified approval logic by removing confusing pr_approved check; added transparency by showing mergeable_state value

    Sequence Diagram

    sequenceDiagram
        participant GH as GitHub Event
        participant WF as Auto-merge Workflow
        participant API as GitHub API
        participant PR as Pull Request
    
        GH->>WF: Trigger (label/review/check_run/dispatch)
        
        Note over WF: Step 1: Get PR Details
        WF->>API: Get PR info
        alt check_run event
            WF->>API: paginate(pulls.list) - find PR by branch
        end
        API-->>WF: PR data (number, sha, mergeable_state)
        
        Note over WF: Step 2: Check All Conditions
        WF->>API: paginate(listCommitStatusesForRef, sha)
        API-->>WF: All commit statuses (nvfuser-ci, etc.)
        WF->>API: paginate(checks.listForRef, sha)
        API-->>WF: All check runs
        WF->>API: getCombinedStatusForRef(sha)
        API-->>WF: Combined status
        
        Note over WF: Validate all checks
        alt nvfuser-ci passed
            WF->>WF: ✅ internal_ci_passed
        else nvfuser-ci failed/pending
            WF->>WF: ❌ internal_ci_passed
        end
        
        alt no failed statuses/checks
            WF->>WF: ✅ no_failed_checks
        else has failures
            WF->>WF: ❌ no_failed_checks
        end
        
        alt mergeable and clean/unstable
            WF->>WF: ✅ pr_mergeable
        else conflicts or blocked
            WF->>WF: ❌ pr_mergeable
        end
        
        Note over WF: Step 3: Update Status Comment
        WF->>API: paginate(issues.listComments, pr_number)
        API-->>WF: All comments
        WF->>API: updateComment(status)
        API-->>PR: Comment updated with status
        
        Note over WF: Step 4: Merge if Ready
        alt all checks passed
            WF->>API: pulls.merge(squash)
            API-->>PR: PR merged
            WF->>API: removeLabel('enable-auto-merge')
        else checks failed
            WF->>WF: Skip merge
        end
    
    Loading

    Copy link
    Contributor

    @greptile-apps greptile-apps bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    1 file reviewed, no comments

    Edit Code Review Agent Settings | Greptile

    @xwang233
    Copy link
    Collaborator Author

    !build

    @xwang233 xwang233 added enable-auto-merge Auto-merge a PR when: 1) PR mergeable 2) Internal CI complete 3) No failures and removed enable-auto-merge Auto-merge a PR when: 1) PR mergeable 2) Internal CI complete 3) No failures labels Nov 22, 2025
    Copy link
    Collaborator

    @crcrpar crcrpar left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    looks clinical to me

    @xwang233 xwang233 merged commit 8c0d3ee into main Nov 22, 2025
    20 checks passed
    @xwang233 xwang233 deleted the fix-auto-merge-pagination branch November 22, 2025 06:31
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants