When the OS revokes your GPU: background execution in a Core ML pipeline on iOS 26

The problem
We run a multi-stage machine-learning pipeline on device, over full-length 4K/60 fps clips — minutes of sustained GPU work per clip. The biggest threat to that work is not the algorithm. It is the app going to the background.
On iOS, once you are backgrounded the GPU is no longer yours. In-flight Core ML requests start failing, and if you keep pushing, the system tears you down.
The part that surprised us: when it happens, Core ML does not hand you a typed error. There is no .gpuUnavailable case to switch on. You get a generic error, and the only way to know the GPU was pulled out from under you is to read its description string. That single fact dictated the whole design.
When we started, we targeted iOS 26 only, for one specific reason. Apple had just announced BGContinuedProcessingTask — a background task that starts in the foreground and keeps running once the app is backgrounded — with an option to keep using the GPU for exactly the kind of work we do: "Core ML processing or sensor data analysis." The documentation listed iPhone among the devices this applied to. On paper it was precisely our use case, so we committed the pipeline to it.
Our approach
The API shape is clean. You mark the request as needing the GPU, add the com.apple.developer.background-tasks.continued-processing.gpu entitlement, and submit:
let request = BGContinuedProcessingTaskRequest(identifier: id, title: ..., subtitle: ...)
request.requiredResources = .gpu // background GPU, on supported devices
Then we ran it on the device our users actually record on — an iPhone 17 Pro — and the promise did not hold. The continued task did not give us a usable GPU in the background. The moment we lost the foreground, Core ML lost the GPU, exactly as it had before the API existed. Background GPU turned out to be a capability that was not there on the phone, whatever the API surface suggested.
The clean way to ask the system is BGTaskScheduler.supportedResources, and on our iPhone 17 Pro it did not list .gpu. The lesson is to check it on real hardware before building on it, because "the API compiles" and "this device honours it" are different claims.
A CPU-only continued task does run on iPhone. But a CPU fallback for a pipeline tuned for the Neural Engine and GPU is not a fallback, it is a different and far slower product. We had already seen how much slower: when Core ML once fell back to the CPU for our keypoint model, a frame took 9.48 s instead of 0.04 s on the Neural Engine. So we stopped trying to keep computing in the background, and made stopping cheap and resuming correct the design centre instead.
The hard decisions and trade-offs
Detecting the revocation with no typed error to catch. When the OS pulls GPU access mid-inference, Vision and Core ML do not throw anything you can pattern-match on. You get a generic error whose description string contains the real reason. The only reliable signal we found is a substring:
} catch {
// If Core ML failed because the OS revoked GPU access during execution,
// treat it as a clean stop rather than a hard failure.
if Task.isCancelled { throw CancellationError() }
let errorString = String(describing: error)
if errorString.contains("BackgroundExecutionNotPermitted") ||
errorString.contains("Insufficient Permission") {
logger.warning("OS revoked GPU access safely. Aborting frame.")
throw CancellationError()
}
logger.error("Keypoint ML request failed. Reason: \(error)")
throw AnalysisError.keypointMLRequestFailed
}
Matching on a framework's internal wording is exactly the kind of thing that breaks on an OS update. We took it anyway, because there is no alternative — but we quarantine it in a single seam, log it loudly, and keep it out of business logic entirely.
The important move is semantic, not technical. A revoked GPU is not a failure, it is a pause. We translate it into a CancellationError, which the pipeline already understands as "stop cleanly and checkpoint", so a genuine ML fault and a backgrounding-induced abort take completely different paths from that point on.
Pausing before the GPU gets yanked, not after. Catching the revocation mid-frame is the safety net, not the plan. A lifecycle observer turns app-state and thermal notifications into explicit pause reasons:
group.addTask {
for await _ in notificationCenter.notifications(named: UIApplication.didEnterBackgroundNotification) {
await self?.pauseAnalysis(reason: .backgrounded)
}
}
// …plus willEnterForeground → resume, and thermalStateDidChange → pause/resume.
Backgrounding pauses immediately and checkpoints; returning to the foreground resumes. Overheating pauses too, because a throttled GPU would crawl, and auto-resumes once the device cools. Even the first frame is guarded: if the app is already backgrounded or already hot when analysis starts, we pause up front instead of firing a request that is guaranteed to be revoked.
Cleanup that cannot itself be cancelled. When we stop, we still need to talk to the backend — reset state, post results — and those calls must not be killed by the same cancellation that stopped the pipeline. The teardown runs inside a cancellation shield:
try await shieldedFromCancellation { [self] in
try await handleRecordingCleanup(recordingId: ..., reason: reason, currentStage: ...)
}
Without it, "app backgrounded" cancels the very work that records where we paused, and we lose the checkpoint we just decided to rely on. The bug that teaches you this is not obvious from a stack trace: everything looks like it shut down cleanly, and the next launch simply starts from the beginning.
The outcome
- Before this work, backgrounding was fatal. The moment the app left the foreground, the run died — every time. In practice a long analysis could not be reliably finished at all.
- After it, there are no background-related failures. The app can go to the background and the analysis picks up from the frame where it stopped on return.
- GPU-revocation errors are caught and reclassified as pauses in exactly one place. Genuine ML faults still surface as real errors.
- We shipped without background GPU at all, because the resume cost is small enough — around 20 re-processed frames per stage — that pausing on background is invisible in practice.
| Situation | Before | After |
|---|---|---|
| App backgrounded mid-run | Job fails | Pause + checkpoint, resume on return |
| GPU revoked mid-frame | Hard error | Reclassified as a clean pause |
| Device overheats | Throttled or dropped work | Auto-pause, auto-resume on cooldown |
Stack & takeaways
Stack: iOS 26, BackgroundTasks (BGContinuedProcessingTask, BGTaskScheduler.supportedResources), Core ML and Vision, Swift 6 concurrency (actors, structured task groups, cooperative cancellation), ProcessInfo thermal state, UIApplication lifecycle notifications.
- A shipped API is not a shipped capability.
BGContinuedProcessingTaskwith.gpucompiles and runs on iOS 26, but a usable background GPU never materialised on the iPhone we ship on. Verify on real hardware. - Model "resource revoked" as a state transition, not an exception. Treating a yanked GPU as a pause rather than a crash changed the architecture, and cleanly separated the failure path from the interruption path.
- When a framework will not give you a typed error, quarantine the guesswork. One seam, matched on the description string, logged loudly, converted into a first-class cancellation. Fragile code you cannot avoid should at least be contained.
- Get ahead of the platform. Pausing proactively on the background or thermal notification beats catching the revocation mid-flight. The catch is the safety net, not the strategy.
- Shield your teardown from the cancellation that triggered it. The work that records where you stopped has to outlive the stop.
Related: Resumable ML analysis of 4K/60 video covers the checkpoint-and-resume machinery this post relies on.

