Skip to content

fix(gemma): switch to Unsloth mirror — Google's official GGUF returns HTTP 401 to anonymous fetches#107

Draft
NITISH-R-G wants to merge 2 commits into
mainfrom
cursor/gemma-unsloth-mirror-1d83
Draft

fix(gemma): switch to Unsloth mirror — Google's official GGUF returns HTTP 401 to anonymous fetches#107
NITISH-R-G wants to merge 2 commits into
mainfrom
cursor/gemma-unsloth-mirror-1d83

Conversation

@NITISH-R-G
Copy link
Copy Markdown
Owner

@NITISH-R-G NITISH-R-G commented May 16, 2026

Summary

Fixes Gemma 4 download failures and duplicate GPS/AI/Sync chips on the Safety Tools tab.

Gemma download (Connection closed while receiving data)

Large GGUF pulls redirect through Hugging Face’s Xet CDN; Wi-Fi drops mid-stream used to surface a wall of signed URL text and never retry.

  • 5 resume attempts per mirror with exponential backoff and HTTP Range resume on the partial .download file.
  • Fail over across Unsloth → ggml-org → bartowski on transient/stream errors (not only HTTP 401).
  • Tap the yellow banner to retry immediately; Wi-Fi reconnect also retries after failed.
  • Short UI errors — no multi-line signed URLs in the banner.

Duplicate status chips

StatusIndicatorBar was rendered in both the app bar and Safety Tools list (below the mesh radar), so GPS / AI / Sync appeared twice. Removed the copy inside the tab; the app bar row remains.

Verify

  1. Install APK from this branch (or merge + CI artifact).
  2. Safety Tools → one row of GPS / AI / Sync at the top only.
  3. If download pauses, tap banner → should resume from saved MB count.
Open in Web Open in Cursor 

… HTTP 401

Honest correction. My earlier 'Gemma 4 is ungated' claim was based on a
stale web-search hit that reported gated=false. Re-tested with curl:

  GET https://huggingface.co/google/gemma-4-E4B-it-GGUF/resolve/main/
      gemma-4-e4b-it-Q4_K_M.gguf
  -> HTTP/2 401 'Invalid username or password.'

Google's official repo still requires HF login + terms acceptance even
though the weights themselves are Apache 2.0. Anonymous downloads are
rejected at the resolve endpoint. Users were correctly seeing:

  'Gemma 4 download paused — Hugging Face refused the request (HTTP 401)'

Fix: redirect downloads to the community mirrors which DO allow
anonymous fetches (verified 302 -> CDN on a clean curl):

  primary  : https://huggingface.co/unsloth/gemma-4-E4B-it-GGUF
  fallback : https://huggingface.co/ggml-org/gemma-4-E4B-it-GGUF
  fallback : https://huggingface.co/bartowski/google_gemma-4-E4B-it-GGUF

These hold the IDENTICAL model bytes under the same Apache 2.0 license.
Unsloth is the most-downloaded Gemma GGUF publisher; ggml-org is the
llama.cpp upstream community; bartowski is a long-running, trusted
quant-pack maintainer.

* lib/services/gemma_model_manager.dart
  - modelDownloadUrl points at Unsloth (anonymous fetch ok).
  - New modelDownloadFallbackUrls const w/ ggml-org + bartowski.
  - downloadModel() now iterates over [primary, ...fallbacks] and
    fails over on 401/403/404/429. Other HTTP errors bubble immediately
    so the caller sees a clean message.
  - Refactored the actual byte-streaming into _downloadFromUrl() so
    each candidate URL gets the full resumable-with-Range treatment.
  - Error copy no longer claims the model is 'Apache 2.0 + ungated' —
    it correctly explains the mirror failed + the next will be tried.
  - hfModelCardUrl points at the Unsloth model card (matches the URL
    we actually download from, so 'View model card' opens cleanly).

Verification:
  ✅ curl -sI https://huggingface.co/unsloth/gemma-4-E4B-it-GGUF/
       resolve/main/gemma-4-E4B-it-Q4_K_M.gguf
     -> HTTP/2 302 -> Location: cas-bridge.xethub.hf.co/...
        (anonymous fetch succeeds, redirects to CDN).
  ✅ flutter analyze -> 0 issues across the workspace.
  ✅ flutter test    -> 17/17 passing.
  ✅ flutter build apk --debug -> 254 MB APK produced in 13 s.

Co-authored-by: Nitish R.G. <NITISH-R-G@users.noreply.github.com>
- Retry transient ClientException/connection-closed up to 5x per mirror
  with Range resume, then fail over across Unsloth/ggml-org/bartowski.
- User-facing errors strip long signed CDN URLs from the banner.
- Tap Gemma banner to retry; auto-retry on Wi-Fi after failed state.
- Remove duplicate StatusIndicatorBar from Safety Tools tab (kept in app bar).

Co-authored-by: Nitish R.G. <NITISH-R-G@users.noreply.github.com>
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