Skip to content

Batch GitHub GraphQL queries to avoid API timeout on large changesets - #1925

Closed
TooTallNate wants to merge 4 commits into
changesets:mainfrom
TooTallNate:batch-github-graphql-queries
Closed

TooTallNate wants to merge 4 commits into
changesets:mainfrom
TooTallNate:batch-github-graphql-queries

Conversation

@TooTallNate

Copy link
Copy Markdown

Summary

When there are many changesets (e.g. 600+), the single GraphQL query built by DataLoader becomes too large for GitHub's API to validate, resulting in "Timeout on validation of query" errors.

Changes

Batched GraphQL requests (@changesets/get-github-info)

  • Extracts the fetch/parse/clean logic into a fetchBatch() helper
  • The DataLoader batch function now splits requests into chunks (default 100) and processes them sequentially
  • Adds progress logging when multiple batches are needed, e.g.:
    Fetching GitHub info for 654 items in 7 batches (batch size: 100)
    Fetching batch 1/7...
    

Fixed DataLoader cache deduplication (@changesets/get-github-info)

  • Adds a cacheKeyFn to the DataLoader so its result cache actually works
  • Previously, cache keys were compared by object reference (JavaScript Map semantics), so identical requests for the same commit/PR were never deduplicated
  • This was causing a 6-7x inflation in the number of GitHub API lookups (e.g. 654 changesets → 4261 requests)

Configurable batch size (@changesets/changelog-github)

  • Via .changeset/config.json:
    {
      "changelog": ["@changesets/changelog-github", { "repo": "org/repo", "batchSize": 50 }]
    }
  • Via environment variable (fallback): CHANGESET_GITHUB_BATCH_SIZE=50

When there are many changesets, the single GraphQL query built by
DataLoader can become too large for GitHub's API to validate, causing
"Timeout on validation of query" errors.

This change:
- Splits the DataLoader batch into sub-batches (default 100 items each)
  to keep individual queries within GitHub's limits
- Adds a cacheKeyFn to DataLoader so its deduplication cache actually
  works (previously broken due to object reference equality in Map keys)
- Adds progress logging when multiple batches are needed
- Makes batch size configurable via config.json ("batchSize" option)
  or CHANGESET_GITHUB_BATCH_SIZE env var
Copilot AI review requested due to automatic review settings April 6, 2026 22:24
@changeset-bot

changeset-bot Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e33a50

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@changesets/get-github-info Minor
@changesets/changelog-github Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

TooTallNate added a commit to vercel/workflow that referenced this pull request Apr 6, 2026
Bundles a patched version of @changesets/changelog-github that batches
GitHub GraphQL API requests to avoid "Timeout on validation of query"
errors when there are many changesets.

Upstream PR: changesets/changesets#1925

Copilot AI 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.

Pull request overview

This PR addresses GitHub GraphQL "Timeout on validation of query" failures for very large changesets by batching GraphQL lookups and improving request deduplication via DataLoader caching.

Changes:

  • Split a single large DataLoader GraphQL request into sequential batches (default size 100) and add progress logging for multi-batch runs.
  • Fix DataLoader cache deduplication by adding cacheKeyFn, reducing redundant GitHub lookups.
  • Add configurable batch size wiring from @changesets/changelog-github into @changesets/get-github-info.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
packages/get-github-info/src/index.ts Implements batching, cache keying, and exposes setBatchSize/clearCache.
packages/get-github-info/src/index.test.ts Updates tests to import clearCache and clears cache in the custom GraphQL URL test.
packages/changelog-github/src/index.ts Passes options.batchSize into setBatchSize for both release line generators.

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

Comment thread packages/get-github-info/src/index.ts Resolved
Comment thread packages/get-github-info/src/index.ts Resolved
Comment thread packages/get-github-info/src/index.ts Resolved
Comment thread packages/get-github-info/src/index.ts Resolved
Comment thread packages/changelog-github/src/index.ts Resolved
Comment thread packages/changelog-github/src/index.ts Resolved
@codecov

codecov Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.78261% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.40%. Comparing base (036fdd4) to head (4e33a50).

Files with missing lines Patch % Lines
packages/get-github-info/src/index.ts 90.47% 4 Missing ⚠️
packages/changelog-github/src/index.ts 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1925      +/-   ##
==========================================
+ Coverage   83.37%   83.40%   +0.03%     
==========================================
  Files          56       56              
  Lines        2466     2507      +41     
  Branches      742      759      +17     
==========================================
+ Hits         2056     2091      +35     
- Misses        404      410       +6     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 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.

- Add input validation to setBatchSize (throws RangeError on invalid)
- Use Number() coercion + null check for options.batchSize in changelog-github
- Switch progress logging from console.log to console.error (stderr)
- Move clearCache() to afterEach for proper test isolation
- Fix pre-existing typo in comment ('use' -> 'us')
- Add changeset file
The changelog-github test mock uses `typeof import(...)` so it must
include all exports from get-github-info, including the new
setBatchSize and clearCache functions.
- Test that setBatchSize rejects invalid values (0, negative, float, NaN, Infinity)
- Test that two distinct commits with batchSize=1 triggers two separate
  GraphQL requests, exercising the batching code path
- Fix GITHUB_GRAPHQL_URL restore in custom-URL test (was setting env var
  to string 'undefined' instead of deleting it)
TooTallNate added a commit to TooTallNate/sys-autopilot that referenced this pull request Jun 30, 2026
… generator (#26)

The Release job intermittently failed in 'Create Version PR' with:
  Failed to parse data from GitHub
  Invalid response body while trying to fetch
  https://api.github.com/graphql: Premature close

That GraphQL call is made by @changesets/changelog-github (via
@changesets/get-github-info), which does a single fetch with no retry, so
one dropped connection aborts the whole release. The packages are
effectively unmaintained (see changesets/changesets#1925).

Replace them with scripts/changelog-github.mjs, a self-contained ESM
changelog generator that produces byte-for-byte identical output but adds:
- retry with exponential backoff + jitter on transient failures
  (premature close, resets, timeouts, 5xx, 429)
- GraphQL request batching + correct cache-key dedup (the fix from
  changesets/changesets#1925, which was never merged upstream)
- loud failure after exhausting retries — no silent degraded changelog,
  so real outages surface instead of shipping an inconsistent CHANGELOG

Verified against the live GitHub API: 'changeset version' output is
identical to the upstream plugin. Adds tests/changelog-github.test.mjs
(stubbed fetch; format match, retry, fail-loud, no-retry-on-auth).
@bluwy

bluwy commented Jul 24, 2026

Copy link
Copy Markdown
Member

We had fixed this in #2121 by using dataloader's builtin batch size handling:

const GHDataLoader = new DataLoader(batchLoad, { maxBatchSize: 50 });

I believe this should address your issue if you use the latest beta versions.


However it looks like we didn't handle the cacheKeyFn fix as you had done here. Would you be able to update the PR (or open a new one if it's easier) that brings in the cacheKeyFn handling? Without tests is fine.

Sorry to have missed the PR.

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