Repository navigation
Studio: fall back to anonymous HF browsing on a malformed token - #6605
Conversation
The Discover/Recommended feeds call the Hugging Face JS client (`listModels`/`listDatasets`) directly from the browser. That client throws `Your access token must start with 'hf_'` when handed a non-empty token that isn't a well-formed HF token, instead of falling back to anonymous access. A single bad value left in the HF token field (e.g. a placeholder someone typed) therefore takes down the entire discovery feed even though it works fine with no token at all. Add `hfApiToken()` to the HF token store, which returns the token only when it looks like a real `hf_...` credential and `undefined` otherwise, and route hub-page's four HF call sites through it. Malformed tokens now degrade to anonymous public browsing rather than erroring. The raw token is still stored and shown in the settings field unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Code Review
This pull request introduces a sanitization helper function, hfApiToken, to ensure only well-formed Hugging Face tokens (starting with 'hf_') are forwarded to the Hugging Face client, preventing malformed tokens from breaking anonymous browsing. The ModelsPage component is updated to use this sanitized token. The reviewer advises against implementing logic for features not yet exposed in the UI, specifically cautioning against wiring up a token store if the token cannot be configured by the user yet.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| export function hfApiToken( | ||
| token: string | undefined | null, | ||
| ): string | undefined { | ||
| return token && token.startsWith("hf_") ? token : undefined; |
There was a problem hiding this comment.
Avoid implementing logic for features that are not yet exposed in the UI or planned for the near future. Do not wire up a token store for Hugging Face if the token cannot be configured by the user yet.
References
- Avoid implementing logic for features that are not yet exposed in the UI or planned for the near future, even if it seems more consistent. For example, do not wire up a token for a service if the token cannot be configured by the user.
There was a problem hiding this comment.
Thanks, but this guidance doesn't apply here — the HF token is already user-configurable and has been for a while. The store is wired to inputs in Settings → General (general-tab.tsx), the Export page (export-page.tsx), onboarding (dataset + model-selection steps), and the studio model section. This PR doesn't introduce a new token store; it adds a sanitizer to the existing one.
In fact this is a real, user-triggered bug: a malformed value typed into one of those fields (e.g. hellothere) makes the HF JS client throw Your access token must start with 'hf_' and takes down the entire Discover/Recommended feed, which otherwise works anonymously with no token. hfApiToken() makes a malformed token degrade to anonymous browsing instead of erroring. Keeping the change.
|
@codex review |
Collapse the 11-line JSDoc to a 2-line note and drop the redundant call-site comment in hub-page. AST signature check confirms code is unchanged (comments only). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Codex Review: Didn't find any major issues. Delightful! 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". |
Problem
The Hub Discover and Recommended feeds call the Hugging Face JS client (
listModels/listDatasets) directly from the browser. That client throwswhen handed a non-empty token that isn't a well-formed HF token, instead of falling back to anonymous access. So a single bad value left in the HF token field — e.g. a placeholder like
hellotheresomeone typed once — takes down the entire discovery feed, surfacing as:This is confusing because the feed works perfectly fine with no token (anonymous public browsing). It only breaks when a malformed token is present. The failure is purely client-side, so nothing shows up in the server logs.
Fix
Add
hfApiToken()to the HF token store. It returns the token only when it looks like a realhf_...credential, andundefinedotherwise.hub-page.tsx's four HF call sites (model search, feed write-back, model selection, dataset search) now route through it.A malformed token therefore degrades to anonymous public browsing instead of erroring out. The raw token is still stored and shown unchanged in the settings field — this only sanitizes what gets handed to the HF client.
Testing
localStorage['unsloth_hf_token'] = 'hellothere', open/hub?tab=discover→ feed errors. With this change the feed loads anonymously.localStorage.setItem('unsloth_hf_token','')) and a validhf_...token both continue to work as before.🤖 Generated with Claude Code