A photographer swipes the wedding app away mid-upload and reopens it next morning; what did the OS cancel, and how should the queue resume with expired upload URLs?
answer
- a user kill is not a system kill
- cancelled, and no relaunch for them
- reconcile disk with the server at launch
- an expired URL never heals on retry
- sign at hand-over, not at enqueue
basics
~20 sOn one platform a user force-quit cancels every transfer handed to the OS, and nothing relaunches the app for them. Next launch, the app reads its saved queue, gets fresh upload URLs, asks each upload's server offset and resumes.
solid answer
~50 sA swipe from the recent-apps screen is a user force-quit, not the system ending a suspended app. On one platform, a system termination leaves background transfers running and relaunches the app to collect them; a force-quit cancels them all, and nothing restarts until the user opens the app. On the other, a long user-started transfer job that the user stops from the system's task list ends at once and is not rescheduled. So the design never relies on what survived: the next launch reads the queue from disk, reattaches to any transfers the OS still reports, and treats other `uploading` entries as unknown. The pre-signed URLs expired overnight and would fail on every retry, so it asks the backend for fresh ones, queries each upload's offset and resumes; an upload the server already discarded starts again from zero.
go deeper
Recall that a user swiping the app away differs from the system closing it, and that an upload link which has expired never starts working again on retry.
Explain the next launch step by step: read the queue, reattach to surviving transfers, get fresh URLs, ask each upload's offset, resume from it.
Show the asymmetry between system termination and user force-quit, sign URLs at hand-over, keep URL expiry apart from upload expiry, and stop after one refused refresh.
Decide what the product promises for long uploads: a persistent progress notice, deferring originals to Wi-Fi and charging, or telling photographers not to swipe the app away.
## Two ways an app ends, and why they differ The photographer finishes the reception at midnight, sees a dozen apps in the recent-apps screen and swipes them all away — including the gallery app, which had handed three video clips to the OS's **background-transfer service**. That swipe is a **user force-quit**, and the platforms treat it differently from the system quietly ending a suspended app to reclaim memory. | What ended the app | Transfers already handed to the OS | Is the app started again for them? | |---|---|---| | The system, while the app was suspended (one platform) | keep running in a separate system process | yes — relaunched in the background, it must reattach to its transfer session | | A user force-quit from the recent-apps screen (same platform) | **all cancelled** | **no** — nothing restarts until the user opens the app | | The user stopping a long, user-started transfer job from the system's task list (the other platform) | the process ends at once, with no stop callback | **no** — the job is not rescheduled | | The system stopping that job (other platform): a lost network constraint, heat, or the process killed for memory | stopped | after a lost constraint or heat the system retries it later; in every case the app must restore its own state | The point to carry into the room: **a transfer handed to the OS outlives the app — unless the user kills it**, and what a plain swipe does on every device is not something a design should bet on. So the queue is written so that the next launch finds out what survived rather than assuming. ## The next morning's launch The photographer opens the app over breakfast. It: 1. **Reads the queue from disk** — 412 photos `committed`, 188 `waiting`, three clips `uploading`. 2. **Reattaches** to the OS's transfer session under the same identifier it always uses and asks which tasks are still alive. After a force-quit on the first platform, the answer is none. 3. **Treats every unmatched `uploading` entry as unknown** — neither failed nor done. 4. **Refreshes credentials.** Each clip's pre-signed upload URL was valid for, say, one hour (an assumption; the backend sets the real figure). They expired overnight. 5. **Asks the server for each upload's offset** with a fresh URL, then resumes from that byte. 6. **Rebuilds the progress it shows** from those answers. ## An expired URL is not a retryable failure A pre-signed URL carries its own expiry; once past it the storage service refuses the request — commonly with `403 Forbidden` — and refuses it identically on every retry. HTTP's own guidance for `403` is the rule: do not repeat the request with the same credentials; a request with new credentials may succeed. So: - **Never back off and retry a stale URL.** Backoff cures a flaky network, not an expired signature. - **Ask the app's backend for a fresh URL for the same upload**, then ask for the offset; the bytes already stored are not lost because the credential to reach them expired. - **Sign at hand-over, not at enqueue.** Files wait hours in this queue; a URL fetched when the photographer tapped *Upload* is often dead by the time its turn comes. Store when each URL expires and refresh any that is close, before handing the request to the OS — a request handed over is sent as it was signed, and on one platform the OS may hold a transfer for better conditions, such as Wi-Fi or a charger. - **Refresh once.** If a freshly signed URL is refused too, the cause is real — the photographer was removed from the gallery, or the couple closed it. Mark the entry `failed` with that reason. Keep two expiries apart. The **URL's** expiry is about authorization and is cured by re-signing. The **upload's own** lifetime — how long the server keeps a half-received file — is separate; if the server has discarded it (`404` or `410`), the client starts a new upload from zero. ## Progress the photographer can trust Before the swipe the screen said *Clip 2: 74 %*. After relaunch that number is a memory, not a fact. Show each clip as *Resuming…* until the server's offset arrives, then show the server's figure, which may be lower than 74 %. Never let a percentage climb from a stale counter and then jump backwards. Where a long transfer runs as a user-started job, the platform that requires a visible progress notification for it gives a natural place to say *uploading 3 clips*. ## What the app cannot do It cannot count on running any code when the user force-quits, so nothing can be saved at that moment. Every fact the next launch needs — the queue, each upload's address, the pinned file, the last offset — must already be on disk. That is the whole design: write state early, reconcile on launch, and treat a stale credential as a reason to re-sign rather than to retry.
- Why not fetch all 600 upload URLs when the photographer first queues the files?The files wait hours for their turn, longer than a short-lived URL stays valid, so most would be dead on use. Fetch each URL just before its file is handed to a transfer, store when it expires, and refresh any that is near expiry. Short lifetimes are the point of a pre-signed URL; the queue adapts to them rather than asking for longer ones.
- A freshly signed URL is refused as well; what should the queue do?Stop retrying that entry. One refusal with an expired URL is expected; a refusal with a brand-new one means authorization really failed — the photographer lost access, or the gallery was closed. Mark the entry `failed` with the server's reason and show it, so the photographer can act instead of watching a loop drain the battery.
- How does the relaunched app learn which transfers the OS is still running?On one platform it re-creates its background-transfer session under the same identifier, and the OS reattaches the tasks still running and delivers results for finished ones; tagging each task with the queue entry's id maps results back to rows. Where the transfer runs as a scheduled job, the system restarts the job and the app restores progress from its own queue. Any `uploading` entry with nothing live is checked against the server's offset.
- Transfers handed to the OS always finish, even after the user force-quits the app.
- A failed request with an expired pre-signed URL will succeed if retried with backoff.
- A user swipe-away and a system termination leave background transfers in the same state.
- A pre-signed URL fetched at enqueue stays valid however long the file waits.
- The percentage shown before a force-quit is still accurate after relaunch.