fix(sync): authenticate doc fetches and back off on rate limits#27
Merged
Conversation
The docs build fetched every source file individually from raw.githubusercontent.com, unauthenticated (CI passed no token). On shared Actions runners that endpoint's per-IP limit trips fast, failing prebuild with `raw 429 for docs/concepts/mcp.zh.md`. - Read blobs via the authenticated git blob API (n.url) instead of raw.*, so GITHUB_TOKEN buys a 5000/hr budget with no per-IP throttle. - Add ghFetch() with backoff on 429 / 403-exhausted, honoring Retry-After and X-RateLimit-Reset. - Pass GITHUB_TOKEN to `pnpm build` in CI (the automatic token can read the public bitrouter repo; sync-changelog benefits too). Verified end to end against bitrouter@main: 111 files, no 429. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The docs build (
pnpm build→prebuild→sync-docs.mjs) fails intermittently with:Two compounding causes:
ci.ymlrunspnpm buildwith noGITHUB_TOKENin env, so every fetch is unauthenticated.raw.githubusercontent.com, whose rate limit is per-IP and trips fast on shared Actions runners. Unauthenticated × N raw requests → 429.This is pre-existing fragility; the recent get-started restructure merge (more files + a docs-changed dispatch) just made it trip reliably.
Fix
n.urlfrom the tree response) withAccept: application/vnd.github.raw, instead ofraw.githubusercontent.com. The API honorsGITHUB_TOKENfor a 5000/hr budget and isn't subject to raw's per-IP throttle.ghFetch()with backoff on429(and403with the rate-limit budget exhausted), honoringRetry-After/X-RateLimit-Reset. Applied to both the tree call and each blob read.GITHUB_TOKENtopnpm buildin CI. The automaticsecrets.GITHUB_TOKENcan read the publicbitrouterrepo;sync-changelog.mjs(which also fetches) benefits too.Verification
Ran the rewritten
sync-docs.mjsagainstbitrouter@mainwith a token:Exit 0, no 429s. (It also emits the usual non-blocking "N stale translation(s)" warning, unchanged behavior.)
🤖 Generated with Claude Code