Disclosure: This operations guide documents verified macOS launchd, caffeinate, and M4 Mac mini (16GB) resource patterns. See our Japanese Home or Privacy & Disclosure Policy for details.

Running a Home M4 Mac mini 24/7 for Local LLMs and Scheduled Agents

Key Takeaways
  • Idle sleep is the #1 silent killer of overnight home-server runs: wrap always-on inference with caffeinate -s and scheduled batches with caffeinate -i.
  • On a 16GB machine serving a single slot (-np 1 on 127.0.0.1:8080), stagger launchd schedules (for instance 06:30, 08:10, 12:10, 20:10) so jobs never contend for the same memory window.
  • Add --no-webui --no-slots --cache-ram 0 to hold Dirty Malloc heap at 236 MB (-90.1%), monitor logs/SQLite WAL growth, and keep public webhooks on a lightweight VPS due to FileVault reboot locks.

1. Keeping macOS Awake Safely

A consumer Mac mini is quiet and low-power, but left at defaults it sleeps aggressively when no display session is active. Scoped assertions via caffeinate prevent unexpected midnight stalls without turning off power management globally:

# Inspect current power settings and active sleep assertions
pmset -g

# Keep system awake while serving local LLM over AC power
caffeinate -s llama-server -m ./model.gguf --host 127.0.0.1 --port 8080 -np 1 --no-webui --no-slots --cache-ram 0

# Prevent idle sleep only during scheduled batch execution
caffeinate -i /path/to/.venv/bin/python -m my_worker.cli

2. Supervising & Scheduling with launchd

Because cron skips jobs missed during sleep, macOS automation belongs in ~/Library/LaunchAgents/*.plist. Use KeepAlive for the local LLM server bound strictly to 127.0.0.1:8080 with -np 1, and use StartCalendarInterval for daily agents:

<!-- ~/Library/LaunchAgents/com.example.localbatch.plist -->
<dict>
  <key>Label</key><string>com.example.localbatch</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/bin/caffeinate</string>
    <string>-i</string>
    <string>/path/to/.venv/bin/python</string>
    <string>-m</string>
    <string>my_worker.cli</string>
  </array>
  <key>StartCalendarInterval</key>
  <dict>
    <key>Hour</key><integer>6</integer>
    <key>Minute</key><integer>30</integer>
  </dict>
  <key>StandardOutPath</key><string>/path/to/logs/daily.out.log</string>
  <key>StandardErrorPath</key><string>/path/to/logs/daily.err.log</string>
</dict>
Example Slot (Local Time) Role Why Non-Overlapping Matters
06:30 Morning collection & local extraction Completes local 127.0.0.1:8080 inference well before 08:00 workflows
08:10 / 12:10 Separated drafting / digest runs Eliminates -np 1 queue contention and socket timeouts
20:10 Evening summary & cleanup Keeps residential hardware ready for overnight long-running jobs

3. Long-Run Memory & Log Hygiene

Over weeks of uptime, small leaks compound. Disabling default RAM buffers via --no-webui --no-slots --cache-ram 0 reduced Dirty Malloc Large heap from 2,374 MB to 236 MB (-90.1%) on our 16GB M4 Mac mini. Equally important, rotate StandardOutPath / StandardErrorPath log files regularly and checkpoint SQLite WAL journals so uncollected logs never crowd out macOS swap headroom.

4. Physical & Reboot Tradeoffs (FileVault, Power & VPS Split)

Three Homelab Realities to Accept Upfront
  • FileVault reboot locks: After an OS update or power cut, FileVault waits at the pre-login unlock prompt; user LaunchAgents stay paused until manual sign-in.
  • Keep public surfaces off your home IP: Host public mirrors, webhooks, and always-reachable APIs on a lightweight datacenter VPS and keep the Mac mini as a private processing engine.
  • Surge protection, watt meter & UPS: Power disturbances trigger the very reboots that trigger FileVault locks. Protect external APFS drives and active writes with surge protection or a compact UPS.

5. Frequently Asked Questions (FAQ)

Why use caffeinate instead of disabling sleep globally in Energy settings?

caffeinate scopes power assertions to the specific processes you wrap—caffeinate -s for always-on servers on AC power and caffeinate -i for finite batch jobs—so the Mac can still sleep when critical work is absent. You can confirm active assertions with pmset -g.

Why choose launchd StartCalendarInterval over cron on macOS?

Traditional cron skips jobs scheduled while the machine was asleep. Apple launchd StartCalendarInterval runs missed jobs after wake and keeps PATH, working directory, and StandardOutPath/StandardErrorPath cleanly explicit inside a plist.

Why stagger batch schedules when sharing one 16GB M4 Mac mini?

Running llama-server with -np 1 exposes a single parallel inference slot on 127.0.0.1:8080 to prevent memory blowups. Spacing jobs (e.g., 06:30, 08:10, 12:10, 20:10) avoids port 8080 contention and cascade timeouts.

Does disabling --no-webui, --no-slots, and --cache-ram 0 change output quality?

No. In our M4 Mac mini (16GB) verification, removing web UI/slot buffers and disabling the default RAM cache cut Dirty Malloc Large heap from 2,374 MB to 236 MB (-90.1%) while keeping deterministic structured JSON parity at 1.0.

What happens after a power outage or macOS update reboot?

If FileVault disk encryption is enabled, macOS pauses at the unlock screen and user LaunchAgents will not start until someone logs in. Plan around that reality by isolating public webhooks and mirrors onto a lightweight VPS.