Skip to content

Studio: show HF token tick only after validation - #7268

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
Imagineer99:fix/hf-token-validation-tick
Jul 21, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
Imagineer99:fix/hf-token-validation-tick

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • show the green Hugging Face token indicator only after backend validation succeeds
  • hide the indicator while validation is pending, after validation failure, or while the field differs from the saved token
  • update the localized accessible label from "saved" to "validated"

Root cause

The indicator was driven only by whether the input matched the persisted token. That made malformed, expired, or revoked tokens look accepted even when token validation reported an error.

User impact

The success indicator now communicates confirmed validity instead of storage state.

Validation

  • npm run build
  • npm run typecheck
  • npm run i18n:check
  • npx eslint src/features/settings/tabs/general-tab.tsx src/i18n/locales/*.ts
  • uvx --from pytest pytest -q tests/studio/test_hf_token_validation_tick_contract.py tests/studio/test_settings_compact_overflow_contract.py (4 passed)
  • git diff --check
  • manually verified in Studio

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the Hugging Face token success indicator to only display once the token has been successfully validated, rather than just saved. It also updates the corresponding localization files and adds a contract test. The review feedback highlights a potential UX race condition where a stale validation state might briefly flash a success tick due to debouncing, and points out a PEP 8 formatting violation in the new test file.

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.

Comment on lines +229 to +232
const tokenIsCurrent =
draftToken.trim().length > 0 && draftToken.trim() === (hfToken ?? "");
const tokenValidation = useHfTokenValidation(hfToken ?? "");
const tokenValidated = tokenIsCurrent && tokenValidation.isValid === true;

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.

high

There is a potential UX race condition / stale state flash here. When hfToken is updated (e.g., on blur), tokenIsCurrent immediately becomes true. However, useHfTokenValidation debounces the token check by 500ms. During this 500ms window, the hook's internal debouncedToken is still the old token, and since completed.token matches debouncedToken, the hook returns isValid: true (the validation result of the old token). This causes tokenValidated to briefly evaluate to true, flashing the green success tick for up to 500ms before the debounce timer fires and resets the state to isChecking: true.

To fix this, useHfTokenValidation should be updated to compare completed.token against the raw (normalized) token instead of debouncedToken before returning the cached validation state. Since use-hf-token-validation.ts is not modified in this PR, please update that hook in a separate change or include it here to ensure the success tick doesn't flash stale states.

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.

This is exactly what the PR fixes. The hook now compares completed.token against normalizedToken (line 104) and guards on normalizedToken (line 103), so a just-edited token drops into the isChecking branch and the previous valid result is never returned. The tick can no longer flash, so no further change to the hook is needed.



def test_success_tick_requires_the_current_token_to_be_validated():
source = GENERAL_TAB.read_text(encoding = "utf-8")

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.

medium

According to PEP 8, spaces should not be used around the = sign when used to indicate a keyword argument.

Suggested change
source = GENERAL_TAB.read_text(encoding = "utf-8")
source = GENERAL_TAB.read_text(encoding="utf-8")
References
  1. PEP 8: Don't use spaces around the = sign when used to indicate a keyword argument, or when used to indicate a default value for an unannotated function parameter. (link)

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.

This repo intentionally keeps spaces around = for keyword arguments. scripts/enforce_kwargs_spacing.py enforces it as a pre-commit hook and E251 is not in the ruff select set, so the existing tests already use encoding = "utf-8" throughout. Switching to encoding="utf-8" would be reverted by the formatter, so leaving it as is.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 9d278f6a5c

ℹ️ 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
danielhanchen marked this pull request as ready for review July 21, 2026 10:53
@danielhanchen
danielhanchen merged commit 77da6e8 into unslothai:main Jul 21, 2026
37 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants