fix(config): restore huggingface env precedence#3329
Conversation
Keep the TUI Hugging Face API key lookup aligned with the shipped provider registry contract by checking HUGGINGFACE_API_KEY before HF_TOKEN explicitly in config.rs. This makes scripts/check-provider-registry.py pass again on main while preserving the existing runtime fallback behavior and the targeted Hugging Face config tests.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Code Review
This pull request refactors the Hugging Face API key environment variable resolution in crates/tui/src/config.rs. It replaces direct checks of HF_TOKEN with a call to provider_env_api_key, which has been updated to explicitly handle the precedence of HUGGINGFACE_API_KEY over HF_TOKEN while ensuring the values are non-empty. Additionally, some import statements have been sorted alphabetically. There are no review comments to address, and I have no further feedback to provide.
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.
CI Lint runs cargo fmt -- --check, and this change removes the remaining formatting drift (import ordering) so the lint job passes.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
This restores the Hugging Face API key env precedence on the TUI config surface so
scripts/check-provider-registry.py(theCI/Lintgate) passes again onmain.Background
crates/tui/src/config.rspreviously expressed the precedence through a helper (provider_env_api_key), but the registry lint script checks for the literalstd::env::var("HUGGINGFACE_API_KEY")/std::env::var("HF_TOKEN")strings in this file and fails when it cannot find them in the expected order.main.What changed
provider_env_api_key()now spells out the Hugging Face env order explicitly:HUGGINGFACE_API_KEYfirst, falling back toHF_TOKEN.HF_TOKENalone still works,HUGGINGFACE_API_KEYstill wins when both are set, empty values are ignored, and the rest of the providers continue to flow through the existing helper path.huggingface_hf_token_env_api_key_resolves,huggingface_short_env_fallbacks_configure_route,huggingface_env_overrides_key_base_url_and_model,huggingface_missing_key_error_mentions_env_fallbacks, etc.) still pass.Validation
python3 scripts/check-provider-registry.pynow reportsProvider registry drift check passed.cargo test -p codewhale-tui huggingface_is green (6 passed).Out of scope
tools::shelltests onwindows-latestfor feat(tui): preserve thinking/tool blocks when seeding thread from session #3300 are unrelated to this file and are tracked separately.