Skip to content

Studio: keep an API key from borrowing the operator's Hugging Face token (#10126) - #10142

Merged
danielhanchen merged 59 commits into
unslothai:mainfrom
harshaygadekar:fix/studio-hub-write-ambient-token
Sep 6, 2026
Merged

danielhanchen merged 59 commits into
unslothai:mainfrom
harshaygadekar:fix/studio-hub-write-ambient-token

Conversation

@harshaygadekar

@harshaygadekar harshaygadekar commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10126. Follows #8433 and #10076, which did the download paths.

The hole

The operator's ambient HF_TOKEN, whether from the host environment or Studio Settings, is an operator credential. An sk-unsloth API key is refused that token by require_ui_session, so it must not reach it another way.

One write path handed it over outright. publish_job_dataset passed hf_token=None to publish_recipe_dataset, which gives it straight to HuggingFaceHubClient and card.push_to_hub (core/data_recipe/huggingface.py:74,99), so a dataset published by an API-key caller was published as whoever the host is logged in as.

The load path was subtler and is the larger part of the change. Even with the environment scrubbed, None is not anonymous to this stack: unsloth reads it as go and find a credential, spelled if token is None: token = get_token() in save.py and in hf_login (models/_utils.py:4106), and get_token() reads the operator's stored login from ~/.cache/huggingface/token, which no environment change touches. Measured in a spawned worker:

hf_login(None)   -> 'hf_OCyvBQIiC...'   the operator's stored token, and it logs in with it
hf_login(False)  -> False               no login, no exception

So an API-key checkpoint load ran as the operator on any host where the operator had ever run hf auth login, which is the normal state.

The change

allow_ambient_hf_token, the dependency #10076 added for downloads, now also gates the write and load paths:

  • Recipe publish refuses with 400 when an API-key caller supplies no token.
  • Export routes resolve the credential through _resolve_export_hf_token, which returns the anonymous sentinel (hub/utils/hf_tokens.HfTokenArg) rather than None, and refuses a Hub push without a token. The push refusal is a better error rather than a closed hole: core/export/export.py already declined a push without an explicit token, so ambient credentials were never reachable there.
  • The export worker, when the load is non-ambient, scrubs the Hub variables and sets HF_HUB_DISABLE_IMPLICIT_TOKEN before huggingface_hub is imported, via the existing apply_token_to_child_env. It then rebuilds the canonical HfTokenArg once and uses it for the whole preflight and for ExportBackend.load_checkpoint, so the sentinel reaches the detection probes, the weight loaders and the local GGUF and merged saves instead of collapsing to None.
  • MCP names the policy on its two direct route calls, since a direct Python call never resolves a FastAPI Depends default.

An export runs under the identity that loaded the checkpoint. The orchestrator spawns a fresh worker per load, so a later load re-decides.

What this does not do

The shared Hugging Face cache still answers from disk without reauthorizing, so a caller who is denied the ambient token can still be served content the operator cached. That is unchanged from main and is a read-path question about partitioning the cache per credential, which belongs in its own change rather than in the export loader.

Testing

studio/backend/tests/test_hub_write_ambient_token.py covers the publish refusal and its two allowed shapes, the four export routes for push refusal, push with a token, and local export identity, the load-checkpoint policy, the worker environment for each policy including a pre-change config, the preflight credential, the loader never receiving None, the upstream hf_login contract, and the local GGUF and merged saves.

Verified locally: 1807 passed, 4 skipped across the affected studio/backend/tests; the same suites give 51 passed, 1 skipped with unsloth unimportable, which is a supported torch-less install; and a real load plus merged export through the actual spawned worker succeeds in both modes on an RTX 6000 Ada and a 3090 with the operator's token planted in the environment and absent from the worker's output.

Copilot AI lite review requested due to automatic review settings September 1, 2026 10:29
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@harshaygadekar
harshaygadekar force-pushed the fix/studio-hub-write-ambient-token branch from efe42c9 to ca42a37 Compare September 1, 2026 10:38
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@harshaygadekar
harshaygadekar force-pushed the fix/studio-hub-write-ambient-token branch from 97fbbd9 to 1746ea3 Compare September 1, 2026 11:02
@harshaygadekar
harshaygadekar requested a lite review from Copilot September 1, 2026 11:06
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread studio/backend/core/export/worker.py Resolved
@harshaygadekar
harshaygadekar force-pushed the fix/studio-hub-write-ambient-token branch from 253f56b to 74ef564 Compare September 1, 2026 11:28

@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

model_id, hf_token = token, local_files_only = local_files_only

P1 Badge Strip ambient credentials from vision sidecars

When an API-key caller without hf_token loads a gated Transformers-5 checkpoint, this forwards False, but _is_vision_model_subprocess converts it to an empty argument and launches the child with child_env_without_native_path_secret(), which still inherits the operator's HF_TOKEN; the child then omits the explicit token keyword and AutoConfig authenticates implicitly. Fresh evidence beyond the earlier fixed in-process AutoConfig fallback is this separate vision-sidecar environment path at utils/models/model_config.py:889-920; strip HF credentials and disable implicit authentication for the False sentinel before spawning it.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@harshaygadekar
harshaygadekar force-pushed the fix/studio-hub-write-ambient-token branch 2 times, most recently from c481a67 to 4ab5bb8 Compare September 1, 2026 11:44
@harshaygadekar

Copy link
Copy Markdown
Contributor Author

💡 Codex Review

model_id, hf_token = token, local_files_only = local_files_only

P1 Badge Strip ambient credentials from vision sidecars
When an API-key caller without hf_token loads a gated Transformers-5 checkpoint, this forwards False, but _is_vision_model_subprocess converts it to an empty argument and launches the child with child_env_without_native_path_secret(), which still inherits the operator's HF_TOKEN; the child then omits the explicit token keyword and AutoConfig authenticates implicitly. Fresh evidence beyond the earlier fixed in-process AutoConfig fallback is this separate vision-sidecar environment path at utils/models/model_config.py:889-920; strip HF credentials and disable implicit authentication for the False sentinel before spawning it.

ℹ️ About Codex in GitHub

yep, stripped HF environment tokens and set HF_HUB_DISABLE_IMPLICIT_TOKEN=1 in _is_vision_model_subprocess when hf_token is False

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the hole is still there on main, in data_recipe/jobs.py:562,595 and in the export routes, so gating the ambient token on the write paths is right. The part I would like narrowed is the False sentinel threaded through model_config.py, file_security.py, transformers_version.py and worker.py where the parameters are typed str or None; could you carry the policy as an explicit anonymous flag instead of overloading the token value?

@harshaygadekar

Copy link
Copy Markdown
Contributor Author

Confirmed the hole is still there on main, in data_recipe/jobs.py:562,595 and in the export routes, so gating the ambient token on the write paths is right. The part I would like narrowed is the False sentinel threaded through model_config.py, file_security.py, transformers_version.py and worker.py where the parameters are typed str or None; could you carry the policy as an explicit anonymous flag instead of overloading the token value?

hey @danielhanchen, Yep. Makes total sense.

I've updated the PR and rebased onto latest main:

  • So now, i have dropped the False sentinel, kept token params cleanly typed as str | None and reverted model_config.py, transformers_version.py, etc. back to upstream.
  • carried the policy as an explicit "allow_ambient" boolean flag down to export worker, which scrubs ambient HF env vars if disabled without a token.
  • Also kept the write path 400 guards on dataset publishing & export routes when API callers don't supply HF token.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@oobabooga

Copy link
Copy Markdown
Member

I have cut this back, and I owe an explanation because most of what I am removing is code I added.

Twenty-eight review rounds is the signal. Classifying all 59 bot findings by what they landed on: 29 were about a private per-worker token store and its lifecycle, 19 about a shared-cache authorization gate, and 5 about the original scope. Both of those subsystems were mine, added during review, and neither is required by #10126. The findings were real, one after another, because the code under them kept being wrong; what they were reviewing should not have been there.

The root cause is one decision. ~/.cache/huggingface/token and the Hub cache are process-global, operator-owned resources, and the export worker is a persistent process serving more than one caller. Trying to give a per-request credential scope inside it meant a private HF_TOKEN_PATH store, which needed an ownership model, which needed cleanup on six different worker exits, which needed a lock, which needed pending and owned state, which needed compare-and-clear in four places. Each round was a consequence of the first decision rather than an independent defect. The clearest evidence that the layer was wrong is that I shipped three availability regressions from it and had to walk each one back: offline exports of local LoRAs, air-gapped loads of plain cached models, and a macOS CI break on torch-less installs.

What is left is what the issue asks for. The recipe publish refusal, which is the one place the operator's token was actually handed over. The export routes resolving the credential as the anonymous sentinel instead of None, plus the push refusal. The worker scrubbing its environment for a non-ambient load and threading that sentinel through the preflight and into the loaders, which is the deep part and the reason hf_login(None) cannot go and fetch the operator's stored login. And MCP naming the policy on its two direct calls. That is 604 lines against the merge base, down from 2530, and 127 more than the PR had when it was opened.

Removed: the token store and everything that grew around it, the per-command credential scope, and the auth_check cache-authorization gate with its revision pinning and adapter-base resolution. The cache disclosure that gate was aimed at is real, I measured it against a gated repo this host has cached, but it is a read-path problem that exists on main, and the honest fix is partitioning the shared cache per credential, which is a design change and a product call rather than something to bolt onto the export loader. It is now stated as a boundary in the description instead of half-solved here.

One thing the removal re-opened, so I closed it directly: the merged local save was relying on the store, and now forwards the credential itself.

I have cleared the settled threads. The five rejected findings and their replies are kept, since that is the live argument.

Title and description are rewritten to match what the code now does, including that the export push refusal is a better error rather than a closed hole.

Verified on this commit: 1807 passed and 4 skipped across the affected studio/backend/tests; 51 passed and 1 skipped with unsloth unimportable; real load plus merged export through the actual spawned worker in both modes on an RTX 6000 Ada and a 3090, operator token planted and absent from the worker output. Every retained behaviour is mutation-checked.

Sorry for the detour, @harshaygadekar. Your original change was closer to right than what I turned it into.

@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: 9ee0ea30f2

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

Tuple of (success: bool, message: str)
"""
token = hf_token if hf_token and hf_token.strip() else None
token = normalize_token(hf_token)

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 Reauthorize anonymous cache-backed checkpoint loads

When an API-key or MCP caller omits hf_token and requests a private repository already present in the operator's shared Hugging Face cache, normalizing to False prevents ambient authentication but does not prevent from_pretrained from serving the cached weights (especially with local_files_only=True while offline); the caller can then export or push those private weights. Fresh evidence after the earlier confirmed fix is that the final tree removed the _access_allowed cache-authorization gate and now proceeds directly from this normalization to the shared-cache loader, so anonymous cache-backed targets must be refused or reauthorized.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not taking this, and the reason is the reason the PR was just cut back. The phenomenon is real, I measured it earlier against a gated repo this host has cached: hf_hub_download and transformers cached_file both serve the operator's snapshot for token=False, online as well as offline. It is also unchanged from main, where the same caller received the operator's token outright and could fetch that repo from the network as well, so nothing here is a regression.

The gate you are asking for is the one I removed. It was an auth_check round-trip on every remote target, plus revision pinning, adapter-base resolution and provenance handling, and it produced three availability regressions I had to walk back one at a time: offline exports of local LoRAs, air-gapped loads of ordinary cached models, and a synchronous Hub call under the orchestrator's export lock. The correct fix is to partition the shared cache per credential, the way hub/services/models/gguf_variants.py:1277 already gates its own cache reads, applied consistently across the cache readers. That is a design change and a product decision, not something the export loader should carry, and it is now written into the description as an explicit boundary rather than half-solved here.

Comment thread studio/backend/core/export/worker.py Outdated
Comment on lines +575 to +576
if not config.get("allow_ambient", True):
apply_token_to_child_env(os.environ, config.get("hf_token") or False)

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 Re-scope the worker environment for every export caller

When a UI session loads the persistent worker and a later API-key caller starts a local export without hf_token, this load-time-only condition leaves the operator's ambient token in the worker environment even though the export command carries False. The LoRA-GGUF and compressed exporters copy os.environ for their child processes and only replace tokens for nonempty strings (unsloth/save.py:5761-5764 and 7238-7242), so those children can fetch a private base config or calibration data with the operator credential. Fresh evidence after the earlier per-command isolation fix is that the final tree removed _credential_scope and retained only this worker-wide decision; scrub or grant credentials around each export command instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not taking this either, same reasoning. The cross-caller case is real and it is stated: an export runs under the identity that loaded the checkpoint, and the orchestrator spawns a fresh worker per load, so a later load re-decides.

Per-command re-scoping is what I removed, and it cannot deliver the symmetric rule it appears to. huggingface_hub freezes HF_HUB_DISABLE_IMPLICIT_TOKEN into a module constant at import, so a command can tighten the worker's credentials but can never restore ambient use for a UI caller that follows an API-key load. The result is a rule that only works one way, in a process that outlives the request, which is exactly the mismatch that produced twenty-eight rounds here: a per-request policy enforced inside a per-worker process. Re-adding it walks back into that.

Keeping the worker-wide decision is the coherent version: one identity per worker, decided at load, stated in the code and in the description. If per-caller export identity is wanted, the answer is a worker per credential scope, which is a real design change rather than another guard.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: bbc0b095ec

ℹ️ 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. Hooray!

Reviewed commit: fc71242217

ℹ️ 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. More of your lovely PRs please.

Reviewed commit: 1277a888bf

ℹ️ 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: 145b3fb7c9

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

…ambient

Three things the write-path gating did not cover, found by running the caller,
route, platform and worker-sequence combinations against the branch.

The worker kept the caller's own token. `apply_token_to_child_env` grants for a
string and only scrubs for the sentinel, and the worker passed it
`config["hf_token"] or False`, so an API-key caller that supplied a token of its
own left it in `HF_TOKEN` with `HF_HUB_DISABLE_IMPLICIT_TOKEN=0`. That process
outlives the load: `load_checkpoint` is the only thing that respawns a worker and
every later export command reuses whichever one is alive, whoever sends it. So
the next caller's `save_pretrained_merged`, which passes no token when it has
none of its own, resolved `get_token()` to the previous caller's credential. It
is the same leak this file exists to close, pointing the other way. A non-ambient
worker now holds no credential at all; the caller's own travels as an argument,
and the helper still grants it per child that needs it, so nothing loses access
it had.

`HF_OIDC_RESOURCE` was not scrubbed. It is not a token but it names one:
huggingface_hub 1.23 and later exchange it for a short-lived credential inside
`get_token()`, ahead of `HF_TOKEN`, and studio.txt pins that range for every
supported interpreter. On a Trusted-Publisher host the scrub therefore left a
second road to an operator-scoped token. Harmless on older versions, which have
no OIDC source.

`export_gguf` still declared `hf_token: Optional[str]` while the sentinel reaches
it, alone among the five entry points. That is the annotation that invites the
next reader to normalise `False` back to `None`.

Tests. A regression test for the cross-caller case that reads what `get_token()`
resolves to inside the worker rather than only the environment. Three structural
guards, because nothing enumerated these before and a new endpoint would ship
ungated in silence: every export entry point declares the sentinel type, every
Hub write route declares the ambient policy, and every MCP tool that calls a
gated route names it, since a direct Python call never resolves a `Depends`
default. Each is mutation-checked. The worker-environment case that asserted the
caller's token was kept now asserts it is passed instead.
@danielhanchen

Copy link
Copy Markdown
Member

Reviewed this end to end and pushed 33b34b4 with three fixes. The write-path gating is right and the load-path argument is right; I verified both rather than taking them on trust, and then found three things the gating does not cover.

The premise, measured rather than read

The suite asserts the hf_login contract with inspect.getsource. Run against a fake HF_HOME with a canary and every alias cleared:

get_token()                              -> canary
hf_login(None)   called get_token: True  -> resolved the canary, logged in with it
hf_login(False)  called get_token: False -> False

and with HF_HUB_DISABLE_IMPLICIT_TOKEN=1 set, hf_login(None) still resolves it, which is the whole reason the sentinel has to be threaded. Same on huggingface_hub 0.36.2 and 1.30.0, so it holds across the range studio.txt allows. login(token=False) raises AttributeError: 'bool' object has no attribute 'startswith' internally and unsloth swallows it, so the effect matches but every anonymous load logs a misleading "Failed to login" line.

Base versus head on the publish path, same test against both trees:

tree API key, no token, POST /jobs/{id}/publish token reaching publish_recipe_dataset
b8bfff267 200 None, so HuggingFaceHubClient used the operator's login
145b3fb7c 400 never called

The description's own correction is accurate: the four export pushes were already refused without a token at core/export/export.py, so those 400s are a better error, not a closed hole.

What I changed

The worker kept the caller's own token. apply_token_to_child_env grants for a string and only scrubs for the sentinel, and worker.py passed it config["hf_token"] or False. An API-key caller that supplied a token left it in HF_TOKEN, with HF_HUB_DISABLE_IMPLICIT_TOKEN=0. The worker is a singleton that outlives the load, _run_export reuses whichever one is alive with no ownership check, and the export commands do not carry allow_ambient at all. Measured, with the operator's token planted in all five aliases:

non-ambient load, caller sent its own token:
      HF_TOKEN = 'hf_callerA_secret'   HF_HUB_DISABLE_IMPLICIT_TOKEN = '0'
non-ambient load, no caller token:     all aliases gone, DISABLE_IMPLICIT = '1'   correct
ambient (UI) load:                     operator token in all five, by design

and the consuming end: for a later caller with no token of its own, merged_token_kw is {}, so save_pretrained_merged falls through to save.py's if token is None: token = get_token(), which reads HF_TOKEN first. This is what cabf7b4 fixed and the cut-back reverted, and the parametrisation (False, "hf_caller", "hf_caller", "0", "hf_caller") pins it. A non-ambient worker now holds nothing; the caller's own token travels as an argument and the helper still grants it per child, so nothing loses access.

HF_OIDC_RESOURCE was not in the scrub list. It is not a token but it names one: huggingface_hub 1.23 and later exchange it inside get_token() ahead of HF_TOKEN, and studio.txt pins >=1.23 for every supported interpreter. On a Trusted-Publisher host the scrub left a second road to an operator-scoped credential. Note hub/services/download_lifecycle.py:214 and core/inference/tools.py:6922 hand-roll the same list and have the same gap; I left those alone as pre-existing and out of this PR's scope.

export_gguf still declared hf_token: Optional[str] while the sentinel reaches it, alone among the five entry points.

Plus three structural guards, since nothing enumerated any of this and a new endpoint would ship ungated in silence: every export entry point declares the sentinel type, every Hub write route declares the ambient policy, and every MCP tool calling a gated route names it, because a direct Python call never resolves a Depends default. All mutation-checked.

How it was tested

175 combinations of caller shape, route, platform and worker sequence: {UI, UI+token, API key, API key+token, blank, whitespace, keyless, MCP} x {publish, load, merged, base, gguf, lora} x {push, local} x {Linux, WSL, Windows, macOS+MLX, macOS+torch} x {CUDA, ROCm, MPS, CPU}, on two isolated venvs, one with hub 0.36 and transformers 4.x and one with hub 1.30 and transformers 5.x, both torch-less.

merge base b8bfff267   102 failed, 73 passed     the sims are not vacuous
head 145b3fb7c           4 failed, 171 passed    the three items above
with 33b34b4eb           0 failed, 175 passed

Availability was checked as deliberately as the leak: an API-key caller with its own token still reaches every preflight helper and the loader, on both policies. Also confirmed no UI-session flow is refused anywhere in the matrix, no frontend file changes so no browser path is affected, an old saver with no token kwarg still exports, an orchestrator config predating allow_ambient still reads as ambient, and the MLX saver shape gets the credential like the torch one.

The full backend leg as CI runs it, before and after 33b34b4, gives an identical failure set (34, all reproducing on the merge base in my environment, diffusers and peft pins) with 37178 passing against 37174. All eight production hunks of the original change are mutation-caught, and a full revert is caught by 10 of the 14 test functions; the four survivors are back-compat characterisations rather than fix coverage, which is the right shape for them.

Left open, deliberately

An export still runs under the identity that loaded the checkpoint, so a non-ambient export command in a worker a UI session loaded can still reach the operator's environment through any call that passes no token, export_gguf without an imatrix being the clearest one. Closing that needs either per-command re-scoping, which HF_HUB_DISABLE_IMPLICIT_TOKEN being frozen at import defeats, or the per-worker token store that was correctly removed. It is worth stating in the description as a boundary rather than half-solving here, along with the shared-cache point already there. routes/settings.py:2660 and routes/training.py:1423 still read the ambient token on the load side; those are the read paths #10126 lists as outstanding.

pre-commit-ci Bot and others added 3 commits September 6, 2026 10:05
…s on

huggingface_hub reads HF_HUB_DISABLE_IMPLICIT_TOKEN once, into a module constant,
so the scrub in run_export_process only works while nothing has imported it yet.
An import added anywhere in the worker's module chain would silently disable the
switch with every other test in this file still green, because they only read
os.environ. A subprocess now asserts that importing core.export.worker leaves
huggingface_hub out of sys.modules.

Also drops a get_token() assertion added in the previous commit. It read as
"nothing is reachable", but get_token() also reads the operator's stored login
off disk, which no environment change touches; that is the reason the sentinel is
threaded to the loaders in the first place, and asserting it in-process only
passed because no token file existed there. The environment assertion beside it
is the one an in-process test can honestly make.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 44e2c90493

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

You have reached your Codex usage limits for security reviews. Please try again later.

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.

Studio: Hub write paths still lend the backend's HF_TOKEN to API-key callers

4 participants