Skip to content

Retry transient GitHub errors in winget ingester#48775

Merged
allenhouchins merged 6 commits into
mainfrom
allenhouchins-update-winget-ingester
Jul 6, 2026
Merged

Retry transient GitHub errors in winget ingester#48775
allenhouchins merged 6 commits into
mainfrom
allenhouchins-update-winget-ingester

Conversation

@allenhouchins

@allenhouchins allenhouchins commented Jul 6, 2026

Copy link
Copy Markdown
Member

This pull request improves the reliability and efficiency of the Winget ingester by introducing robust retry logic for fetching manifest files and directory contents, switching to CDN-backed raw file downloads, and updating tests to cover these changes. The main focus is on handling transient errors (like rate limits and server errors) gracefully, preventing ingestion failures due to temporary issues with GitHub's API or file servers.

Reliability improvements for manifest fetching:

  • Added getRawManifestFile method to fetch manifest files directly from raw.githubusercontent.com (or a testable override), avoiding GitHub API rate limits and using CDN-backed downloads. This method implements retry logic for transient HTTP errors (e.g., 429, 5xx), with exponential backoff, and returns a specific error for missing files. (ee/maintained-apps/ingesters/winget/ingester.go)
  • Introduced getRepoDirContents method to list repository directories via the GitHub API with retry logic for transient errors, improving resilience against API throttling. (ee/maintained-apps/ingesters/winget/ingester.go)

Ingestion logic updates:

  • Updated ingestOne to use the new retry-enabled methods for both directory listing and manifest file fetching, ensuring that only true missing files are skipped and transient errors cause a controlled failure, not silent downgrades. (ee/maintained-apps/ingesters/winget/ingester.go) [1] [2]

Test enhancements:

  • Modified test server and test cases to simulate the new raw file fetching logic, including scenarios for retries, maximum attempts, and handling of 404 errors. Added comprehensive tests for both getRawManifestFile and getRepoDirContents retry behavior. (ee/maintained-apps/ingesters/winget/ingester_test.go) [1] [2]
  • Improved test reliability by reducing retry intervals for faster test execution and using assertions for YAML marshaling and writing. (ee/maintained-apps/ingesters/winget/ingester_test.go)

Dependency and setup changes:

  • Added necessary imports for new functionality (io, net/http, net/url, time, and github.com/fleetdm/fleet/v4/pkg/retry) and updated struct initialization to support the new fields. (ee/maintained-apps/ingesters/winget/ingester.go, ee/maintained-apps/ingesters/winget/ingester_test.go) [1] [2] [3]

These changes make the Winget ingestion process more robust against transient infrastructure issues and provide better test coverage for error handling and retry logic.

Summary by CodeRabbit

  • Bug Fixes

    • Improved app ingestion resilience when GitHub returns transient rate-limit or server errors, so a single failure no longer stops the full import run.
    • Added clearer handling for missing installer data: only genuine “not found” responses now fall back to an older version, while other errors are surfaced properly.
  • Tests

    • Added coverage for version fallback behavior and transient error handling during ingestion.

Replace direct GitHub Contents API calls for installer/locale manifest files with raw.githubusercontent.com fetches (CDN-backed, not subject to gitmon scheduling limits). Add exponential-backoff retry logic for transient 429/5xx errors on both the raw HTTP fetches and the directory listing API calls. Add tests covering retry behavior, max-attempt exhaustion, and 404 handling.
fleet-release
fleet-release previously approved these changes Jul 6, 2026
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.09524% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.02%. Comparing base (bd88e72) to head (6b2a37f).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
ee/maintained-apps/ingesters/winget/ingester.go 38.09% 11 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #48775   +/-   ##
=======================================
  Coverage   68.02%   68.02%           
=======================================
  Files        3681     3682    +1     
  Lines      233961   234013   +52     
  Branches    12416    12416           
=======================================
+ Hits       159146   159196   +50     
- Misses      60498    60500    +2     
  Partials    14317    14317           
Flag Coverage Δ
backend 69.68% <38.09%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

raw.githubusercontent.com rate-limits unauthenticated requests per IP,
which shared GitHub Actions runner IPs exhaust constantly. Send the
existing PAT on raw fetches, and when raw is still throttled after
retries, fall back to the contents API (the two are rate-limited
independently). After 3 consecutive raw failures, skip raw for the
rest of the run instead of burning a backoff cycle per file.
fleet-release
fleet-release previously approved these changes Jul 6, 2026
Two layers:

- The winget ingester no longer trusts a 404 from raw.githubusercontent
  alone before falling through to an older version directory; the
  contents API must confirm the manifest is really missing. Raw is
  CDN-backed and a stale/spurious 404 would otherwise silently walk
  ingestion backwards to an older version.

- cmd/maintained-apps now compares each ingested version against the
  version already published in the app's output manifest and refuses to
  write a regression (all platforms/ingesters). The app is skipped with
  a loud error while the rest of the run proceeds, so an upstream data
  hiccup can never produce a downgrade PR.
…k machinery

Reverts the retry/raw-fallback approach and replaces it with the minimal
change on top of the original code:

GitHub intermittently throttles access to the very hot winget-pkgs repo
("429 gitmon refuses to schedule us" during file-server congestion).
When ingesting an app hits a rate limit, skip it and move on: its
published manifest stays at the current version and it gets picked up
again on the next scheduled run. Other errors still fail the run.

The version-directory walk now only falls through to an older version
dir on a genuine 404; before, a 429 there was treated as "not found"
and could silently ingest an older version.
fleet-release
fleet-release previously approved these changes Jul 6, 2026
The same winget-pkgs file-server congestion that produces 429s also
surfaces as 504s. Treat any 5xx like a rate limit: skip the app and
let the next scheduled run pick it up.
fleet-release
fleet-release previously approved these changes Jul 6, 2026
@allenhouchins allenhouchins marked this pull request as ready for review July 6, 2026 20:03
@allenhouchins allenhouchins requested a review from a team as a code owner July 6, 2026 20:03
Copilot AI review requested due to automatic review settings July 6, 2026 20:03

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the Winget ingester’s error handling to better distinguish “missing manifest” (404) from transient GitHub/API failures, and adds tests around version fallback behavior.

Changes:

  • Skip ingesting individual apps when a transient GitHub/API error is detected (instead of failing the entire run).
  • Only fall back to older Winget version directories when the installer manifest fetch is a true 404; otherwise fail the app.
  • Add a new test server + test cases to validate the version-walk behavior (404 fallthrough vs 429/504 failure).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
ee/maintained-apps/ingesters/winget/ingester.go Adds transient GitHub error classification, skips transient failures per-app, and tightens version fallback to 404-only.
ee/maintained-apps/ingesters/winget/ingester_test.go Adds fixtures/tests to ensure 404 falls through to older versions, while 429/504 fails and is recognized as transient.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return
}
str := string(bytes)
content := &github.RepositoryContent{Name: new("Foo"), Content: &str}
Comment on lines +588 to +592
case "/repos/microsoft/winget-pkgs/contents/manifests/f/Foo":
content := []github.RepositoryContent{
{Name: new("2.0"), Type: new("dir")},
{Name: new("1.0"), Type: new("dir")},
}
Comment on lines +95 to +99
// skip throttled apps; they'll be retried on the next scheduled run
if isTransientGitHubError(err) {
skippedApps++
logger.WarnContext(ctx, "skipping app: GitHub rate-limited its ingestion; it will be retried on the next scheduled run",
"name", input.Name, "err", err)
Comment on lines +108 to +110
if skippedApps > 0 {
logger.WarnContext(ctx, "some winget apps were skipped due to GitHub rate limiting", "count", skippedApps)
}
Comment on lines +115 to +126
// isTransientGitHubError reports whether err is GitHub load-shedding (rate limits, 429s, 5xx).
func isTransientGitHubError(err error) bool {
if _, ok := errors.AsType[*github.RateLimitError](err); ok {
return true
}
if _, ok := errors.AsType[*github.AbuseRateLimitError](err); ok {
return true
}
if ghErr, ok := errors.AsType[*github.ErrorResponse](err); ok && ghErr.Response != nil {
return ghErr.Response.StatusCode == http.StatusTooManyRequests || ghErr.Response.StatusCode >= 500
}
return false
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c17f8ea5-85a8-4eea-8518-03566c0b9178

📥 Commits

Reviewing files that changed from the base of the PR and between dfc8c27 and 6b2a37f.

📒 Files selected for processing (2)
  • ee/maintained-apps/ingesters/winget/ingester.go
  • ee/maintained-apps/ingesters/winget/ingester_test.go

Walkthrough

The winget ingester now classifies certain GitHub API errors (rate limit, abuse rate limit, HTTP 429, and HTTP 5xx) as transient. During bulk ingestion, apps that fail with transient errors are skipped and logged rather than aborting the entire run, with an aggregate warning at completion. Within single-app ingestion, installer manifest lookup failures now fall through to the next version directory only on HTTP 404; other errors are returned. A new test helper simulates a two-version package server, and a new test verifies fallback and error-classification behavior for 404, 429, and 504 responses.

Changes

Area Change
ingester.go Added isTransientGitHubError helper; IngestApps skips apps on transient errors and logs aggregate warning; ingestOne restricts version fallback to HTTP 404 only
ingester_test.go Added newTwoVersionServer helper and TestIngestOneVersionWalk test

Related PRs: None identified.

Suggested labels: maintained-apps, winget, bug

Suggested reviewers: None identified.


🐰 A winget wobble, rate-limit blues,
Now skips the noise, no need to lose,
Four-oh-four falls to versions past,
While five-oh-fives are handled fast,
Hop along, the ingest crew!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the main changes and testing, but it does not follow the repo template or include a related issue line. Add the required template items, especially a Related issue line and checklist-style entries for testing and any applicable sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: handling transient GitHub errors in the Winget ingester.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch allenhouchins-update-winget-ingester

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@allenhouchins allenhouchins merged commit a19a1c7 into main Jul 6, 2026
46 checks passed
@allenhouchins allenhouchins deleted the allenhouchins-update-winget-ingester branch July 6, 2026 20:54
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.

4 participants