Skip to content

fix(install): resolve version via redirect to avoid GitHub API rate limits#1414

Merged
pszymkowiak merged 1 commit intortk-ai:developfrom
xdm67x:fix-install-api-rate-limit-fallback
Apr 23, 2026
Merged

fix(install): resolve version via redirect to avoid GitHub API rate limits#1414
pszymkowiak merged 1 commit intortk-ai:developfrom
xdm67x:fix-install-api-rate-limit-fallback

Conversation

@xdm67x
Copy link
Copy Markdown
Contributor

@xdm67x xdm67x commented Apr 20, 2026

Summary

  • install.sh fails with Failed to get latest version when the GitHub REST API returns 403 (anonymous rate limit of 60 req/hour, easily hit from shared NATs, CI, or corporate networks).
  • Switch the primary lookup to the https://github.com/<repo>/releases/latest 302 redirect, whose Location header contains the tag — no API quota consumed.
  • Keep the REST API call as a fallback for defense in depth.
  • Add an RTK_VERSION env var as an escape hatch to pin a specific version (the error message now points users to it).

Problem

# Before
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
  | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

When unauthenticated requests exceed 60/hour (GitHub's documented rate limit for anonymous API access), the API returns HTTP 403. With curl -f, that produces an empty pipeline result, and the installer bails with Failed to get latest version. Users sharing an outbound IP (CI, NAT, coworking spaces) can trivially exhaust the quota for everyone behind that IP.

Fix

Primary: parse the 302 redirect from github.com/<repo>/releases/latest. This doesn't hit the API at all and has no documented rate limit.

VERSION=$(curl -sI "https://github.com/${REPO}/releases/latest" \
    | grep -i '^location:' \
    | sed -E 's|.*/tag/([^[:space:]]+).*|\1|' \
    | tr -d '\r')

Fallback: if the redirect parsing yields nothing (unexpected GitHub change, network oddity), fall back to the original API call with a warning.

Escape hatch: RTK_VERSION=v0.37.1 curl -fsSL ... | sh lets users pin a version and skip both lookups entirely.

Verification

  • POSIX syntax check: sh -n install.sh
  • Redirect lookup tested against rtk-ai/rtk:
    $ curl -sI https://github.com/rtk-ai/rtk/releases/latest | grep -i '^location:'
    location: https://github.com/rtk-ai/rtk/releases/tag/v0.37.1
    
  • Resolved version: v0.37.1
  • Fallback path preserved (still parses the API JSON the same way).
  • RTK_VERSION override path tested by setting the env var and short-circuiting get_latest_version.

Test plan

  • curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/master/install.sh | sh installs successfully on macOS
  • Same on Linux (bash, /bin/sh = dash)
  • RTK_VERSION=v0.37.0 curl -fsSL ... | sh installs v0.37.0 specifically

Related

@xdm67x xdm67x changed the title fix(install): resolve version via redirect to avoid GitHub API rate limits fix: resolve version via redirect to avoid GitHub API rate limits Apr 20, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 20, 2026

CLA assistant check
All committers have signed the CLA.

@xdm67x xdm67x changed the title fix: resolve version via redirect to avoid GitHub API rate limits fix(install): resolve version via redirect to avoid GitHub API rate limits Apr 20, 2026
@xdm67x

This comment was marked as outdated.

@xdm67x xdm67x changed the base branch from master to develop April 20, 2026 12:24
The installer failed with "Failed to get latest version" when the GitHub
REST API returned 403 due to the anonymous rate limit (60 req/hour, shared
across NAT/CI). Switch the primary lookup to the `/releases/latest` 302
redirect, which doesn't count against the API quota. Keep the API call as
a fallback, and add a RTK_VERSION escape hatch for pinning.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@xdm67x xdm67x force-pushed the fix-install-api-rate-limit-fallback branch from 2ac884c to f67ae3b Compare April 20, 2026 12:31
Copy link
Copy Markdown
Collaborator

@pszymkowiak pszymkowiak left a comment

Choose a reason for hiding this comment

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

Tested the redirect approach live — curl -sI https://github.com/rtk-ai/rtk/releases/latest | grep location: returns the tag cleanly, full parsing pipeline extracts v0.37.2 correctly with no trailing chars.

The fallback to REST API and the RTK_VERSION escape hatch are both well-placed. Fixes a real blocker for CI environments and shared NATs hitting the 60 req/hr anonymous limit.

LGTM

@pszymkowiak pszymkowiak merged commit 5e1a641 into rtk-ai:develop Apr 23, 2026
1 check passed
@aeppling aeppling mentioned this pull request Apr 25, 2026
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