← All posts

The 1,350-Character URLWhy We Stopped Trusting Android's DownloadManager

27th August, 2026

"Downloading models doesn't work (0 progress) … I even tried to route the app via VPN in another country."

GitHub issue #64 · OnePlus 11, Android 15 · 20 February

That was the first report. Off Grid runs AI models on your phone, so the very first thing anyone does is download one, and for this user nothing moved. A week later a Xiaomi on Android 16 said the same. Then a Samsung S24 Ultra. We had no logs, because the app collects no data. Our own reply on the issue says it best: "Flying in the blind here." This is the two-month story of that bug, told in order, including every fix that didn't work.

One download, two hops. Some phones never made the second hop.

Foundation : two things we didn't know

First, the URL is not the file. Ask Hugging Face for huggingface.co/<repo>/resolve/main/model.gguf and you get a 302 redirect to a CDN host, cas-bridge.xethub.hf.co, with a signed URL of about 1,350 characters. The signature proves you may read the file, and it expires.

GET  https://huggingface.co/…/resolve/main/model.gguf
HTTP/1.1 302 Found
Location: https://cas-bridge.xethub.hf.co/xet-bridge-us/…?<signature, expiry, credentials … ≈ 1,350 chars>

Second, there is no single DownloadManager. Android ships a system service with that name: hand it a URL and it downloads in the background, survives your app being killed and shows a notification. We used it from day one. But phone makers ship their own modified copy of Android, so "the" DownloadManager is really Samsung's, OnePlus's and Xiaomi's. Same API, different insides, and we could not see any of them.

So the reports said "0 bytes", our logs said nothing, and the component in the middle was a black box. What do you do?

5 March : the first fix that wasn't

Our first theory was the redirect. If some DownloadManagers can't follow it, we follow it ourselves: send a HEAD request, read the Location header, and hand DownloadManager the final CDN URL directly.

// DownloadManagerModule.kt (v0.0.66)
val resolvedUrl = resolveRedirects(url)
val request = DownloadManager.Request(Uri.parse(resolvedUrl))
...
internal fun resolveRedirects(originalUrl: String, maxRedirects: Int = 5): String {
    connection.instanceFollowRedirects = false
    connection.requestMethod = "HEAD"
    connection.connectTimeout = 10_000
    connection.readTimeout = 10_000

It shipped in v0.0.66 the same day. One tester replied "working fine now 👍". The original reporter replied the next morning: "Nope, the issue is still there in v0.0.66."

Worse, the pull request had reasoned that signed URLs "expire after 1 hour; since resolution happens immediately before enqueue(), this is not a concern." It was a concern. A big model can take longer than the signature lives, and when DownloadManager paused and retried, it retried the same stale URL, forever, in a loop that ended only in ERROR_FILE_ERROR. Our fix had created the next bug.

16–31 March : patching around a black box

Next we went after the other symptom: downloads that stopped in the background. The rest of March was a series of reasonable patches, each with a short life.

About two hours after the watchdog landed, we found it was killing downloads before their first byte. A slow CDN can take longer than 45 s to start sending. So the rule split in two:

One rule could not tell "slow to start" from "frozen".

The battery prompt went too, in the same commit: the foreground service already kept the process alive, and the prompt "added unnecessary friction on every download". Meanwhile the reports kept coming:

"I have tried the last version 0.0.81; the git version, the PlayStore version and the 0.0.66 version but neither of them can download any model. It just keep waiting at 0%."

GitHub issue #122 · Samsung S24 Ultra · 7 April

After 0.0.83 the same user wrote: "simply stuck there at 0% for the last 20 min. No error this time but no progression." The watchdog had turned an error into silence.

9 April : own the HTTP

On 11 April a contributor wrote the diagnosis on the issue: "the native http client used by some download managers, especially on samsung or redmagic devices, was cutting off or blocking huggingface's long signed urls." Whether it was the length, the redirect or a header, we never saw inside. But by then the answer didn't depend on it. We had been patching a component we couldn't read, on phones we didn't own.

The rewrite replaced the system downloader with two pieces we control. WorkManager schedules the job, keeps it alive across app kills and reboots, and waits for a network. OkHttp does the HTTP. State lives in a small Room database. It shipped in v0.0.88.

The key decision is one line. We store the stable /resolve/ URL, never the signed one. OkHttp follows the 302 on every attempt, so every attempt gets a freshly signed URL. The expiry bug from March doesn't get fixed. It can't happen.

// WorkerDownload.kt (v0.0.88)
val existingBytes = if (targetFile.exists()) targetFile.length() else 0L
val requestBuilder = Request.Builder().url(url)        // the stable /resolve/ URL
if (existingBytes > 0L) {
    requestBuilder.addHeader("Range", "bytes=$existingBytes-")
}

It also deleted a lot: a 500 ms polling handler, the watchdog timer and its thresholds. The worker's main function went from a cognitive complexity of 39 to about 12.

One honest detail: three days after the rewrite started, a fourth DownloadManager patch landed anyway. It re-enqueued downloads stuck in PAUSED_WAITING_TO_RETRY with a fresh URL after two watchdog cycles. Both shipped in the same release. And this was not our first rewrite attempt. Two earlier refactor branches had failed. One left two sources of truth running side by side. The other replaced the whole jobs object every second, so every screen re-rendered on every tick. The lesson we wrote down: both attempts "added new code without fully deleting the old code." This time we deleted it.

Date on top, the release that shipped it below.

"In the latest version the downloading problem is fixed for me."

GitHub issue #122 · 20 April, after v0.0.89

10–26 April : the trap was ours

With the black box gone, we made a mistake of our own. On a network error the worker returned Result.retry(), which sounds right. But WorkManager's retry has no cap: it backs off exponentially, up to 5 hours between attempts. So the "download failed" event never fired, and the progress bar sat frozen.

A retry with no limit is a hang with extra steps.

The fix in v0.0.94 was boring and correct: fail fast and show a Retry button.

// WorkerDownload.kt (v0.0.94)
-   downloadDao.updateStatus(downloadId, DownloadStatus.RETRYING)
-   return Result.retry()
+   return failDownload(downloadId, download, DownloadReason.fromThrowable(e))
    ...
-   !response.isSuccessful -> { if (code in 500..599 || code == 429) { … Result.retry() } }
+   !response.isSuccessful -> failDownload(downloadId, download, DownloadReason.fromHttpCode(code))

The foreground service had its own round trip. We deleted it on 21 April, 246 lines, to stop crashes that the code comments name as Android 12+'s ForegroundServiceStartNotAllowedException and Android 15's time budget for data-sync services. In July it came back, inside WorkManager this time, because a plain worker gets about a 10-minute window plus Doze throttling, and "a multi-GB model download stalled … once the app was backgrounded or the screen went off". Now the worker asks to run in the foreground, and if Android refuses, it carries on as a background worker instead of failing.

Resume : half done

That Range header is how a download resumes. The server's answer decides what happens next:

Tapping Retry re-uses the same download row and the same partial file, so it resumes. But starting the same model again from the model card creates a new download with a random file name, so it finds no partial and starts from zero. Users noticed:

"phone went to sleep. On wakeup it told me that the download dropped and I lost all download progress … Would be great if 'Retry' was called 'Resume'."

GitHub issue #320 · May

We are testing the fix now: name the partial file after the URL, so the same model always finds its own partial, and a new model version, with a new URL, never resumes into an old one. On one 652 MB file that failed at 600 MB, the old behaviour threw away all 600 MB.

What we are still figuring out

Not every failure was the URL. In June the very first reporter confirmed downloads now worked, then found one network where they still didn't: plain Wi-Fi failed, the same Wi-Fi through a VPN worked. Their guess: "it's gotta be DNS." Some phones still pause downloads mid-way on their own, and a few users report files that arrive corrupt. For those we check the size after every download, and compute a SHA-256 only when the size looks wrong, because hashing 4 GB on a phone takes 30 to 60 seconds we don't want to spend on every download.

What we took away