Skip to content

Studio: stop re-fetching every llama.cpp release from the GitHub API - #10461

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
NilayYadav:fix-llama-prebuilt-github-rate-limit
Sep 8, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
NilayYadav:fix-llama-prebuilt-github-rate-limit

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Fixes #10449.

When the installer looks for a prebuilt llama.cpp release, it already gets the full list of releases and their files from GitHub in one request. It then went back to GitHub once more for every single release to ask for the same files again. That extra request per release was enough to use up the free GitHub API limit on its own, and once the limit was hit, each remaining release was still tried four more times with waits in between. For the report in the issue that meant over a hundred requests and a few minutes of waiting, and the final error said no compatible prebuilt was found, which was not true.

This change reads the file list from the release listing it already has, so the walk through releases now makes one request instead of one per release. A GitHub 403 is only retried when GitHub says the limit resets soon enough to wait for, otherwise it fails right away. Because of that, a rate limit now shows up as a rate limit with the GH_TOKEN hint instead of being reported as a missing prebuilt, and the update check no longer caches a false "no prebuilt" answer for a day.

Tested on a Mac against the real GitHub API without a token: three releases resolved with two requests total, both for the listing pages. The install and backend test suites pass with four new tests covering this.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T05:35:39.063736Z 9c07a94 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: bf6e7acc1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: bf6e7acc1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: a5217be517

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions reproduction

Pinned review: 1d57d7ab3f05e69ef4e25f1285f59bb880608073. The two studio/ files are byte-identical from the first commit e793d4ebd; everything after it only touches tests. One finding, fixed in a5217be51: the new 403 test built its X-RateLimit-Reset header with time.time() + 30 inside parametrize, which pytest evaluates once at collection, so in the 11-minute upstream suite the reset had already passed when the test ran ("Repo tests (CPU)" was red on bf6e7acc1 while main at 502c4d237 was green). The clock is now pinned in the test.

I staged fresh upstream main (502c4d237) on my fork twice with the same probe and workflow; the two branches differ only in this PR's delta. The probe loads studio/install_llama_prebuilt.py, disables the download-host fast path (the GitHub API walk that macOS always takes and every other host falls back to), wraps the URL opener to count requests per host, and drives iter_resolved_published_releases("latest", "unslothai/llama.cpp"). Both runs execute on ubuntu-latest and macos-15; the counts are identical on both runners.

Scene Before, main (expected-failing run) After, PR (passing run)
Real API, first 5 releases resolved (authenticated) 2 listing pages + 5 /releases/tags requests 2 listing pages + 0 /releases/tags requests
Listing succeeds, every /releases/tags answers 403 with the reset 50 min away, 30 releases (the shape in #10449) 120 API requests, 167.5 s, 0 resolved, then PrebuiltFallback: no usable published llama.cpp releases were available 1 API request, 0.0 s, all 30 releases resolved from the listing
The listing itself answers 403 with the reset 50 min away 4 requests, 5.6 s 1 request, 0.0 s, GitHub API returned 403 ...; set GH_TOKEN or GITHUB_TOKEN
The listing answers 403 once with Retry-After: 2 retried once after 2.1 s, 3 releases resolved same: 2 requests, 2.0 s, 3 releases resolved

The last row is the guard that a reachable reset is still waited for. The PR's three test files also run in both jobs: 392 passed on the main tree, 400 on the PR tree. Locally on a Mac against the real API without a token the numbers match the table.

The red parity (windows-latest) check is unrelated: the same two test_windows_python_venv_hardening.py:859 non-ASCII assertions fail on main since b66d2a4c8 earlier today.

Conclusion: the per-release API traffic and the false "no prebuilt" verdict reproduce on main and are gone on this PR; I found no new blocker.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 1d57d7ab3f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 1d57d7ab3f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the walk still calls github_release per release in studio/install_llama_prebuilt.py, so a token-less install burns the anonymous API budget and then reports no prebuilt found; reading the assets from the listing looks right and I will get this reviewed.

Reviewing this change against main with a fake transport that counts real
api.github.com requests: the walk drops from 1 + N to 1 request, the parsed
checksums and asset maps come out byte identical, and the unslothai#10449 shape (listing
fine, every /releases/tags 403) goes from 13 requests plus a false "no usable
published llama.cpp releases" to 1 request and all releases resolved.

The one behaviour change that showed up: reading assets from the listing judges
a release on that snapshot, so a release still being published (sha256 asset not
uploaded yet) is now skipped instead of picked up by a fresh per-tag lookup. The
walk-back handles it correctly, so this adds a test pinning that it degrades to
the next good release rather than failing the resolution.

Also two traps next to the code this touches:

- _RATE_LIMIT_WAIT_CAP_SECONDS in install_llama_prebuilt.py was a literal copy,
  but _http_error_retry_delay reads prebuilt_core's global, so editing the copy
  did nothing. Now that the cap decides whether a 403 is retried at all and not
  just how long the backoff waits, make it an alias so it cannot drift.
- test_fast_path_rejected_checksum_falls_back_to_api stubbed
  _download_host_resolved_release with a one-argument function while it is
  called as (repo, tag). The TypeError hit the same broad except that catches
  PrebuiltFallback, so the test passed without the branch it names ever running.
@danielhanchen

Copy link
Copy Markdown
Member

Reviewed with a base-vs-head differential

I reviewed this by running origin/main and this branch side by side in two worktrees against a fake transport patched at install_llama_prebuilt._URL_OPENER.open, which is the seam prebuilt_core.download_bytes actually uses, so the numbers below are real request counts rather than counts of stubbed helpers. Clock frozen, jitter zeroed, sleeps recorded instead of slept, UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE=1 to force the API path, GH_TOKEN and GITHUB_TOKEN cleared. Three releases in the listing.

Scenario main this PR
Healthy walk 4 API requests (1 listing + 3 /releases/tags), 3 resolved 1 API request, 0 /releases/tags, same 3 resolved
Listing fine, every /releases/tags 403, reset 50 min out (the #10449 shape) 13 API requests, sleeps [0.75, 1.5, 3.0] x 3, 0 resolved, PrebuiltFallback: no usable published llama.cpp releases were available 1 API request, no sleeps, all 3 resolved
Same but the 403 carries no rate-limit headers at all 13 requests, same false verdict 1 request, all 3 resolved
Listing itself 403, reset 50 min out 4 requests, 3 backoff sleeps, GitHub API returned 403 ...; set GH_TOKEN or GITHUB_TOKEN 1 request, no sleeps, same message preserved
Listing 403 once with Retry-After: 2 retried after 2.0 s, resolves identical: retried after 2.0 s, resolves
Listing 403 once with reset at T+30 retried after 31.0 s, resolves identical
Pinned tag 2 API requests 1 API request
Download-host fast path 0 API requests 0 API requests

The false verdict in row 2 is exactly what #10449 reported, and it reproduces on main and is gone here.

Validation is not weakened to buy that: dumping the fully parsed ApprovedReleaseChecksums plus bundle.assets and manifest_sha256 for every release, main and this branch are byte identical.

I also checked the assumption the change rests on, that the listing's inline assets array is complete, against the real repo rather than the docs. Across the first 100 releases of unslothai/llama.cpp, every one of the 99 non-draft releases carries all 42 assets inline, matching both /releases/{id}/assets and /releases/tags/{tag}, and all 99 include llama-prebuilt-sha256.json. The one zero-asset entry is a draft, which iter_published_release_bundles already skips and which unauthenticated callers never see anyway. No inline truncation shows up on electron/electron either at 76 assets per release, so the fork has plenty of headroom.

403 classification, every shape

Both is_retryable_url_error and the real download_bytes loop, attempts counted:

403 shape main this PR
Retry-After 5 / 60, reset T+30 / T+59 / T+60, lowercase headers retry, 4 attempts unchanged
no headers, Retry-After 61, reset T+61 / T+3600, reset now or past, malformed reset, HTTP-date Retry-After retry, 4 attempts 1 attempt, no sleep
non-API host 403 (CDN, HF) 1 attempt unchanged
429, 404, 5xx, URLError, timeout unchanged unchanged

Every narrowed case falls through to the source build, which is faster than waiting out a reset that is over the 60 s cap, so I am satisfied this is the right trade. Two notes rather than objections: a headerless 403 is GitHub's secondary-limit shape, and retrying it four times over 5.25 s was never going to clear it; and a 429 with a far reset still burns four attempts because 429 stays in RETRYABLE_HTTP_STATUS unconditionally, so 403 and 429 are now handled asymmetrically for the same underlying limit. Worth aligning separately, not here.

Compatibility

Nothing to migrate for existing installs: no on-disk metadata format changes, and the installed llama.cpp is untouched. Version skew is not reachable either. load_approved_release_checksums and its only caller both live in install_llama_prebuilt.py, the is_retryable_url_error change is internal to prebuilt_core.py, and install_llama_prebuilt.py puts its own directory on sys.path before import prebuilt_core, so the two files are always siblings from the same install. install_whisper_prebuilt.py has its own github_release and is unaffected.

The resolution path is upstream of all platform and accelerator selection, and running the two scenarios above across [Linux, WSL, macOS, Windows] x [NVIDIA, AMD, CPU-only] gives identical counts in all 12 combinations: 4/3/3 on main, 1/0/3 here, everywhere. No frontend or UI surface is touched, so there is nothing browser-specific to check.

tests/studio/install/ on both revisions: 3413 passed on main, 3421 here, same 3 pre-existing failures in test_managed_node_runtime.py on both, unrelated to this change.

What I pushed

One behaviour change did show up, and it is the only one: reading assets from the listing judges a release on that snapshot, so a release still being published, sha256 asset not uploaded yet, is skipped here where main would pick it up via the fresh per-tag lookup. The walk-back handles it correctly, resolving the next good release with no error, so I added a test pinning that instead of changing the behaviour.

I also fixed two traps sitting next to this code:

  • _RATE_LIMIT_WAIT_CAP_SECONDS in install_llama_prebuilt.py was a literal 60.0 copy, but _http_error_retry_delay reads prebuilt_core's global, so editing the copy did nothing. That was harmless when the cap only sized the backoff; now that it decides whether a 403 is retried at all, it is a trap. Made it an alias.
  • test_fast_path_rejected_checksum_falls_back_to_api stubbed _download_host_resolved_release with a one-argument function while it is called as (repo, tag). The TypeError hit the same broad except that catches PrebuiltFallback, so the test passed without the branch it names ever running. Pre-existing on main, but it guards the fallback this walk depends on.

Approach and change look right to me.

Opening comment-reduction pass: 12 added comment lines down to 4, each
surviving line naming the mistake the next reader would otherwise make.
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 8, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 8, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 8, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 8, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 8, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 9c07a94a49

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Cross-platform validation, converged

Codex has approved the head commit. Closing the loop with the cross-platform run, since this touches the installer on every OS.

Ran the PR's install test files per OS plus a live Studio Playwright leg on an owned staging repo, so the org queue was spared:

Leg Result
ubuntu-latest pass
macos-15 pass
windows-latest pass
studio-live Playwright (chromium, firefox, webkit) pass

One thing worth recording for whoever reads this later. The first windows-latest leg came back with 21 failures, and none of them were this PR: 18 were FileNotFoundError: [WinError 2] from tests that shell out to bash (TestSetupShLogic, TestMacOSMetalBuildLogic, TestLatestTagResolution), and the rest were the POSIX exec bit, tar symlink semantics, and LD_LIBRARY_PATH. That is expected: cross-platform-parity-ci.yml says in its own comment that studio-backend-ci runs tests/studio/install on ubuntu only, and the Windows parity job runs a curated allowlist instead. The one line this PR changes in test_pr4562_bugfixes.py is in TestResolveRequestedLlamaTag, which is not among them, and both tests it adds to test_prebuilt_core.py passed on Windows. The gap was in my per-OS harness, which ran the whole files; fixed there, and the re-run is the green windows-latest above.

The other red job on the staging run, Clean machine install / virgin win container / overlay=true, was also unrelated: the container could not seed its root CA store after three attempts, winget was unavailable, and the direct VC++ runtime download arrived unsigned, so torch could not load c10.dll. The overlay=false sibling passed and that workflow is green on the staging repo's main.

Nothing further from me on this one.

@danielhanchen
danielhanchen merged commit 6ef5955 into unslothai:main Sep 8, 2026
56 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] unsloth studio update hits the github api too hard

2 participants