# Plan macOS Updates Around Hosted Agent Jobs

Canonical: https://figment.so/blog/mac-agent-update-maintenance

Drain the agent, save a checkpoint, run softwareupdate, verify with a smoke test, then resume or roll back by re-provisioning. For zero downtime, rent two Macs and update one at a time.

Apply a macOS update in five phases: drain the agent, save a checkpoint of tool versions and config, run `softwareupdate`, verify with a smoke test, then resume or roll back. A macOS update applied at the wrong moment ends in-flight jobs, changes tool versions and can break a dependency chain your automation has relied on for months. The answer is not to skip updates but to control when they happen and to have a tested rollback. A single long-running agent on a Figment Intel Mac VM ($25 a month) can follow this runbook, and a team that wants a rotation can rent two Macs.

## Which Figment plan fits my maintenance plan?

Pick the plan before you plan the window, because the update path is the same on every plan but the rollback and the downtime differ. You run `softwareupdate` yourself, over SSH or in a remote desktop terminal, with administrator access to your own Mac or VM.

| Situation | Plan | Price |
|---|---|---|
| One agent, Intel-compatible tools, and a window where a short outage is fine | [Intel Mac VM](/mac-hosting#intel-vm), macOS Sequoia | $25 a month, $2 a day |
| arm64-only tools, Xcode 26.4 or later (needs macOS Tahoe 26.2 or later), visionOS | [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) | $39 a month, $6 a day |
| Heavy jobs, or a Mac you update without any other customer on the same hardware | [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) | $349 a month ($299 on a 12-month term) |
| No downtime during updates | Two Macs of any plan above, updated one at a time | See the worksheet below |

The Intel VM runs macOS Sequoia. It runs Intel-compatible Xcode up to 26.3 and most CLI-driven agent work. Native Apple silicon execution, Xcode 26.4 or later, and visionOS need an Apple silicon plan ([Apple: porting your macOS apps to Apple silicon](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon)). Figment runs the Mac, network and virtualization layer. macOS updates, tool versions and agent state are yours.

## What do I need before I touch an update?

Prepare three things:

- **A known-good checkpoint:** installed tool versions, running services and agent config you can diff against after the update.
- **A drain signal:** a mechanism that tells the agent to finish the current job and not start another.
- **A rollback target:** a scripted re-provisioning path (a Brewfile and agent config in version control) plus a copy of the checkpoint outside the Mac. Do not rely on an in-place filesystem rollback.

Figment does not back up your Mac, and there is no pre-update snapshot you can restore on demand. Scripted re-provisioning is the rollback you control.

The simplest drain mechanism is a sentinel file the job wrapper checks at the top of each run:

```bash
#!/usr/bin/env bash
set -euo pipefail
DRAIN_FLAG="$HOME/agent/.drain"

if [[ -f "$DRAIN_FLAG" ]]; then
  echo "Drain flag set — agent will not start a new job" >&2
  exit 0
fi
# ... rest of job logic
```

Pair it with a launchd plist whose `KeepAlive` dictionary sets `SuccessfulExit` to `false`. launchd relaunches only on a non-zero exit, so a clean exit under drain stops the restart loop. See the `launchd.plist(5)` man page and Apple's [Creating Launchd Jobs](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html) for the plist schema.

## What are the phases of the maintenance runbook?

Work through five phases in order. Each has a pass check before you continue.

### Phase 1: Drain

1. `touch ~/agent/.drain`
2. Watch the current job finish: `tail -f /tmp/agentjob.log`.
3. Confirm launchd shows the job idle with `launchctl list | grep agentjob`. The PID column should be `-`.
4. Tell upstream schedulers and webhooks that the agent is offline for the window.

### Phase 2: Checkpoint

Record the environment so you know exactly what to restore:

```bash
#!/usr/bin/env bash
set -euo pipefail
OUT="$HOME/agent/checkpoint-$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$OUT"
sw_vers                        > "$OUT/os-version.txt"
xcode-select -p                > "$OUT/xcode-path.txt"   || true
brew list --versions           > "$OUT/brew-versions.txt"
brew bundle dump --file="$OUT/Brewfile" --force
launchctl list                 > "$OUT/launchctl-list.txt"
ln -sfn "$OUT" "$HOME/agent/checkpoint-latest"
echo "Checkpoint saved to $OUT"
```

Copy the checkpoint directory to storage outside the Mac (object storage, your own server, or a git repo you control) before you update. Do not put secret values in the checkpoint. Capture only names and versions.

### Phase 3: Update

Apply the update from an SSH or remote desktop terminal:

```bash
# List available updates
softwareupdate --list

# Install all recommended updates (patches only — no major macOS upgrade)
sudo softwareupdate --install --recommended --restart

# Or install one by exact label from --list
sudo softwareupdate --install "macOS Sequoia 15.x.x-..." --restart
```

`--recommended` applies security and reliability patches without a major macOS version jump. A major upgrade should be a deliberate decision and not a side effect, so confirm your toolchain supports the target macOS first. If your organization pushes updates through MDM, check Apple's current MDM deferral documentation before you rely on timing you tested on an earlier macOS.

### Phase 4: Post-update verification

After the Mac comes back, run a verification script before you remove the drain flag:

```bash
#!/usr/bin/env bash
set -euo pipefail

CP="$HOME/agent/checkpoint-latest"

echo "=== OS version ==="
sw_vers

echo "=== Brew bundle check ==="
brew bundle check --file="$CP/Brewfile" \
  || { echo "FAIL: missing Homebrew packages"; exit 1; }

echo "=== Agent smoke test ==="
# Use your real smoke test — do not count a failed build as a success.
shortcuts run "AgentSmokeTest" \
  || { echo "FAIL: smoke test"; exit 1; }

echo "All checks passed"
```

Apple documents the `shortcuts` command at [Run shortcuts from the command line](https://support.apple.com/guide/shortcuts-mac/run-shortcuts-from-the-command-line-apd455c82f02/mac). Replace `AgentSmokeTest` with a shortcut or script that exercises the same code paths as your production job, including any network call your agent depends on. If the script exits non-zero, keep the drain flag and move to rollback.

### Phase 5: Resume or roll back

**Resume:** `rm ~/agent/.drain`. The next launchd trigger starts the agent again.

**Roll back if verification fails:**

| Situation | Action |
|---|---|
| Brew packages broken | `brew bundle install --file="$HOME/agent/checkpoint-latest/Brewfile"` |
| Tool version regressed | Re-install via Brewfile or `brew install formula@version` |
| Core dependency broken by the OS change | Re-provision a fresh Mac and restore agent config from the checkpoint |
| Cannot restore in place | Rent a replacement Mac and replay the checkpoint |

## What does the whole runbook look like at a glance?

```
1. Drain       touch ~/agent/.drain
               wait for the running job to finish

2. Checkpoint  ./save-checkpoint.sh
               copy checkpoint dir off the host

3. Update      sudo softwareupdate --install --recommended --restart

4. Verify      ./verify-after-update.sh
               PASS -> remove drain flag
               FAIL -> rollback; keep drain flag set

5a. Resume     rm ~/agent/.drain
5b. Rollback   brew bundle install  |  re-provision + replay checkpoint
```

## What if something fails after the update?

Check these four cases:

- **Agent exits immediately after the drain flag is removed.** Run `tail -50 /tmp/agentjob.err`. A changed `PATH` or a missing CLI is the usual cause.
- **Brew formula on the wrong version.** Run `brew list --versions <formula>`, then `brew upgrade` or pin it with `brew pin`.
- **Shortcut fails after the OS update.** Relaunch the Shortcuts app with `open -a Shortcuts`, then retry.
- **launchd agent will not load.** Run `launchctl load ~/Library/LaunchAgents/com.yourteam.agentjob.plist` and check `log show --last 5m --predicate 'subsystem == "com.apple.launchd"'`.

## Is a second Mac worth it for zero-downtime updates?

It is worth it when an hour of agent downtime costs you more than the second Mac. A rotation means one Mac updates while the other keeps jobs moving. Suppose a single-node update takes about 90 minutes of agent downtime and you run four maintenance cycles a quarter. Two nodes remove roughly 4 × 90 = 360 minutes of job backlog a quarter.

The extra cost is a second plan. Two Intel VMs cost 2 × $25 = $50 a month, two Apple Silicon VMs cost 2 × $39 = $78 a month, and two Dedicated M4 Pro 48 GB Macs cost 2 × $349 = $698 a month. Prices are USD before tax. Whether that pays off depends on your job value per hour, so price it against your own backlog cost. A maintenance window does not pause billing. For several Macs under one agreement, Figment quotes on a call. See the [Mac hosting plans](/mac-hosting).

## How do I start?

Rent a Mac and run the Phase 2 checkpoint script before you touch an update, so your first rollback target exists on day one and not after the first incident.

**Related guides:**
- [Mac agent screenshot privacy](/blog/mac-agent-screenshot-privacy)
- [Mac agent browser profiles](/blog/mac-agent-browser-profiles)
- [Mac GitHub Actions self-hosted runner](/blog/mac-github-actions-self-hosted-runner)
