Three different sleeps, often confused for one
macOS has separate timers for the display and for the system, and a third path for the lid. You can see the first two on your own Mac right now:
pmset -g customprints your current settings, anddisplaysleepandsleepare two independent lines — separate timers, separate values, one block for Battery Power and one for AC Power. Both are in minutes;0means never.
Display sleep turns the panels off. Nothing else changes: your agent keeps running, downloads keep going, the shell command it launched keeps writing output. Nothing about a dark screen stops work.
System (idle) sleep is the one that hurts. macOS suspends the machine, and every process is frozen where it stood — not killed. That's why it looks so confusing afterwards: the process is still there, the terminal still has your prompt, and the last thing the agent printed is from twenty minutes ago. macOS decides this from your idle time — how long since real keyboard or mouse input — and from the sleep assertions running processes hold. CPU load is not part of it: a Mac at 100% CPU still idle-sleeps on schedule, which is why an agent burning a core all night doesn't save itself.
Closing the lid is not a timer. macOS doesn't consult the idle settings there; it just sleeps. This catches people who set every timer to never and still lose runs. The supported way to keep a MacBook running with the lid shut is clamshell mode — on power, with an external display and an external keyboard or mouse connected. Assume otherwise that the lid is a hard stop.
One footnote that explains why some overnight runs survive without anyone arranging it:
ttyskeepawake is on by default, and man pmset describes it as preventing
idle system sleep while any tty — a terminal or remote login session — is active, where a tty counts
as inactive only once its idle time passes the sleep timer. So a CLI agent printing output into
Terminal can hold the machine up on its own. It's a nice accident, not something to depend on: a
quiet or detached session doesn't count, and it isn't attributed in either command below.