Skip to content

Detect Hugging Face hub cache from HF_HOME/HF_HUB_CACHE - #6

Merged
lucasnewman merged 2 commits into
Blaizzy:mainfrom
rcanand:fix/hf-home-hub-cache
Jul 21, 2026
Merged

Detect Hugging Face hub cache from HF_HOME/HF_HUB_CACHE#6
lucasnewman merged 2 commits into
Blaizzy:mainfrom
rcanand:fix/hf-home-hub-cache

Conversation

@rcanand

@rcanand rcanand commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #5

Summary

  • Resolve the default model search path like the huggingface_hub Python library: HF_HUB_CACHE$HF_HOME/hub~/.cache/huggingface/hub.
  • Existing installs that never customized the path have the legacy default persisted in Settings.plist; it is re-resolved against the environment on settings decode. Genuinely customized paths are always preserved.
  • macOS GUI apps can't see shell rc-file exports, so when the process environment doesn't configure the cache, the app probes the user's login + interactive shell once at startup (async, 3s timeout — the same approach VS Code and JetBrains IDEs use) and adopts its HF_HOME/HF_HUB_CACHE. Parsing is
    NUL-separated behind a marker segment, so noisy rc files (prompts, banners) can't corrupt values.
  • Downloads and the embedded server already flow from this setting, so no other call sites change; views re-scan reactively when the path changes.

Testing

  • Adds a hostless NativTests XCTest target (the repo had none): 21 tests covering path-resolution precedence, legacy-default migration, isConfigured, env-output parsing (marker, junk segments, values with =/newlines), and process execution (output capture, timeout, missing executable). xcodebuild -scheme Nativ -configuration Debug test — all pass.
  • Manually verified on a machine with HF_HOME only in ~/.zshrc, launching via open (i.e. launchd environment):
    • existing-user upgrade (persisted legacy default): Models view flips from ~/.cache/huggingface/hub contents to the HF_HOME cache within ~1–3s, and the migrated path persists across relaunches;
    • fresh install (no plist): same result;
    • terminal launch with HF_HOME exported: detected instantly, probe skipped.
  • Probe failures (missing shell, timeout, rc errors) degrade gracefully to current behavior.

Notes for reviewers

  • Run xcodegen generate after checkout to get the test target; the tracked Nativ.xcodeproj is intentionally unchanged to avoid xcodegen-version churn (CI regenerates it).

Note: this fix was generated by AI, verified by me.

rcanand added 2 commits July 20, 2026 17:26
The model search path defaulted to a hardcoded ~/.cache/huggingface/hub,
so models stored in a hub cache relocated via the standard Hugging Face
environment variables were never discovered.

Resolve the default the same way the huggingface_hub Python library does:
HF_HUB_CACHE first, then HF_HOME with /hub appended, then the per-user
fallback. Existing installations that never customized the path have the
legacy default persisted; re-resolve it against the environment on decode
so they pick up the configured location without manual intervention.

Adds a hostless NativTests target covering path resolution and the legacy
default migration. Regenerate Nativ.xcodeproj with xcodegen after checkout
to get the test target (the tracked project file is left untouched to
avoid xcodegen version churn).
GUI apps on macOS inherit launchd's environment, so HF_HOME exported from
shell startup files (.zshrc, .zprofile, ...) is invisible to the app and
the previous commit alone could not help GUI-launched installs.

When the process environment does not configure the hub cache, probe the
user's login + interactive shell once at startup (async, with a timeout),
the same approach VS Code and JetBrains IDEs use. NUL-separated env output
behind a marker segment keeps shell-startup noise out of the parsed
values. A discovered HF_HOME/HF_HUB_CACHE only migrates the legacy default
search path; user-customized paths are preserved. Views already re-scan
reactively when the search path changes.

Adds ShellEnvironment tests covering parsing (marker handling, junk
segments, values with '=' and newlines) and process execution (output
capture, timeout, missing executable), plus isConfigured tests.
@Blaizzy
Blaizzy requested a review from lucasnewman July 21, 2026 00:50
@Lazarus-931 Lazarus-931 added the bug Something isn't working label Jul 21, 2026

@lucasnewman lucasnewman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@lucasnewman
lucasnewman merged commit a04ba31 into Blaizzy:main Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Models in HF_HOME / HF_HUB_CACHE locations are not detected

3 participants