Skip to content

Fix HF cache permissions and add startup fallback#677

Open
enveryasar wants to merge 1 commit into
jamiepine:mainfrom
enveryasar:fix/hf-cache-permission
Open

Fix HF cache permissions and add startup fallback#677
enveryasar wants to merge 1 commit into
jamiepine:mainfrom
enveryasar:fix/hf-cache-permission

Conversation

@enveryasar

@enveryasar enveryasar commented May 18, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Chores
    • Improved Hugging Face model cache initialization with automatic directory setup during startup
    • Added graceful fallback handling if cache directory creation fails
    • Updated container environment configuration for cache directory paths

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b08a9e3-0ea5-4c25-a5a1-35053e64381b

📥 Commits

Reviewing files that changed from the base of the PR and between b35b909 and 59a1ed7.

📒 Files selected for processing (2)
  • backend/app.py
  • docker-compose.yml

📝 Walkthrough

Walkthrough

Backend startup now sets a Hugging Face hub cache fallback directory under the app's configured cache path when HF_HUB_CACHE is not already set, creating it with graceful error handling. Docker Compose configuration is updated to expose this environment variable and removes the corresponding named volume.

Changes

Hugging Face Hub Cache Setup

Layer / File(s) Summary
Backend HF cache environment and directory setup
backend/app.py
Startup computes and sets HF_HUB_CACHE fallback directory under the app's configured cache directory, then creates the directory with graceful error handling that logs a warning without aborting startup if directory creation fails.
Docker Compose HF cache environment configuration
docker-compose.yml
Environment variable HF_HUB_CACHE is set in the voicebox service to point to the cache directory under /app/data, and the previously used huggingface-cache named volume is removed from the compose volumes definition.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A cache directory now has its home,
No volumes needed, just paths to roam,
Environment variables light the way,
Hugging Face models can stay and play!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: fixing HF cache permissions and adding a startup fallback directory creation mechanism in both backend/app.py and docker-compose.yml.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

KurzonDax pushed a commit to KurzonDax/voicebox that referenced this pull request Jun 27, 2026
Cherry-picked from upstream PRs:
- jamiepine#629: Refinement language preservation (captures.py + refinement.py)
  Non-English transcripts were being translated to English during
  refinement. Adds language-lock header + 'Do not translate' instruction
  + Chinese few-shot example.
- jamiepine#681: Apple Silicon MLX setup (justfile)
  Adds --no-deps install of mlx-lm==0.31.1 mlx-audio==0.4.1 to fix
  broken fresh installs (transformers version conflict).
- jamiepine#788: Kokoro male Mandarin voices (kokoro_backend.py)
  Adds 4 missing male Mandarin Chinese voices: zm_yunjian, zm_yunxi,
  zm_yunxia, zm_yunyang.
- jamiepine#667: SQLite WAL mode + busy timeout (session.py)
  Fixes 'database is locked' errors under concurrent load.
  PRAGMA journal_mode=WAL, busy_timeout=5000.
- jamiepine#539: Intel XPU IPEX optional (app.py + base.py + health.py)
  Makes IPEX import optional (try/except). Fixes Intel Arc/XPU support
  without requiring IPEX. (Task spec said jamiepine#538, actual PR is jamiepine#539.)
- jamiepine#621: Model cache validation (pytorch_backend.py + numpy compat)
  Checks for config files (not just weight files). Fixes partial cache
  detection crashes. Refactors pyi_rth_numpy_compat into testable
  _install_torch_numpy_fallback function with regression tests.
- jamiepine#677: HF cache permissions + startup fallback (app.py + docker-compose.yml)
  Sets HF_HUB_CACHE env var with fallback. Fixes container permission
  issues.
KurzonDax pushed a commit to KurzonDax/voicebox that referenced this pull request Jun 27, 2026
…ical fixes plus cache-validation test coverage (IPEX optional, MLX setup, SQLite WAL, refinement language preservation, Kokoro male Mandarin, HF cache permissions, model cache validation, pyi_rth refactor)

Cherry-picks (with IPEX jamiepine#538/jamiepine#539 ordering verified by content):
- PR jamiepine#629 — Refinement language preservation (zh/fr/ja/ru lock + few-shot demo)
- PR jamiepine#681 — Apple Silicon MLX setup (justfile --no-deps mlx-lm/mlx-audio pins)
- PR jamiepine#788 — Kokoro male Mandarin voices (4 zm_ voices)
- PR jamiepine#667 — SQLite WAL journal mode + 5s busy_timeout via SQLAlchemy creator lambda
- PR jamiepine#538 — Intel XPU IPEX optional (native torch.xpu first, IPEX optional)
- PR jamiepine#621 — Model cache validation (require config/preprocessor/tokenizer files in Whisper snapshots)
- PR jamiepine#677 — HF cache permissions (HF_HUB_CACHE under /app/data for non-root containers)
- PR (refactor) — pyi_rth_numpy_compat: extract _install_torch_numpy_fallback to a testable module-level function (3 new tests)

Zeph added 3 regression tests in test_pytorch_cache_validation.py to cover the partial-cache guard in PyTorchSTTBackend._is_model_cached (no other workers covered the missing-preprocessor_config case).

Test results on merged main: 95 passed / 1 pre-existing failure (test_hf_progress_tracker — unrelated, fails on both sides of the merge).

Review checklist:
[x] IPEX fix verified — try/except inversion matches jamiepine#538 content (try IPEX, fall back to native torch.xpu)
[x] Each cherry-pick matches its upstream diff
[x] No secrets, no merge markers, no debug leftovers
[x] SQLite WAL uses SQLAlchemy creator= lambda (correct pattern)
[x] justfile MLX pins mlx-lm==0.31.1 / mlx-audio==0.4.1 (matches release.yml)
[x] Tests run from branch and merged tree — no regressions
[x] Lint: no new ruff errors introduced vs main baseline (993 vs 1008 — actually 15 fewer)
@Xarianne Xarianne mentioned this pull request Jul 8, 2026
@Xarianne

Xarianne commented Jul 8, 2026

Copy link
Copy Markdown

I hit the same issue and suggested a fix in PR #584chown the data and cache directories in the entrypoint before the gosu privilege drop.

The issue with this PR's approach is that moving the cache to /app/data doesn't actually fix the root-ownership problem — /app/data is a named volume that's also mounted as root:root on first use, which is the same thing causing the SQLite attempt to write a readonly database error. The fallback in app.py would hit the same permission denied when trying to create /app/data/cache/huggingface/hub.

Fixing the ownership in the entrypoint before the privilege drop would resolve both the cache permission issue and the SQLite readonly error without needing the application-level fallback or moving the cache location.

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