Skip to content

Studio: read the local model cache locally, and keep host paths off the API - #11026

Merged
danielhanchen merged 103 commits into
mainfrom
pr/studio-local-discovery-offline
Sep 21, 2026
Merged

danielhanchen merged 103 commits into
mainfrom
pr/studio-local-discovery-offline

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Three connected things about the local model cache in Studio.

  1. Local cache discovery no longer depends on reaching huggingface.co. The cache-read gate added
    in Studio: verify Hub credentials before cache-backed reads #10264 put a live /auth-check round trip in front of every read of the host's own Hugging
    Face disk cache and collapsed "the Hub could not be asked" into "the Hub said no", so an operator
    offline with a fully downloaded model, an air-gapped install, a Hub outage, a rate limit, or a
    self-hosted HF_ENDPOINT mirror that never implemented that undocumented route was told the model
    was unavailable.
  2. No host filesystem path reaches a caller that is not a browser session, on the routes listed
    under "Covered". GET /api/hub/cached-models answered an sk-unsloth API key with the absolute
    cache directory of every cached repo, and GET /api/hub/models-folder with the absolute hub cache
    root. The listing still answers, with the same repo ids, sizes, capabilities and partial state;
    the paths become an opaque reference. The dataset router and three routes that answer a path only
    through HTTPException.detail are outside this scope and unchanged.
  3. The chat load toast names the download phase. A load that begins believing the weights are
    cached can still turn into a download, and it said "Loading cached model into memory" the whole
    time, which is what [Studio Bug] Cached Qwen3.5-9B is re-downloaded, stalls on Xet, then fails after 14 minutes #9094's reporter watched for fourteen minutes.

Root cause

The local question was asked remotely. hub/utils/hf_tokens.py answered a two-valued question,
so every way of failing to reach the Hub became a denial: one blanket except Exception: return False over a refused connection, a 5xx, a 429 and a bare 404 from a mirror with no route, and a
timeout memoized as a denial for 30 seconds. utils/utils.py::anonymous_and_offline then refused
every non-local model at the route entry, before any of those gates ran.

The inventory is a filesystem listing, and it said so. Its rows carry the directory each copy was
found in. That is the right answer for the browser session, which is the operator looking at their
own machine and which hands the path back to the delete endpoint. It is not the right answer for an
API key, which is explicitly denied the operator's ambient Hugging Face credential in the first
place and never needed the cache root, the home directory above it or the account name inside it in
order to enumerate what is downloaded.

The load UI stopped asking. let downloadComplete = isDownloaded || isCachedLora; sent a cached
load straight to the mmap poller, so a transfer starting afterwards was never polled for.

Changes

A Hub that cannot be asked is not a Hub that said no

hub/utils/hf_tokens.py. _probe_repo_access and _explicit_token_reaches_repo become
three-valued: True confirmed, False answered no, None could not be asked. Denials are
{401, 403, 410, 451}, a 404 carrying an HF error code, and hub's own RepositoryNotFoundError,
GatedRepoError, DisabledRepoError and RevisionNotFoundError. A bare 404, 405, 429, 5xx, a 3xx,
a recorded redirect, a final URL that is not the repo asked about, a timeout and a refused
connection are not answers.

An unanswerable probe resolves against the disk, and only for the caller whose own credential
filled that cache
. Presence reuses hf_cache_state.repo_cache_has_usable_snapshot, so an
interrupted download is not presence, and it requires a readable listing to have actually found the
repo's cache directory. Provenance is recorded per repo at download time, carrying the identity of
the credential the fetch went out under, so a repo fetched under a one-off X-Unsloth-HF-Token is
not later handed to the host's own credential, which cannot reach it on the Hub. An answered no is
remembered for longer than it is cached and stands while the Hub cannot be asked, since 429 and 5xx
are unaskable while the Hub is still reachable from outside.

utils/models/model_config.py, utils/utils.py and routes/models.py ask that same shared rule
instead of refusing everything; online behaviour is deliberately unchanged.

What is deliberately unchanged: a UI session was never behind the probe and still is not; the
anonymous sentinel still cannot authorize itself; a local path is still never probed; and online, an
API key that cannot reach a private repo is still refused the operator's cached copy of it.

Host paths stay on the host

hub/utils/host_paths.py is new and holds the whole decision. The caller class comes from
auth.authentication.authenticated_via_api_key, the dependency the ambient token boundary is
already drawn with. A redacted cache_path becomes an opaque ref:<32 hex>, an HMAC under a
per-process key: stable for the life of the server, so a client can compare two rows, group a
companion asset with its model and de-duplicate a repo cached under two roots, and not reversible
into a path. null stays null, because the download manager reads cache_path as a three-state
discriminator. Scan-root lists are emptied rather than referenced. Anything that is not a bool for
the caller class means no HTTP request was classified, which is an in-process call by the operator's
own process.

Covered: /api/hub/cached-models, /api/hub/cached-gguf, /api/hub/models-folder,
/api/hub/scan-folders (both verbs), /api/hub/local, /api/hub/hidden-models,
/api/hub/orphan-companions, /api/hub/download-progress, /api/hub/gguf-download-progress,
/api/hub/transport-status, /api/models/cached-models and /api/models/cached-gguf. Routes on
that router which answer no host path are listed with their reason in the new test, and a drift test
fails if a new route neither takes the caller class nor appears in that list.

scrub_paths and short_path_for_log shorten an absolute path in a log line to the two components
that identify it, beside download_registry.scrub_secrets which does the same for credentials.

One path an API key still receives, deliberately: load_id. It is the repo id in the ordinary case
and becomes a snapshot directory exactly when the bare repo id cannot reach that copy. It is then
the handle the load and train endpoints take, so blanking it would leave a caller able to see a model
and unable to load it, and substituting the repo id would load a different revision. The decision is
recorded in the module docstring, and response_leaks_host_path takes an explicit ignore argument
so every test that tolerates it says so at the call site.

The download phase has a name

studio/frontend/src/features/chat/lib/cache-miss-download.ts is new and holds the decision as a
pure function. A byte count below the expected total proves nothing, since that is the ordinary state
of a partially fetched revision; only a count that grew between two readings is a transfer. A
complete reading resets the watch, and an unmeasurable cache is not evidence either way. Local paths,
Ollama manifests and cached LoRAs are never watched.

Compatibility

Three behaviour changes on inputs that previously succeeded.

A cached-model listing made with a Studio API key returns different JSON. String path fields come
back as "" and list path fields as [], for API-key callers only; an operator session is
unaffected. So that a client can still tell "this row has no file" from "this row's path is
withheld", cache_ref is present exactly when the row had a path, and that equivalence is pinned by
tests.

Cache reads are authorized more narrowly when the Hub cannot answer. Where a repository's status
is unaskable, presence on disk authorizes only the caller whose own credential populated that cache,
established from the per-repo provenance record rather than from what the host happens to hold now.
A caller with a valid Studio API key but a different HF token, or no HF token, is refused; so is a
host holding two different credentials, since either could have filled the cache. Where the
credential store cannot be read the outcome is "unknown", which authorizes nobody. What remains
uncovered is a cache filled before that record existed: those entries read as never recorded, which
authorizes. Failing closed on them would refuse the tokenless offline install its own cache on first
upgrade, which is the case this whole path exists for.

Measured over the gate's full input space, 1260 cells per predicate: 1250 and 1245 identical to the
merge base, 15 newly authorized, 0 newly refused. Every newly authorized cell is the tokenless
offline install, the operator's own credential on a repo recorded as fetched by it, or a repo never
recorded at all.

Four compatibility routes redact host paths for an API-key caller. GET /api/models/local,
/scan-folders, /download-progress and /gguf-download-progress now answer an sk-unsloth caller
with the same redaction their /api/hub twins use. Both routers are mounted in one app and reachable
with one key, so a boundary on one of them was not a boundary. A browser session sees exactly what it
saw.

Tests

Studio backend and frontend only, no core library surface. Python 3.13.12, torch 2.10.0+cpu,
transformers 5.4.0, huggingface_hub 1.31.0, mirroring studio-backend-ci.yml.

cd studio/backend
pytest tests/test_offline_local_cache_discovery.py        105 passed
pytest tests/test_cache_inventory_path_boundary.py        140 passed
pytest tests/test_hub_token_caller_identity.py            196 passed
pytest tests -n 8 --ignore=tests/test_studio_api.py       48324 passed, failure set identical to
                                                          the same run on main in this container
pytest hub/tests                                          697 passed

cd studio/frontend
node --experimental-strip-types --test tests/chat-cache-miss-download-label.test.ts   11 passed

The two new modules are behavioural: real cache directory trees, only the list of cache roots
redirected so the presence walk runs for real, real consumers driven rather than the helper alone,
and every path assertion made on the serialised HTTP response body rather than on the helper, because
the response model is where a field survives or is dropped.

Coverage is measured rather than asserted. A mutant that disables the redaction kills 48 of the 140
boundary cases; one that makes an unaskable probe deny again, the defect this PR exists for, kills 24
of the 105 discovery cases; nine further mutants, one per file this PR touches, each still die.

Each fix is paired with the boundary it must not move, so the change cannot be loosened later without
a test arguing back: a Hub that answered no still refuses a cached copy, a repo not on disk is still
refused, an interrupted download is not presence, one unreadable cache root does not make every repo
present, a UI session still sees its own paths, and an incomplete cache that is not moving is a load
rather than a download.

Two existing tests changed, both stated rather than quietly adjusted:

  • tests/test_hub_token_caller_identity.py, one assertion in
    test_an_unreachable_probe_takes_the_short_ttl_and_spans_the_next_request: the memo for an
    unreachable probe holds unknown rather than a denial. That line asserted the defect.
  • tests/test_export_absolute_paths.py gains authenticated_via_api_key in the import surface it
    pins, which its own comment predicted would be needed.

Cross-platform

Run on owned staging, counts read from the run logs rather than the green tick.

leg result
ubuntu-latest 840 passed, 1 skipped, 0 failed
macos-15 837 passed, 3 failed
windows-latest 836 passed, 3 skipped, 2 failed

Every failure has a base arm at the merge base, same OS, same tests, and each fails there
identically, so the five are pre-existing and platform-specific. None is in this PR's own modules,
which pass on all three.

Notes

This addresses item 2 of #10147 and the load-UI half of #9094; the download scoping half of #9094 is
unslothai/unsloth-zoo#1231. No Fixes line: #10147 is a tracker with other slices still open, and
#9094 needs both halves.

#10265 answers the same item of #10147 by returning an empty list to API keys. This takes the other
route on purpose, because the issue itself records that restricting the listing "would break API and
CLI consumers whose purpose is enumerating locally available models". Removing the paths removes the
disclosure without removing the feature. The two overlap textually in hub/routes/inventory.py only.

Log scrubbing also covers a Windows UNC path, which previously kept the server and share name in
full, and the redaction walk rebuilds a NamedTuple rather than raising on one.

What this looks like in Studio

Two isolated installs, built from this PR's merge base and from 432175c41, driven offline by one
scene against the same seeded cache, as a declared parity plan: matching halves are the passing
condition, a moved fact is a failure, and a scene that read nothing off the page is also a failure.

On Device list, operator session, merge base vs head

Two of the three changes here are deliberately invisible in the browser, so the screenshot is the
parity control, and for a PR that touches the inventory it is the load-bearing one: a UI session was
never behind the Hub probe and keeps its paths on purpose. Read from the same two servers, as a UI
session: row_count 2 and 2, rows_with_cache_path 2 and 2, rows_with_cache_ref 0 and 0,
models_folder_non_empty true and true. FACTS DIFF: (none). rows_with_cache_ref = 0 is the
load-bearing figure: it is the redaction's own discriminator, read from the side that must NOT be
redacted, so a 1 there would mean the API-key boundary had swallowed the operator too.

The change lives one layer out, in what the same photographed server tells a different caller class.
Read over HTTP from that server with an sk-unsloth key: apikey_rows 1 and 1,
apikey_rows_with_cache_path 1 and 0, apikey_rows_with_cache_ref 0 and 1, apikey_models_folder
<host path>/hub and "".

Two things the shot does not show, stated rather than left to be assumed. The absolute cache path is
not rendered at this zoom, so rows_with_cache_path is a measured API reading rather than something
you can confirm by eye. And row_count is 2 because HuggingFaceTB/SmolLM2-1.7B-Instruct also
appears from the real ~/.cache/huggingface/hub, which hf_cache_roots() scans even with HF_HOME,
HF_HUB_CACHE, HF_XET_CACHE and XDG_CACHE_HOME all pointed at the seeded directory; it is
present identically on both sides.

The composite predates the commits that followed it. Both later redactors are identity functions for
a UI session, each with a boundary test asserting exactly that equality, and the credential ledger
sits behind a gate a UI or ambient caller never reaches, so the picture still describes the head that
ships.

The one thing that does change on screen: the load toast

chat load toast for a cached model whose bytes are moving, merge base vs head

Two isolated installs again, merge base 353e38d41 on the left and head 9a678c04d on the right,
each serving its own install.sh --local build. The model really is in the cache (Qwen2.5-0.5B-Instruct,
seeded into an isolated HF_HOME the two Studios share), the row really is that cached repo under the
picker's On Device tab, and the click is real. What is scripted, identically on both sides, is the
transport: a fetch shim answers /api/models/download-progress with a sequence whose byte count grows
and carries no expected total, answers /api/inference/load-progress with "no phase", and holds
/api/inference/load open so neither half races a real load to the shot. That is #9094's shape without
needing a multi-gigabyte re-fetch to happen on a CI host, and both halves are handed the same readings,
so the only thing that can move the picture is the code under test.

Beside the picture, read out of the live page: names_cache_miss false to true, and
download_progress_reads 0 to 3 -- the base never asks the download endpoint at all during a cached
load, which is exactly why it had nothing to notice. load_progress_reads moves the other way, 20 to
1, which is the same finding seen from the other side: the head stops polling the load the moment it
decides a transfer is running. No weights are loaded and no GPU is touched.

…phase

The local model inventory is a filesystem listing, so its rows carried the
directory each copy was found in. A browser session is the operator looking at
their own machine, and the UI renders that path and hands it back to the delete
endpoint. An sk-unsloth API key is not: it is denied the ambient Hugging Face
credential, and the absolute cache root, the home directory above it and the
account name inside it are host detail it never needed in order to enumerate
what is downloaded.

The inventory keeps answering every authenticated caller with the same repo ids,
sizes, capabilities and partial state. For an API key, every host path in the
payload is now replaced by an opaque reference that is stable for the life of
the server, so rows can still be compared and de-duplicated, and the scan roots
are dropped rather than referenced. The same hygiene is applied to the inventory
log lines, which interpolated raw exceptions and raw cache directories.

Separately, a load that begins believing the weights are cached can still turn
into a download when the backend re-fetches a blob it will not resume. The chat
load toast said "Loading cached model into memory" throughout, so the transfer
was invisible. It is now watched for, and once bytes are seen to grow the phase,
the progress and the wording change to name it.
The cache-read gate put a live /auth-check round trip in front of every read of
the host's own Hugging Face disk cache, and collapsed "could not ask" into
"denied". A purely local question -- is this repo on my disk, what can it do,
load it -- then depended on reaching huggingface.co, so HF_HUB_OFFLINE=1, an
air-gapped host, a Hub outage, a rate limit, or an HF_ENDPOINT mirror that never
implemented the undocumented /auth-check route all reported a fully downloaded
model as unavailable and refused to load it.

The probe now answers three ways instead of two: the Hub confirmed it, the Hub
answered no, or the Hub could not be asked. Only an answered no denies. An
unaskable Hub resolves against the disk instead: present in one of this host's
caches means authorized, because the bytes are already here and nothing new is
fetched by saying so; absent still means refused, because there is nothing to
serve and the caller would only be asking the backend to go and fetch it.

Classification is measured against the live endpoint rather than assumed. A
public repo answers 200, a gated one 401 with X-Error-Code: GatedRepo, a private
or missing one a bare 401; /auth-check on a path that is not a route answers 404
with generic HTML. So 401, 403, 410 and 451, plus a 404 carrying an HF error
code, are answers; a bare 404, a 405, a 429, a 5xx, a redirect away from the repo
that was asked about, a timeout and a refused connection are not.

An unreachable probe is memoized as unknown rather than as a denial, so the
window no longer hands every caller a refusal the Hub never gave and a download
finishing inside it takes effect at once. The presence check is a disk walk that
never dials out, and requires a readable listing to have actually found a cache
directory for the repo, so one unreadable cache root cannot declare every repo
present. A probe that raises is a failure to ask, not a 500 on the route.

load_model_config's anonymous branch refused every cache-only read outright,
which cost an API client its own public downloaded models on exactly the host
where the cache is the only answer there is. It now asks the shared rule, which
also closes the reverse hole: online, that branch served a cached private
config.json with no gate at all.

The boundary is unchanged where it matters. A UI session keeps its ambient
entitlement, an API key still cannot borrow it for a network fetch, and online an
API key that cannot reach a private repo is still refused the operator's cached
copy of it.

tests/test_hub_token_caller_identity.py: the unreachable-probe memo assertion
asserted the stored value was False, which is the behaviour being removed; it now
asserts None, with the reason in place.

(cherry picked from commit f9907415f50af57aa782caccac6d865756fa58e8)
The offline precondition in utils.utils.anonymous_and_offline was a blanket:
an API client with no Hub token, on an offline host, was refused every cached
model before any per-reader gate ran, public repositories included. Fixing the
gates alone therefore left the operator with the same 404.

Given the repository the caller named, it now asks the shared cached-read rule,
which offline resolves against the disk: a repository that is present is served,
one that is not is still refused, because then there is nothing local to decide
with and saying yes would only authorize a new network fetch. Online behaviour
is unchanged, deliberately, since this guard has always been the offline
precondition and the per-reader gates own the online question.

The two refusal messages now name the cache as well as the credential. With a
local read no longer decided by reaching the Hub, "cannot be authorized" on its
own sent operators looking for a credential problem that was not there.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ebfe28b3f6

ℹ️ 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".

online, an API key that cannot reach a private repo is still refused the operator's
cached copy of it.
"""
return _repo_present_on_disk(repo_id, repo_type)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Require caller authorization before trusting local presence

When /auth-check is unavailable because the host is offline, rate-limited, behind an incompatible mirror, or experiencing an outage, this authorizes any usable on-disk repository without establishing that the API caller may access it. Consequently, an sk-unsloth caller with no Hugging Face token or an invalid token can name a cached private/gated model or dataset and reach cache-only readers that return its configuration, templates, source snippets, or preview data. Disk presence proves availability to the operator, not authorization for a remote API caller; retain a prior affirmative authorization or fail closed for non-UI callers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not taking this one: the authorization check you are asking for is already the gate on this branch, in _caller_populated_the_cache, and _resolve_unaskable consults it before it ever looks at disk.

Drove the matrix rather than reading it:

host HAS a token, caller sends none           -> authorized: False
host HAS a token, caller sends a wrong one    -> authorized: False
host HAS a token, caller sends empty          -> authorized: False
host HAS a token, caller sends the same       -> authorized: True
host has NO token, caller sends none          -> authorized: True
host has NO token, caller sends one           -> authorized: False
ambient UNKNOWN, caller sends none            -> authorized: False
ambient UNKNOWN, caller sends one             -> authorized: False

The exact case named, an sk-unsloth caller with no Hugging Face token or an invalid one naming a cached private or gated repo, is rows 1 to 3, and all three refuse. The token comparison is hmac.compare_digest rather than ==, since it is a compare on a secret over a repeatable request.

The single True for a credential-less caller is the case where it cannot leak anything: the host has no ambient credential either, so nothing in that cache can have been fetched under a credential this caller lacks. That is the ordinary install this PR exists for, and it is why the check is "the caller that fact is about" rather than "any caller".

It also fails closed on the third state: an ambient token that cannot be established authorizes nobody, on both branches, rather than guessing.

A Hub that ANSWERS no never reaches this function at all, so an online API key with no access to a private repo is still refused the operator's cached copy.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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-20T13:06:55.398535Z 5e73e2a 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.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Before and after, from two isolated installs

Two Studios built from this PR's merge base (1ee14f0) and its head (ebfe28b), each with its
own UNSLOTH_STUDIO_HOME and the same seeded Hugging Face cache holding exactly one model,
unsloth/gemma-3-270m-it. Both runs use HF_HOME, HF_HUB_CACHE, HF_XET_CACHE and
XDG_CACHE_HOME pointed at that cache, so the numbers below are about the seeded model and
nothing else on the host.

On Device list, before and after

The picture is the parity half, and for a change that touches the inventory it is the important
half: the operator's own On Device list is the same list, with the same row and the same paths,
before and after. A browser session was never behind the Hub probe and keeps its paths on
purpose, because it is the operator looking at their own machine, and the UI renders the path
and hands it back to the delete endpoint.

Footage of each side, offline, opening On Device on the seeded cache:

merge base this PR
before after

What did move, read from the same servers that were photographed

An sk-unsloth API key was minted on each install through POST /api/auth/api-keys and used to
call the routes with that key alone. Run offline, with HF_HUB_OFFLINE=1.

reading merge base this PR
GET /api/hub/cached-models as an API key 200, 1 row 200, 1 row
that row's cache_path the absolute repo directory empty, with an opaque cache_ref instead
the host cache root appears in the body yes no
GET /api/hub/models-folder as an API key 200, the absolute hub cache root 200, empty
GET /api/models/config/unsloth/gemma-3-270m-it with no Hugging Face credential, offline, model fully cached 404, "This request cannot be authorized without network access." 200, the config
the operator's own list, same call as a UI session 1 row, cache_path present 1 row, cache_path present

The first four rows are the disclosure in item 2 of #10147, closed without emptying the listing:
an API key still learns what is downloaded and no longer learns where it is kept. The fifth is
the offline half: a fully cached model, no network, and the answer is now the config instead of a
404 that blamed a credential.

The one path an API key still receives is load_id, and only when a copy's bare repo id cannot
reach it. It is the handle the load and train endpoints take, so blanking it would leave a caller
able to see a model and unable to load it. That is stated in the PR body and in the module
docstring, and the leak detector used by the tests takes an explicit ignore argument so the
decision has to be written down at each call site.

Not shown here: the load toast naming a download phase. Staging it faithfully needs a cache that
Studio reads as complete while huggingface_hub re-fetches a multi-gigabyte blob from it, which is
#9094's shape and not something this host can produce quickly. The decision it turns on is a pure
function with eight tests, including the case that must NOT relabel: an incomplete cache that is
not moving is a load, not a download.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
pre-commit-ci Bot and others added 2 commits September 15, 2026 16:15
Two of the predicate tests asserted str(cache_dir) == "/studio/cache", where the
value travels from the test's own Path through the production code and back
through str(). On Windows that round trip spells it with backslashes, so four
tests failed on a runner the backend suite has never been run on. Comparing
Path to Path keeps the claim, which is which cache root was asked about.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Cross-platform CI, off the org queue

Run on owned staging (danielhanchen/unsloth-staging-2, branch pr-11026-xplat-ci), because
Backend CI here is ubuntu only and this change touches path handling, which is exactly where the
three platforms disagree.

leg result tests
ubuntu-latest pass 314 passed
macos-15 pass 314 passed
windows-latest pass 312 passed, 2 skipped
studio-live Playwright pass installs this tree with install.sh, waits on /healthz, drives a live browser session

Counts are read out of each leg's log rather than taken from the green tick, since the generated
workflow treats "no tests ran" as success. The Playwright leg's smoke step runs with || true, so
read it as "this tree installs and serves a working UI on Linux" and not as a gate on the UI change.

Windows is the reason this was worth doing. On the first green-on-Linux pass it reported 4 failed,
270 passed, all four in test_hub_token_caller_identity.py:

assert all(root == "/studio/cache" for _n, root in seen)
AssertionError: asked the wrong cache root
assert (['\studio\cache', '\studio\cache', ...] and False)

Those tests stub active_hf_hub_cache to return Path("/studio/cache") and then compare
str(cache_dir) to the POSIX literal, so the round trip through Path spells it with backslashes
and they can never pass on Windows. They came in with #10264 and no Windows runner had executed
them. Comparing Path to Path keeps the claim, which is which cache root was asked about, and is
the last commit here.

Before that, all three per-OS legs failed at collection with
ModuleNotFoundError: No module named 'transformers': the generated job installs
studio/backend/requirements/studio.txt, which does not carry it. That is the runner rather than
the branch, and the legs above install it explicitly.

…ubber

An unaskable Hub resolves the cached read against the disk, which is right for an
offline operator. A 429 or a 5xx is unaskable while the Hub is still reachable from
outside, and the verdict cache only holds a minute, so a caller the Hub had already
refused could be handed the operator's cached copy of a private repo by an outage.
Remember an answered no for longer than the verdict is cached and let it stand while
the Hub cannot be asked; an answer of yes drops it, and a repo that was never refused
is unaffected, so air-gapped hosts, outages and mirrors without the route behave as
before.

Also scrub a Windows UNC path in log lines, which kept the server and share name in
full, and rebuild a NamedTuple in a redacted payload instead of raising.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Second pass over this one. Three things found and fixed on the branch, one of them on the boundary this PR exists to keep.

  1. An answered refusal could be overturned by an outage. Unaskable resolving against the disk is right for an offline operator, but 429 and 5xx are unaskable while the Hub is still perfectly reachable from outside, and the verdict cache only holds sixty seconds. So a caller the Hub had refused a minute ago was one induced rate limit away from the operator's cached copy of a private repo. An answered no is now remembered for longer than it is cached and stands while the Hub cannot be asked; an answered yes drops it; a repo that was never refused is untouched, so air-gapped hosts, Hub outages and mirrors with no /auth-check route behave exactly as the PR describes.
  2. scrub_paths left a Windows UNC path in the log in full, server and share name included, because it only matched a drive letter or a leading slash.
  3. The redaction walk raised on a NamedTuple instead of editing it, which would be a 500 rather than a payload.

Fixed in 1e573dd, with six tests, including one pinning that the test reset drops the denial memory so it cannot leak between tests.

Also checked:

  • Who the redaction actually applies to, against the real dependency rather than the test override: a session JWT sees paths, an sk-unsloth key does not, an in-process caller holding an unresolved Depends marker sees them, and a keyless caller counts as an API caller, which is off by default.
  • An older Studio cache layout. A repo present only in the legacy Unsloth cache is found by the presence walk, so an old install gets the offline fix too. Measured across legacy, current and absent layouts on both sides: the branch authorizes both layouts offline for an API key and for an anonymous caller, and still refuses when the repo is not on disk; main refuses all of it.
  • The path pattern against pathological input: 100k characters with no path in them, and a 20,000 segment path, both under 5ms.
  • The frontend. Whole suite 7568 passed, tsc -b clean, and the new cache-miss decision run in four real browser engines, Chromium 151, Firefox 153, WebKit 26.5 and Edge 152, with identical verdicts in all four.
  • A Studio home written by the merge base opens on this branch unchanged, and the response only gains a field, so an already-open tab on the old bundle still parses it.
  • The whole Studio backend suite: 45502 passed, no failure this branch introduces.
  • Cross-platform staging CI: Linux green and the live Studio Playwright leg green; macOS and Windows were still queued when this was written. The first attempt needed transformers installed on the runner, since test_hub_token_caller_identity.py imports it at collection.

One note unrelated to this PR: the Composer (macos-latest, browsers) check is failing here, and it fails the same way on other branches in the same hour. The artifact shows Chromium, Firefox, WebKit and Edge all passing and only the Chrome stable channel, now 152, failing to_have_value("First line\nSecond line") in tests/studio/playwright_composer_settings.py.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 16, 2026
@danielhanchen

danielhanchen commented Sep 20, 2026 •

Copy link
Copy Markdown
Member Author

Cross-platform run, head vs base, on the staging repo rather than the org queue.

Head arm (PR merged onto main): macOS 15 882 passed / 3 failed, Windows 881 passed / 2 failed. Base arm (main alone, same generated jobs, same dependency set): macOS 1324 passed / 4 failed, Windows 1319 passed / 7 failed.

Every failure the head arm shows is reproduced by the base arm:

platform failing on head also failing on base
macOS 15 test_video_routes: judges_a_quantized_reference_pick_per_partition, refuses_a_quantized_reference_task, refuses_an_unavailable_transformer_quant yes, all three
Windows test_diffusion_routes: a_pipeline_pick_may_pin_a_precision, a_transformer_family_still_reaches_the_scheme_check yes, both

The macOS three are the Apple Silicon refusal for minimax-h3 answering 400 where the test expects a quant verdict, which has nothing to do with this branch; they fail identically without it. The base arm also fails five tests the head arm does not, four in test_hub_token_caller_identity and one in test_openai_auto_switch, which is the base version of those files on Windows: the arms run each side's own tests, so that column is not a regression in either direction.

The Linux leg has since finished green: ubuntu-latest 885 passed, 1 skipped, 0 failed.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 4 commits September 20, 2026 06:36
The status route took neither the api-key dependency nor the redactor, so polling
a started run handed back the model path the inventory hides: the worker quotes
what it is loading, and for a local model that is an absolute path. Scrubbing the
message alone was not enough either, since a run's warnings quote the file they
are about and no singular text field reaches a list.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The dataset preview recorded above list_repo_files, so a 404 or an outage left a
record for a fetch that never happened and the first record stands; it now writes
at each load_dataset call, the only place rows can materialise. Separately, the
rule that keeps https:// intact refuses the leading slash of file:///home/...,
so an exception formatting its filename as a URI went out whole through the
retained error text an API-key caller reads.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 20, 2026 07:25
…hing

The anonymous config gate carried a second clause that discarded the very verdict
the unaskable fallback produces: online but unable to ask, transformers serves
the cached config.json after its own metadata request fails, which is the private
read the gate is for. A public repo on disk is not the cost, since the provenance
rule underneath refuses only where a credential could have filled that cache.

The three call sites that fetch under a request token now wrap the call instead
of writing beside it. The record still precedes the fetch, because a download
that dies half way has filled the cache anyway, but a call that raised having
left nothing on disk takes its record back, and only while the record is still
its own.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0ed620ad45

ℹ️ 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".

The one-off-token contract was a 106-line test that failed as a single opaque
assertion; it is now three tables (present, absent, ordered) of 25 named cases,
so a broken rule says which rule. Four route tests that differed only in client
or stub become two parametrized ones, which also gains the compat mirrors the
browser-session leg they did not have.

Coverage is unchanged, measured rather than assumed: four mutations (redaction
off, provenance off, an unaskable probe denying again, text scrubbing off) kill
exactly 32, 8, 25 and 27 tests before and after. Cases go 264 to 284, functions
121 to 120, lines 3355 to 3421: the tables cost about as much as the duplication
they remove, which is the honest state of these two files.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 3 commits September 20, 2026 10:42
The ledger of credentials this host has ever held was written only where an
unaskable probe happened to consult it, so on an upgraded install an operator who
replaced or cleared the saved token before any such probe left no trace of the
old one, and a later outage handed a tokenless caller everything it had
downloaded. The save and delete paths now record it while Studio still has it,
and a row that exists but cannot be decrypted records a sentinel identity no
caller can match, since an unreadable credential is still one this host held.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: ef79145a21

ℹ️ 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".

pre-commit-ci Bot and others added 2 commits September 20, 2026 11:24
Removing the online clause from the anonymous config gate left its import unused,
which the import-hoist gate blocks, and left `hub_answered_no` itself with no
caller anywhere. It exists only to express the reasoning that clause got wrong,
so it goes with it rather than sitting there for someone to reach for.
@danielhanchen

Copy link
Copy Markdown
Member Author

pre-commit.ci run

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 5e73e2a43e

ℹ️ 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 Author

Both red checks on this head were investigated and neither reproduces against this branch's code.

(Python 3.13, rest) failed 2 of 13073: test_managed_requests_do_not_grow_with_account_count and test_transcode_to_file_leaves_no_temp_file_when_the_encode_fails. I ran that job's exact selection (same Python, same dependency install, same -n 4 --dist loadgroup --timeout=330 with all fourteen ignores and the -k filter) on a clean runner twice, against two trees that differ only in whether this PR is merged in:

arm tree result
base e49b2df3c (main) 13072 passed, 0 failed
head 3ee1bcee8 (this PR merged) 13073 passed, 0 failed

Runs: base, head.

The head arm is the same tree that failed here, and it passed the whole shard. Both tests also pass in isolation on this head, and locally the full shard produces an identical failure set on both arms with nothing unique to either side. That matches what studio-backend-ci.yml already records about this suite under four workers: "it fails tests serial does not, in more than one way and not the same way twice."

Composer (macos-latest, safari) failed in webdriver.Safari() with SessionNotCreatedException: The session timed out while connecting to a Safari instance, before any application code ran. That is the runner, not the diff.

Neither run can be re-run through the API from here, so the two checks stay red on this commit until something else pushes the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# important# refactor# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants