Repository navigation
Conversation
The upload action re-read the token from huggingface_hub.get_token() on every iteration of the action loop. When no token is stored on disk (the default, since Heretic deliberately avoids huggingface_hub.login()), the user was therefore prompted for it again on every single upload. Cache the token in memory for the duration of the loop so that a subsequent upload reuses the one that was just entered, without ever persisting it to disk or exposing it through the settings. Fixes p-e-w#142
agammann
left a comment
There was a problem hiding this comment.
upload_token is assigned before huggingface_hub.whoami(token) validates it. If the user mistypes a token, whoami raises and the outer action-loop handler prints the error, but the invalid token remains cached. Selecting Upload again then takes upload_token or huggingface_hub.get_token() and never prompts for a replacement, so the user cannot recover within the session. Could the cache be updated only after a successful whoami (and cleared on an authentication failure)?
|
The token is now only remembered after |
Excellente analyse et merci pour cette PR. |
| if settings.upload_repo_private is None | ||
| else ( | ||
| "Private" | ||
| if settings.upload_repo_private |
The previous change correctly validated before caching on failure, but dropped the successful-path assignment, so a valid token was never remembered across uploads in the same session.
|
Follow-up at |
|
Thanks for the follow-up. At One documentation detail: the description says |
|
Thanks, you were right that the code and the description disagreed. Fixed in 8dbbb69 by making the code match the documented intent:
I've updated the description with a short precedence and recovery section. On tests: this logic sits inline in the interactive action loop in |
|
Thanks for clarifying the configured-token precedence. One follow-up: at |
Only an authentication failure (HTTP 401) clears the remembered token. Network errors, rate limits and server errors leave it in place.
|
Good catch, thanks. Fixed in 43d285f: the handler now catches only I checked the three cases (401, 503, |
|
Thanks for the update. I rechecked |
fix: remember the Hugging Face token between uploads
Summary
The
uploadaction of the interactive action loop obtained the Hugging Face access token withhuggingface_hub.get_token()on every iteration, and only fell back to an interactive prompt if that returned nothing.Since Heretic deliberately avoids
huggingface_hub.login()(it would write the token to disk, which is undesirable on rented or shared GPU servers),get_token()usually returnsNoneunless the user has setHF_TOKENor a token file. That means a token entered at the prompt was used for exactly one upload: uploading a second model in the same session asked for the token again.Cache a token entered at the prompt in a local variable for the duration of the action loop, so a second upload reuses it.
Token precedence and recovery
On every upload the token is resolved as
huggingface_hub.get_token() or upload_token:HF_TOKENor the HF token file always wins and is never cached.A prompted token is remembered only after
huggingface_hub.whoami()succeeds. If the Hub rejects the token (HTTP 401), the cache is cleared and the error goes to the action-loop handler, so the next upload attempt prompts again. Transient failures (network errors, rate limits, server errors) leave a cached token in place, so retrying the upload does not require re-entering a token that may still be valid. A configured token that fails validation is used again on the next attempt, which is the same as before this change; the user recovers by fixingHF_TOKENor the token file.Why this doesn't weaken the security posture
The cache is a plain local variable in
run():settings, so it cannot be exported in a saved configuration,huggingface_hub.get_token()is consulted first on every upload, so a token configured viaHF_TOKENor the token file keeps taking precedence over anything cached.Related
Fixes #142.