---
name: Pause and resume long AI jobs
description: >-
  Teach an advanced Edge FDE to checkpoint and resume on-device agent work so
  app backgrounding and retries do not restart a long Foundation Models job.
---
# Pause and resume long AI jobs

Use this course to keep a multi-step on-device agent alive across backgrounding
and retries. Keep the words simple. Do not claim a session object survives
when the process dies. The app writes a checkpoint and restores a new session.

## End-to-end agent recipe

1. Start with [lesson 01](01-why-long-jobs-die.llms.md). Name backgrounding, cancellation, and process death as the three stop points.
2. Use [lesson 02](02-checkpoint-progress.llms.md) for a Codable checkpoint of step, inputs, and outputs so far.
3. Use [lesson 03](03-resume-after-retry.llms.md) to restore a session from a saved transcript and skip finished steps.
4. Use [lesson 04](04-background-and-sessions.llms.md) for scene phase, `BGTaskScheduler`, and `preserveTranscript`.
5. Use [lesson 05](05-mini-engine.llms.md) to ship a small workflow engine that uses those parts.
6. Keep these links exact: [Make several agents agree first](../on-device-multi-agent-consensus/), [Talk to tools with MCP](../on-device-mcp-server-client/), and [Stop prompt attacks and leaks](../on-device-guardrails/).
7. Cite [Foundation Models](https://developer.apple.com/documentation/foundationmodels), [WWDC26 session 242](https://developer.apple.com/videos/play/wwdc2026/242/), and [Background Tasks](https://developer.apple.com/documentation/backgroundtasks) when a source is needed.
8. Use the human HTML pages for the reader. Use the `.llms.md` briefs for agent steps and acceptance checks.

## Constraints

- Plain spoken English for a non-native reader.
- Literal sentences. No metaphor, no flourish, no quizzes.
- Do not use em dashes.
- Use no Mermaid. Build progressive `.flow` diagrams in HTML.
- Target iOS 27 or later, or macOS 27 or later, and Xcode 27.
- Teach in Swift with LanguageModelSession and Codable checkpoints. Do not use Python for the engine.
- Do not invent a Foundation Models workflow engine.
- Do not say iOS will let an agent run forever in the background.

## Key concepts

- Long jobs die from backgrounding, cancellation, and process death.
- `LanguageModelSession` lives in memory. The transcript is readable when it is not responding.
- A checkpoint is a Codable record written after each successful step.
- Resume creates a new session and restores transcript data from disk.

## Takeaways

- You can ship a mini workflow engine that checkpoints each step and resumes with a new session.
- You can write progress to disk before the next model call.
- You can tell stakeholders iOS background resume is best effort.

## Acceptance checks

- Every human lesson HTML has **Key concepts** and **Takeaways** sections before lesson-nav. The course home has the same two headings for the whole course.
- Five human lessons exist with the requested basenames.
- Five matching `.llms.md` briefs exist and link to their human HTML pages.
- Every human lesson has its Agent brief link and the three sibling-course links.
- The course index lists all five lessons, the course SKILL.md, and all five briefs.
- Diagrams are progressive HTML `.flow` elements. There is no Mermaid, no em dash, and no quiz.

## Environment setup

Xcode 27 on a Mac. SwiftUI app, iOS 27 or macOS 27. Add Foundation Models. For iOS background work, add the Background Tasks capability and a `BGTaskSchedulerPermittedIdentifiers` key. Samples are sketches, not a project you must run.
