Repository navigation
iOS: a stopped model download resumes from NSURLSession's resume data (#127) - #132
Merged
Merged
Conversation
…#127) On iOS, expo-file-system resumes only from the base64 resume data NSURLSession produces on a pause, and .part does not exist until the file is complete, so every stopped download started again from zero. - download-resume.ts (pure, tested): which path each platform takes, the record kept next to .part, and when to fall back to a clean restart. - The download screen pauses the running download on iOS when the app goes to the background or the connection drops; the pause saves the resume data in <name>.part.resume, and the next attempt resumes from it. A missing, stale or rejected record means one clean restart. - partialModel and the model update read the saved bytes on iOS. - Android keeps its byte offset path. The SHA-256 check is unchanged. Signed-off-by: Daniel Bejarano <dbejarano820@gmail.com>
juancguerrerodev
marked this pull request as ready for review
November 27, 2026 19:44
juancguerrerodev
force-pushed
the
dbejarano820/127-ios-download-resume
branch
from
November 27, 2026 19:45
50fbb0d to
c8485fc
Compare
12 of 16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Closes #127
On iOS a stopped model download started again from zero: expo-file-system resumes only from the base64 resume data NSURLSession produces on a pause (it rejects Android's byte offset), and
.partdoes not exist on iOS until the file is complete. Now the download screen pauses the running download when the app goes to the background or the connection drops, the resume data is saved in<name>.part.resume, and the next attempt resumes from it. A missing, stale or rejected record means one clean restart. Android keeps its byte offset path, and the SHA-256 check on the finished file is unchanged.Vision fit
The model comes down once over HTTPS and is checked before use, so the phone can work offline. A download that keeps its place on a phone that drops Wi-Fi or leaves the app makes that first step work on iPhones, and keeps the screen's promise ("If it drops, it picks up where it stopped").
Non-negotiables
Checklist
acceptedproposal.pnpm check:privacy,pnpm typecheck,pnpm lint,pnpm testandnode scripts/guard/check.mjs --patterns scripts/guard/patterns.txt.packages/copy, in es-419 and en, with matching keys and placeholders, and no em or en dashes.How it works:
apps/mobile/src/download-resume.ts(pure,download-resume.test.ts):resumePlan()picks the path (Android: range from.part; iOS: the saved resume data, or straight to the check when the whole file is already in.part; otherwise clean),resumeRecordText()/readResumeRecord()write and check the record (URL, base64 resume data, bytes so far; a record for another URL, malformed, not base64, an unknown version or longer than the model is ignored),resumableBytes()is what the screen and the update read as kept, andpausesFor()says only iOS pauses, onbackground(notinactive) or when the connection drops.adapters/device.ts:phoneDownload()follows the plan. The record is used once and deleted before a resume; a resumed task that pauses again saves a fresh one. If NSURLSession rejects the resume data, the same call restarts clean from zero.pauseDownloadWhenLeaving()pauses the running task on iOS; it is a no-op on Android.app/download.tsxsubscribes to it while the screen is open. A pause lands as the existing interrupted state, and the existing return and reconnect handlers resume it.adapters/model-update.tsreads the iOS saved bytes fordownload_failedand recovery, and deletes the record with the staged file.Known limit: expo-file-system does not hand back resume data when a task fails (only when it is paused), so a failure the app did not pause for (for example a server error) still restarts from zero on iOS. Getting that data would need a Swift change to expo-file-system, which this pull request does not make.
Test-first:
download-resume.test.tswas run beforedownload-resume.tsexisted and failed withERR_MODULE_NOT_FOUND; with the module it passes, 9 of 9.Model path
packages/model,agent,skillsoreval, the prompt, the router, tool descriptions, normalizers, examples or the model file.Screenshots
No copy changed: the screen's lines about keeping progress are now true on iOS for the pauses above.
New dependencies and network calls
n/a. No new dependency. The download is still the one request to the pinned model host (huggingface.co), counted once per attempt through
countOutboundindownloadModel()as before; a resume continues that same download.AI agents