---
title: "Background the job without losing it"
lesson_id: "04"
---

# Background the job without losing it

- **Lesson ID:** 04
- **Goal:** Save on scene leave. Explain BGProcessingTask as best effort. Name preserveTranscript.
- **Human lesson:** [04-background-and-sessions.html](04-background-and-sessions.html)

## Prerequisites

Lesson 03.

## Inputs, outputs, and artifacts

- **Inputs:** scenePhase and a long respond call.
- **Outputs:** A persisted checkpoint when the user leaves.
- **Artifacts:** Scene-phase and BGTaskScheduler sketches.

## Agent build steps

1. Save when scenePhase is not active.
2. Cite preserveTranscript and revertTranscript from [WWDC26 session 242](https://developer.apple.com/videos/play/wwdc2026/242/).
3. Say iOS may skip a background task.
4. Link [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/).

## Constraints

iOS 27 or later, or macOS 27 or later, and Xcode 27. Plain spoken English. No metaphor, quizzes, Mermaid, or em dashes. LanguageModelSession does not survive process death. Persist a checkpoint and the transcript yourself. Confirm transcript mutability and BGTaskScheduler names in the installed docs.

## Key concepts

- On leave foreground, cancel a long respond if needed, then save the checkpoint.
- `preserveTranscript` keeps partial work. You must repair the transcript yourself.
- Register a background processing task if you want a chance to continue.
- iOS background resume is a chance, not a promise.

## Takeaways

- Save on the way out.
- Use `preserveTranscript` only if you will repair the transcript.
- Do not save a half sentence as a finished plan.

## Acceptance checks

- Background resume is not promised.
- preserveTranscript is named.
- Sibling links, progressive .flow diagrams, and the Agent brief link are present.
- [ ] Proceed to [lesson brief](05-mini-engine.llms.md).
