Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 19, 2025

This PR addresses the critical issues identified in PR #7027 reviews, particularly @ZainRizvi's report of incorrect runner statistics and type safety concerns.

Issues Fixed

Pagination Bug (Zain's Review)

The API was only fetching the first 100 runners from GitHub's API but returning the total count from the API response, leading to inconsistent statistics like "3189 total runners, 96 online, 46 busy" where the math clearly doesn't add up.

Root Cause: The original implementation used a single API call with per_page: 100, but GitHub's runners API paginates results. For organizations with 3000+ runners, this meant:

  • total_count: 3189 (from GitHub API)
  • runners.length: 100 (only first page fetched)
  • onlineRunners: 96 (calculated from incomplete data)
  • busyRunners: 46 (calculated from incomplete data)

Solution: Implemented proper pagination with fetchAllRunners() function that:

  • Fetches all pages until no more runners remain
  • Uses actual fetched runner count for total_count
  • Ensures statistics are calculated from complete dataset

Type Safety Issues (Copilot Review)

The code used any types for GitHub API responses, defeating TypeScript's type safety benefits.

Solution:

  • Added proper TypeScript interfaces (GitHubRunnerLabel)
  • Implemented type-safe mapping with validation
  • Added fallback handling for unknown status/type values
  • Maintained backwards compatibility

Technical Changes

  • torchci/pages/api/runners/[org].ts: Added pagination logic and proper TypeScript interfaces
  • torchci/test/runners-api.test.ts: Added comprehensive test coverage

Behavior Changes

Before: API returned mathematically inconsistent numbers

{
  "total_count": 3189,
  "runners": [/* only 100 runners */]
}

After: API returns accurate, consistent numbers

{
  "total_count": 3189,
  "runners": [/* all 3189 runners */] 
}

The fix ensures that for any organization, the runner statistics will be mathematically consistent and calculated from the complete dataset.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link

vercel bot commented Aug 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
torchci Ready Ready Preview Aug 19, 2025 11:26pm

Copy link

meta-cla bot commented Aug 19, 2025

Hi @Copilot!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@Copilot Copilot AI changed the title [WIP] Fix all the concerns mentioned in @pytorch/test-infra/pull/7027 reviews, esp the review by Zain Fix pagination bug and type safety issues in GitHub runners API Aug 19, 2025
@Copilot Copilot AI requested a review from ZainRizvi August 19, 2025 23:24
Copilot finished work on behalf of ZainRizvi August 19, 2025 23:24
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.

2 participants