Repository navigation
Studio: resolve upstream llama.cpp releases, assets and digests without the GitHub API - #5886
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a tokenless fast path for resolving the latest upstream llama.cpp release. By utilizing GitHub's HTTP redirect from /releases/latest to /releases/tag/<TAG>, the installer can determine the latest release tag and construct deterministic asset download URLs without consuming the rate-limited api.github.com REST API budget. This fast path is bypassed for Windows x64 hosts with NVIDIA or AMD GPUs to ensure proper dynamic asset enumeration. Comprehensive unit tests have been added to verify the redirect resolution, fallback mechanisms, and platform-specific behaviors. I have no feedback to provide.
d643764 to
d307631
Compare
…REST API is rate limited unsloth studio update discovers the llama.cpp prebuilt through the GitHub REST API, which is rate limited to 60 requests per hour per IP for anonymous callers. Without GH_TOKEN or GITHUB_TOKEN, users on shared, NAT, or cloud IPs hit HTTP 403 and the installer falls back to a slow source build. Keep the REST API as the primary path. When it is unavailable (for example a tokenless 403), fall back to resolving the latest upstream release from the unauthenticated github.com/<repo>/releases/latest redirect and build deterministic asset download URLs, so the prebuilt path still works with no token. The redirect is only a fallback and is always unauthenticated. Scope is narrow: the fallback only applies to the upstream repo plus latest plus the simple policy path, on platforms whose asset choice is a single deterministic file. Pinned tags, the Linux CUDA manifest path, the token path, and Windows x64 NVIDIA or AMD asset selection are unchanged. Add tests covering redirect parsing, REST first resolution, the redirect fallback on a 403 and on a missing tag, the Windows CUDA opt out, and end to end macOS and Linux latest resolution when the REST API 403s.
188a5e7 to
7e6e2ff
Compare
…5886) Harden the tokenless llama.cpp release-redirect fallback: - Guard the redirect-resolved tag with is_release_tag_like so an unexpected redirect target fails closed to the REST/source path instead of building a 404-bound download URL. - When the REST listing and the redirect both fail, raise a chained error that names both causes instead of only the REST 403. - Drop a no-op except branch in the specific-tag path and clarify the synthetic-release comment. Add negative tests: both paths failing, a pinned tag never using the redirect, a malformed redirect target being rejected, and a real REST asset URL taking precedence over the synthetic one.
Implement the hardening the added tests cover: - Guard the redirect-resolved tag with is_release_tag_like so an unexpected redirect target fails closed to the REST/source path instead of building a 404-bound download URL. - When the REST listing and the redirect both fail, raise a chained error that names both causes instead of only the REST 403. - Drop a no-op except branch in the specific-tag path and clarify the synthetic-release comment. - Unpack the (requested_tag, plans) return in the asset-precedence test.
…okenless-llama-prebuilt # Conflicts: # tests/studio/install/test_macos_version_compat.py
|
Main now resolves the latest tag through the release redirect in _download_host_latest_release_tag (studio/install_llama_prebuilt.py:1968) and the download-host fast path. Could you rebase and route the upstream ggml-org case through that helper rather than a second resolver plus its own URL builder? |
# Conflicts: # studio/install_llama_prebuilt.py # tests/studio/install/test_macos_version_compat.py # tests/studio/install/test_selection_logic.py
…ut the GitHub API The redirect-only fallback this branch opened with no longer resolves anything installable, and could not install it if it did. github.com/ggml-org/llama.cpp/releases/latest now redirects to v0.4.1, a pointer release whose single asset is nightly-tag.txt, so the bNNNN guard rejected it and the fallback never fired. Main has also since required a published per-asset sha256 for upstream prebuilts (#11402), which a release payload synthesized from a tag alone cannot supply, so even a bNNNN redirect would have been refused. Resolve the whole release from the web host instead of guessing filenames: - web_release_tags reads github.com/<repo>/releases.atom, which orders releases, so the newest build tag and the older-release walk-back both survive the API being unavailable. - web_release_payload reads github.com/<repo>/releases/expanded_assets/<tag> and returns an ordinary release payload: real asset names, tag-pinned download URLs and the sha256 GitHub published for each one. Digests are read off the copy-to-clipboard control, which names its asset in the same element, so no asset can be handed another asset's hash. Because the payload has the shape the REST one does, direct_upstream_release_plan and _apply_release_digests are untouched and digest enforcement stays authoritative: an asset the release states no sha256 for is still dropped, and a release with none is still refused rather than installed. Scope: upstream only, REST first, source build still the final fallback, and UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE opts out. The fork keeps its own API-free download-host path. Real asset names also retire the Windows CUDA and AMD carve-out the filename-guessing version needed, and a pinned tag now resolves through the same path, which is what the macOS version floor pin b9415 needs. Verified live with api.github.com blocked: macOS arm64, Linux x64 and Windows x64 NVIDIA each resolve b11071 and a digest that matches the REST payload exactly.
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…le HTTP failure HTTPError subclasses URLError, so the HTTPError clause shadowed the fallback added alongside it: a pinned tag whose REST lookup exhausted its retries on a 500, 502, 503 or 504 re-raised instead of reading the release page, and the install dropped to a source build with the page sitting there. The 404 case keeps scanning, since a tag that does not exist has no page to read either, and the fork still re-raises.
_newest_release_tag_from_releases dropped every prerelease unconditionally while the planner now installs an upstream bNNNN build, so the two answered differently from the same payload, which its own docstring says must not happen. Reproduced live against the API: the freshness check named v0.4.1 newest while the planner installed b11071, so the marker for the freshly installed build read as stale and every later update run would have repeated the whole download and install. It now takes the repo and applies release_is_selectable, the rule the planner uses. After the fix both answer b11071, and the fork is unchanged: it still drops prereleases and still resolves b11030-mix-5ff778e.
…the whisper caller Two things. latest_upstream_release_tag returned whatever /releases/latest named, and upstream points that at v0.4.1, a pointer release packaging no prebuilt. The source build would then compile a different version from the one the prebuilt path installs, which is the only reason that tag is resolved here. A non-build REST tag now consults the release feed, as a missing one already did, and the REST answer is still kept when the feed cannot name a build, since a released version beats no source ref. Live, this moves the source ref from v0.4.1 to b11073. install_whisper_prebuilt called _newest_release_tag_from_releases positionally and the previous commit gave it a repo parameter, which broke three whisper tests. The repo was already in scope; whisper is never ggml-org/llama.cpp, so it keeps the plain drafts-and-prereleases-dropped rule it has always had.
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…our the opt-out everywhere Four findings from a parallel review pass focused on install regressions, each reproduced before it was fixed. An upstream release that is not a bNNNN build is no longer selectable. It was only the prerelease flag that excluded them, and the versioned pointer releases do not carry one, so a v0.4.2 published after the newest build became the freshness check's answer while the planner walked past it for want of an asset: the marker read stale forever and every update run reinstalled the same build. For upstream the rule is now simply whether the tag names a build, which closes that and the prerelease case together. Every other repo keeps the plain rule. A stalled or reset read no longer strands the install. TimeoutError and ConnectionResetError are not URLError subclasses, so they escaped the four handlers that route the web fallback and the recovery never ran. They now use RELEASE_LISTING_TRANSPORT_ERRORS, which the module already applies to the same listing call. UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE now means the same thing on every path: latest_upstream_release_tag consulted the release feed regardless, and keeps the REST answer instead when the opt-out is set. A release page that cannot be read no longer discards the release. The assets and their digests have already loaded by then, and an upstream build tag answers the prerelease question by itself, so only a tag that cannot fails closed. 192 fork selector cells unchanged, 240 enumerated predicate cells with no violations, full tests/studio/install/ at 6950 passed and 0 failed.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ut the GitHub API (unslothai#5886) * Studio: fall back to a tokenless release redirect when the llama.cpp REST API is rate limited unsloth studio update discovers the llama.cpp prebuilt through the GitHub REST API, which is rate limited to 60 requests per hour per IP for anonymous callers. Without GH_TOKEN or GITHUB_TOKEN, users on shared, NAT, or cloud IPs hit HTTP 403 and the installer falls back to a slow source build. Keep the REST API as the primary path. When it is unavailable (for example a tokenless 403), fall back to resolving the latest upstream release from the unauthenticated github.com/<repo>/releases/latest redirect and build deterministic asset download URLs, so the prebuilt path still works with no token. The redirect is only a fallback and is always unauthenticated. Scope is narrow: the fallback only applies to the upstream repo plus latest plus the simple policy path, on platforms whose asset choice is a single deterministic file. Pinned tags, the Linux CUDA manifest path, the token path, and Windows x64 NVIDIA or AMD asset selection are unchanged. Add tests covering redirect parsing, REST first resolution, the redirect fallback on a 403 and on a missing tag, the Windows CUDA opt out, and end to end macOS and Linux latest resolution when the REST API 403s. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: fail closed on bad redirect tag and report both failures (PR unslothai#5886) Harden the tokenless llama.cpp release-redirect fallback: - Guard the redirect-resolved tag with is_release_tag_like so an unexpected redirect target fails closed to the REST/source path instead of building a 404-bound download URL. - When the REST listing and the redirect both fail, raise a chained error that names both causes instead of only the REST 403. - Drop a no-op except branch in the specific-tag path and clarify the synthetic-release comment. Add negative tests: both paths failing, a pinned tag never using the redirect, a malformed redirect target being rejected, and a real REST asset URL taking precedence over the synthetic one. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: harden tokenless release redirect fallback (PR unslothai#5886) Implement the hardening the added tests cover: - Guard the redirect-resolved tag with is_release_tag_like so an unexpected redirect target fails closed to the REST/source path instead of building a 404-bound download URL. - When the REST listing and the redirect both fail, raise a chained error that names both causes instead of only the REST 403. - Drop a no-op except branch in the specific-tag path and clarify the synthetic-release comment. - Unpack the (requested_tag, plans) return in the asset-precedence test. * Studio: tidy redirect handler signature and align test import (PR unslothai#5886) * Studio: resolve upstream llama.cpp releases, assets and digests without the GitHub API The redirect-only fallback this branch opened with no longer resolves anything installable, and could not install it if it did. github.com/ggml-org/llama.cpp/releases/latest now redirects to v0.4.1, a pointer release whose single asset is nightly-tag.txt, so the bNNNN guard rejected it and the fallback never fired. Main has also since required a published per-asset sha256 for upstream prebuilts (unslothai#11402), which a release payload synthesized from a tag alone cannot supply, so even a bNNNN redirect would have been refused. Resolve the whole release from the web host instead of guessing filenames: - web_release_tags reads github.com/<repo>/releases.atom, which orders releases, so the newest build tag and the older-release walk-back both survive the API being unavailable. - web_release_payload reads github.com/<repo>/releases/expanded_assets/<tag> and returns an ordinary release payload: real asset names, tag-pinned download URLs and the sha256 GitHub published for each one. Digests are read off the copy-to-clipboard control, which names its asset in the same element, so no asset can be handed another asset's hash. Because the payload has the shape the REST one does, direct_upstream_release_plan and _apply_release_digests are untouched and digest enforcement stays authoritative: an asset the release states no sha256 for is still dropped, and a release with none is still refused rather than installed. Scope: upstream only, REST first, source build still the final fallback, and UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE opts out. The fork keeps its own API-free download-host path. Real asset names also retire the Windows CUDA and AMD carve-out the filename-guessing version needed, and a pinned tag now resolves through the same path, which is what the macOS version floor pin b9415 needs. Verified live with api.github.com blocked: macOS arm64, Linux x64 and Windows x64 NVIDIA each resolve b11071 and a digest that matches the REST payload exactly. * Studio: route pinned upstream releases through the web path, and read prerelease status rather than assume it Two review findings. A pinned published_release_tag returned from iter_release_payloads_by_time before reaching the fallback, so an explicitly pinned upstream release still dropped to a source build under a rate limit even though its release page names it exactly. It now takes the same web path, and the fork still re-raises. The synthesized payload hardcoded prerelease False, which the REST listing filters on, so the two paths could select differently. web_release_prerelease reads the status from the release page label instead, and release_is_selectable is now the one rule both paths apply. That rule has one deliberate exception, which turns out to fix a live defect of its own: ggml-org marks EVERY bNNNN build release prerelease, so the plain filter left the upstream path selecting the newest release that is not one. Measured against the live API today, main selects b10549 while the newest build is b11071, an install 522 builds behind, because the releases above it (v0.4.1 and older) publish no prebuilt at all. An upstream bNNNN build is therefore selectable despite the flag; a non-build prerelease is not, and the fork and every other repo keep the plain rule unchanged. * Studio: let a pinned upstream tag reach the release page on a retryable HTTP failure HTTPError subclasses URLError, so the HTTPError clause shadowed the fallback added alongside it: a pinned tag whose REST lookup exhausted its retries on a 500, 502, 503 or 504 re-raised instead of reading the release page, and the install dropped to a source build with the page sitting there. The 404 case keeps scanning, since a tag that does not exist has no page to read either, and the fork still re-raises. * Studio: apply the same selectability rule to the update freshness check _newest_release_tag_from_releases dropped every prerelease unconditionally while the planner now installs an upstream bNNNN build, so the two answered differently from the same payload, which its own docstring says must not happen. Reproduced live against the API: the freshness check named v0.4.1 newest while the planner installed b11071, so the marker for the freshly installed build read as stale and every later update run would have repeated the whole download and install. It now takes the repo and applies release_is_selectable, the rule the planner uses. After the fix both answer b11071, and the fork is unchanged: it still drops prereleases and still resolves b11030-mix-5ff778e. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: take the REST latest tag only when it names a build, and fix the whisper caller Two things. latest_upstream_release_tag returned whatever /releases/latest named, and upstream points that at v0.4.1, a pointer release packaging no prebuilt. The source build would then compile a different version from the one the prebuilt path installs, which is the only reason that tag is resolved here. A non-build REST tag now consults the release feed, as a missing one already did, and the REST answer is still kept when the feed cannot name a build, since a released version beats no source ref. Live, this moves the source ref from v0.4.1 to b11073. install_whisper_prebuilt called _newest_release_tag_from_releases positionally and the previous commit gave it a repo parameter, which broke three whisper tests. The repo was already in scope; whisper is never ggml-org/llama.cpp, so it keeps the plain drafts-and-prereleases-dropped rule it has always had. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Reduce the comments added by this PR * Studio: exclude upstream pointer releases, recover stalled reads, honour the opt-out everywhere Four findings from a parallel review pass focused on install regressions, each reproduced before it was fixed. An upstream release that is not a bNNNN build is no longer selectable. It was only the prerelease flag that excluded them, and the versioned pointer releases do not carry one, so a v0.4.2 published after the newest build became the freshness check's answer while the planner walked past it for want of an asset: the marker read stale forever and every update run reinstalled the same build. For upstream the rule is now simply whether the tag names a build, which closes that and the prerelease case together. Every other repo keeps the plain rule. A stalled or reset read no longer strands the install. TimeoutError and ConnectionResetError are not URLError subclasses, so they escaped the four handlers that route the web fallback and the recovery never ran. They now use RELEASE_LISTING_TRANSPORT_ERRORS, which the module already applies to the same listing call. UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE now means the same thing on every path: latest_upstream_release_tag consulted the release feed regardless, and keeps the REST answer instead when the opt-out is set. A release page that cannot be read no longer discards the release. The assets and their digests have already loaded by then, and an upstream build tag answers the prerelease question by itself, so only a tag that cannot fails closed. 192 fork selector cells unchanged, 240 enumerated predicate cells with no violations, full tests/studio/install/ at 6950 passed and 0 failed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Problem
unsloth studio updateand first install discover the llama.cpp prebuilt release through the GitHub REST API (api.github.com/repos/ggml-org/llama.cpp/releases). That surface allows 60 requests per hour per IP for anonymous callers, so a user withoutGH_TOKENorGITHUB_TOKENbehind a shared, NAT or cloud IP gets an immediate HTTP 403 and the installer drops to a slow source build:Reproduced on current
mainwith the API blocked: macOS arm64, Linux x64 and Windows x64 NVIDIA all refuse and fall back to a source build.Why this branch was rewritten
This PR originally resolved only the latest tag, from the
github.com/<repo>/releases/latest302, and then built asset URLs by guessing filenames. Two things have made that unworkable:github.com/ggml-org/llama.cpp/releases/latestnow redirects tov0.4.1, a pointer release whose single asset isnightly-tag.txt. The branch's ownbNNNNguard rejected it, so the fallback never fired. It failed safe, but it did nothing.bNNNNredirect would have been refused with "publishes no asset digest for any compatible prebuilt".So the branch now resolves the whole release from the web host rather than guessing at it, and routes through the helpers
maingrew in the meantime.Fix
REST stays the primary path. When it is unavailable, resolve upstream releases without
api.github.com:web_release_tagsreadsgithub.com/<repo>/releases.atom. It is the only tokenless surface that ORDERS releases, which is what makes both "the newest build" and the older-release walk-back survive the API being down.upstream_web_release_tagsfilters tobNNNN, so thev0.4.1pointer release is never selected.web_release_payloadreadsgithub.com/<repo>/releases/expanded_assets/<tag>and returns an ordinary release payload: real asset names, tag-pinned download URLs and the sha256 GitHub published for each asset. Digests are read off the copy-to-clipboard control, which names its asset in the same element, so no asset can be handed another asset's hash.Because the payload has the same shape as the REST one,
direct_upstream_release_planand_apply_release_digestsare untouched and digest enforcement stays authoritative: an asset the release states no sha256 for is still dropped, and a release with none is still refused rather than installed unverified.Real asset names also retire two limitations the filename-guessing version needed:
bNNNNtag resolves through the same page, which is what the macOS version floor pinb9415needs.Scope: upstream only (the fork keeps its own API-free download-host path), REST first, the source build still the final fallback,
UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVEopts out, and every web request is unauthenticated with no token attached.Validation
Live, with
api.github.comblocked for every call and nothing else stubbed:main)llama-b11071-bin-macos-arm64.tar.gz, sha25693c1db92...llama-b11071-bin-ubuntu-x64.tar.gz, sha256035c130b...llama-b11071-bin-win-cuda-12.4-x64.zip, sha2561479bfcc...All three digests were compared against the REST payload for
b11071and match exactly, as do the asset names and URLs. Forb11070, the 33 assets and 33 digests parsed from the release page are identical to the 33 the REST API reports.tests/studio/install/test_tokenless_release_resolution.py: 27 pass on this branch, 26 of them fail onmain. They cover the feed parse and the pointer-release skip, per-asset digest binding, an asset with no digest being dropped, a conflicting duplicate digest being refused, a link belonging to another release being ignored, a digest with no published asset not being invented, the response size cap, the absence of any authorization header, REST-first on both entry points, the lazy newest-first walk, an unreadable release being skipped rather than fatal, a pinned tag resolving through its release page, the fork and the escape hatch both declining the path, both paths failing naming both causes, and end-to-end macOS, Linux and older-release-fallback plans asserting the boundexpected_sha256.Full
tests/studio/install/: 6915 passed, 32 skipped on this branch, matchingmain.