Sixty-four gigabytes of memory sounds like enough for anything. Ten cores sounds like a small server. So when we decided to turn a MacBook Pro into an all-night build farm for an AI coding agent, we expected to wake up to green ticks.
Several mornings in a row, we woke up to roaring fans, a terminal full of Docker errors, and an agent that had politely stopped hours earlier because nothing would answer it anymore. This is the story of five ways the laptop fell over, the afternoon we stopped guessing and measured, and the fix, which turned out to be giving everything less.
The dream
The product was a booking app for community sports halls; we will call it Lantern. The stack is ordinary for 2026: a Rust API, a Next.js front end, Postgres, a background worker, and a lot of tests.
Layer | What it checks |
|---|---|
Unit tests | Rust and TypeScript logic, in isolation |
Integration tests | The API against a real Postgres in Docker |
Browser tests | About 2,600 Playwright tests: seven devices (two phones, three tablets, two laptops), three languages, dark mode, visual comparisons |
Performance | A Lighthouse run at the very end |
The builder was an AI coding agent working through the plan one small slice at a time, and the machine was an M1 Max with 10 cores and 64 GB of memory. The plan fitted in one breath:
The agent builds all night. Every slice runs the full suite. CI runs on the same Mac, in a small VM, so we never pay for build minutes. We wake up to green ticks.
Act one: Docker stops answering
Somewhere near the end of the browser suite, Docker Desktop would simply stop. Every command came back with Error: Bad response from Docker engine, and docker ps, docker info and even quitting Docker Desktop all hung. The only way out was the blunt one:
# Force-quit Docker Desktop, start it again, and wait until the engine answers
pkill -f "Docker Desktop"; pkill -f com.docker
open -a Docker
until docker info >/dev/null 2>&1; do sleep 3; done
The instinct was to give Docker more. It is running out of something, so raise the limits. We moved Docker Desktop to 20 GB of memory and 8 CPUs and went to bed. It hung again, three times in one day, and always at the same moment: when the Lighthouse step started inside the browser container.
Act two: a load average of 317
The next clue came from uptime. The load average counts how many things want a CPU at once, so on a 10-core machine a load of about 10 means every core is busy. Ours read 110, 142, 155, and during the tablet tests it touched 317: roughly thirty things fighting over every single core.
# The eight busiest processes, sampled twice so the CPU figures are real
top -l 2 -o cpu -n 8 -stats pid,command,cpu | tail -9
Process | CPU | What it actually is |
|---|---|---|
| 78.0% | Gatekeeper, checking every new program before it runs |
| 21.5% | The kernel itself |
| 18.3% | Drawing the screen |
| 11.4% | File-change events, feeding Spotlight |
| 8.1% | Spotlight, indexing |
Gatekeeper was inspecting every test binary
A Rust test build creates hundreds of brand-new executables every time, and Gatekeeper dutifully inspects each one before it may run. Your terminal can be excused from that check: System Settings → Privacy & Security → Developer Tools, and switch your terminal app on.
# If Terminal is missing from the Developer Tools list, this adds it
spctl developer-mode enable-terminal
Spotlight was indexing the build folder
The other two busy processes were Spotlight, faithfully indexing a build folder that changed thousands of times a minute. System Settings → Spotlight → Search Privacy, add your code folder, and restart the terminal. The CPU that was going to security scans and search indexing goes back to your builds.
It helped. It did not fix Docker.
Act three: 1.36 million files
While chasing slow builds, we asked a different question: where does the time actually go? Every command reports two kinds of CPU time. User time is real computing; system time is the operating system working on your behalf, opening and checking files.
Step | User time | System time |
|---|---|---|
Test build | 364 s | 2,045 s |
Clippy (the Rust linter) | 148 s | 1,522 s |
Builds were spending five times longer in the operating system than in the compiler, and the reason was the Rust build folder:
Folder | Files | Size |
|---|---|---|
| 1,361,111 | 51 GB |
| 148,587 | 22 GB |
Every build walked and checked a folder of 1.36 million files. A clean-up job deleted anything older than two days, but each day added more than it removed. The fix was boring and effective:
# Once: start from a clean slate (the next build takes ~25 minutes, once)
cargo clean
# Every run: drop build leftovers nobody has touched for 6 hours
find target/debug/deps target/debug/incremental \
-mindepth 1 -maxdepth 1 -mmin +360 -exec rm -rf {} +
The full check went from 30 to 50 minutes down to 10 to 12. Docker still kept falling over.
Act four: the disk that was full without being full
Docker Desktop on a Mac keeps every image, volume and cache inside one virtual disk with a fixed ceiling. The Mac had 128 GB free. Docker's own disk did not.
docker system df
Type | Total | Active | Size | Reclaimable |
|---|---|---|---|---|
Images | 69 | 5 | 29.76 GB | 26.35 GB (88%) |
Local volumes | 30 | 1 | 17.96 GB | 17.19 GB (95%) |
Build cache | 69 | 0 | 1.36 GB | 1.36 GB |
Almost 50 GB in use, and nearly all of it leftovers: old image versions, and anonymous volumes from hundreds of throwaway test databases. A safe clean-up removes only what nothing uses:
# Images no container uses AND older than a week (current ones stay)
docker image prune -a --filter "until=168h" -f
# Anonymous volumes no container uses (named volumes stay)
docker volume prune -f
# Temporary build files
docker builder prune -f
Then raise the virtual disk limit in Docker Desktop → Settings → Resources to something comfortable. Better. Still not the cause.
Act five: a supporting cast of gremlins
While we hunted the main problem, smaller ones kept walking on stage. Each is worth knowing, because each looks like the big problem when it happens.
The mail catcher that froze
The tests read sign-in codes from a local test inbox, Mailpit, running in a container. One night it logged database is closed and its API stopped answering, and the tests waited for emails that would never come. It was a known bug in that version: deleting a message that was already deleted could leave its database stuck, and our clean-up did exactly that once two test files shared a worker. The cure was a pinned newer version, a fresh inbox for every run, and clearing mail by recipient rather than by message id:
# A fresh, pinned inbox for this run only (MAILPIT_IMAGE is a fixed tag, never :latest)
run_id=$(date +%s)
docker run -d --rm --name "mailpit-$run_id" -p 1025 -p 8025 "$MAILPIT_IMAGE"
web_port=$(docker port "mailpit-$run_id" 8025 | head -1 | cut -d: -f2)
# Clear one person's mail by search, not by message id
curl -s -X DELETE "http://localhost:$web_port/api/v1/search?query=to:alice@example.test"
# ...run the tests, then throw the inbox away
docker rm -f "mailpit-$run_id"
Eighteen phantom CPU burners
To test a timing check under load, the agent had started 18 yes processes in the background, and its sandbox could not stop them afterwards. They sat there heating the Mac at a load of 97.
pgrep -lx yes # list them
pkill -x yes # and stop every one
That produced a new rule for the agent: never start background load you cannot stop.
The settings that did not apply
Docker Desktop said 8 CPUs; the engine said 6. Later we set memory to 10 GB and the engine still said 20. The sliders needed moving and applying a second time. We now read every setting back from the engine itself:
docker info --format 'CPUs: {{.NCPU}} Memory: {{.MemTotal}}'
The VM that would not shrink
The self-hosted CI runner lives in a small Linux VM managed by Lima (we wrote up that setup in our guide to self-hosted GitHub Actions runners). We lowered its memory in its config file and nothing changed, because Lima reads that file only when it first creates the VM. An existing VM is resized while stopped:
limactl stop ci-runner
limactl edit ci-runner --memory 8 --cpus 6
limactl start ci-runner
limactl list ci-runner # read it back; never trust the file
That sequence now lives in the runner's start script, so a resize cannot be forgotten.
The turning point: stop guessing, start measuring
After the third Docker hang in a day, we stopped fixing and started measuring. A small sampler ran beside one full check and one full browser run, recording the Mac and the Docker VM side by side:
#!/usr/bin/env bash
# Sample the Mac and the Docker VM while a run is going, into one log
log="sample-$(date +%Y%m%d-%H%M).log"
# The Mac's load average, every 10 s
( while true; do echo "$(date +%T) mac-load $(sysctl -n vm.loadavg)"; sleep 10; done ) >> "$log" &
# The Mac's memory pressure, every 15 s
( while true; do echo "$(date +%T) $(vm_stat | grep -E 'free|compressor' | tr -s ' ' | tr '\n' ' ')"; sleep 15; done ) >> "$log" &
# Every container, and the Docker VM's own load and memory, every 20 s
( while true; do
docker stats --no-stream --format '{{.Name}} {{.CPUPerc}} {{.MemUsage}}' | sed "s/^/$(date +%T) /"
echo "$(date +%T) vm $(docker run --rm alpine sh -c 'cat /proc/loadavg; grep -E "MemTotal|MemAvailable" /proc/meminfo' | tr '\n' ' ')"
sleep 20
done ) >> "$log" &
# Stop every sampler when the run ends (see the gremlins above)
trap 'kill $(jobs -p)' EXIT
npx playwright test
The results overturned almost everything we had assumed.
Docker was not short of memory at all. Its VM peaked at 2.7 GB of the 20 GB it had been given. The browser container peaked at 1.37 GB.
The Mac was. During the browser suite macOS showed 0.1 to 0.4 GB free, with 28 GB held by memory compression. Two VMs had reserved a big slice up front, Docker's 20 GB plus the CI runner's 12 GB: 32 GB the rest of the Mac could not touch. Our "give Docker more" fix had made things worse.
Docker was short of CPU. Its VM ran at a load of 12 to 17, with the browser container using up to 708% CPU, while the Mac around it was oversubscribed many times over.

One line of configuration caused most of the browser load
The Playwright container mounted our entire web folder from the Mac. On macOS, sharing a folder into a Linux VM is not free: every file change, and a build makes thousands, has to cross that boundary. We ran the same 144 tablet tests three ways:
What the browser container mounted | Peak load |
|---|---|
The whole web folder | 142 |
Only the paths the tests need | 39 |
Nothing | 22 to 35 |
More parallel browsers barely helped
Playwright workers | Peak load | Time for 144 tests |
|---|---|---|
1 | 23 | 165 s |
2 | 53 | 129 s |
3 | 59 | 133 s |
Going from two workers to three made the run slower while doubling the load. Past a point, parallelism just means more things queueing for the same cores. The unit tests were piling on too: the Rust test runner ran ten test processes at once, and several of them started Node.js processes of their own. Dozens of processes, ten cores.
A 64 GB Mac is not a 64 GB build server. It is a shared computer: your editor, your browser, macOS's own services and every VM's up-front reservation all draw from the same pool.
The fix: give everything less, on purpose
Once we could see the problem, the fixes were almost embarrassingly simple.
1. Right-size the VMs, then read the numbers back
VM | Before | After |
|---|---|---|
Docker Desktop | 20 GB, 6 CPUs (8 set, never applied) | 10 GB, 8 CPUs |
CI runner VM | 12 GB, 6 CPUs | 8 GB, 6 CPUs |
That handed 14 GB back to the Mac, and each figure was confirmed with docker info and limactl list rather than a settings screen.
2. Cap parallelism in the repository, not by hand
Caps typed into a terminal last until the terminal closes. Caps in the repository's own config apply to every run, whoever or whatever starts it.
Tool | Cap |
|---|---|
Cargo build jobs | 6 |
Test processes (nextest) | 4 |
Rust doc tests | 4 |
Vitest workers | 3 |
Turbo tasks | 3 |
Playwright workers | 1 locally, 2 in the CI VM |
The Playwright cap, in playwright.config.ts:
import { defineConfig } from "@playwright/test";
export default defineConfig({
// One browser on the laptop, two in the CI VM. A third made runs slower.
workers: process.env.CI ? 2 : 1,
fullyParallel: false,
});
The Vitest cap, in vitest.config.ts:
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
maxWorkers: 3,
},
});
And the Rust and Turbo caps, as the commands the task runner calls:
# Cargo: six compile jobs (pinned for good as `jobs = 6` under [build] in .cargo/config.toml)
export CARGO_BUILD_JOBS=6
# nextest: four test processes at a time
cargo nextest run --test-threads 4
# Doc tests run outside nextest, so they need their own cap
cargo test --doc -- --test-threads=4
# Turbo: three tasks at once
npx turbo run lint test --concurrency=3
Then a small test keeps the caps in place, so nobody, human or agent, "speeds things up" by quietly deleting one:
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const read = (path: string) => readFileSync(path, "utf8");
describe("parallelism caps", () => {
it("keeps Playwright at one local worker and two in CI", () => {
expect(read("playwright.config.ts")).toMatch(/workers:\s*process\.env\.CI \? 2 : 1/);
});
it("keeps Vitest at three workers", () => {
expect(read("vitest.config.ts")).toMatch(/maxWorkers:\s*3/);
});
it("keeps Cargo at six build jobs", () => {
expect(read(".cargo/config.toml")).toMatch(/jobs\s*=\s*6/);
});
});
3. A fresh browser container per suite, with only what it needs
A 4 GB memory limit, and read-only mounts of just the test folders. No more whole-folder bind mounts.
# lantern-e2e is the Playwright base image with the test dependencies baked in
docker run --rm --init --ipc=host \
--memory=4g \
-v "$PWD/apps/web/e2e:/work/e2e:ro" \
-v "$PWD/apps/web/playwright.config.ts:/work/playwright.config.ts:ro" \
-v "$PWD/test-results:/work/test-results" \
-w /work \
lantern-e2e \
npx playwright test
4. One heavy job at a time
The CI runner and the local browser suite share one Mac, so the suite waits for CI to finish before it starts:
# Wait while a CI run is already busy on this machine
while [ "$(gh run list --status in_progress --json databaseId --jq 'length')" -gt 0 ]; do
echo "CI is running; waiting a minute..."
sleep 60
done
just e2e-full
5. Clean up as you go
The six-hour build-folder prune, Docker's image and volume prune, and a fresh test inbox per run, all from the acts above, now run as part of the check rather than when someone remembers.
The results
Measure | Before | After |
|---|---|---|
Full check (lint, unit and integration tests) | 30 to 50 min | 10 to 12 min |
Load average during the browser suite | 110 to 317 | median about 19 |
Docker hangs | three in one day | none in the proving runs |
Mac's free memory under load | 0.1 to 0.4 GB | comfortable |
Full browser suite | 33 min, when it finished | 45 min, every time |
We also stopped running the full matrix on every small change. Each change now runs its own browser tests on one laptop size and one phone size; the full matrix runs before each push batch, and at night, when nobody is waiting.
The detour: should we just rent a server?
Halfway through the mess, the obvious question came up, so we priced it:
Serverless functions were out at once: they stop after 15 minutes and cannot run Docker.
A big cloud VM running around the clock cost several hundred dollars a month.
A modest dedicated server was cheap, but slower than the Mac per core.
The surprise: the Mac was the fastest machine in the comparison by a wide margin. It was never too weak; it was badly scheduled. A dedicated server still earns its place for one reason, availability, when you want your laptop back for your own work. Raw speed is not it.
Ten lessons, in one place
"Give it more" is a guess. Measure first: load, memory inside and outside the VM, and time per step.
VM memory is reserved, not borrowed. Every gigabyte given to Docker or a Linux VM is gone from macOS, used or not.
Bind mounts are expensive on a Mac. Mount only what a container needs.
Parallelism has a ceiling. Past the number of cores, more workers make runs slower and the machine unusable.
macOS taxes new files. Gatekeeper and Spotlight both react to every one; ask them to stand down for your code folder.
Build folders grow without limit. Prune them aggressively, and clean them once in a while.
Read settings back. Sliders do not always apply.
Long-lived test helpers drift. Give each run its own fresh, pinned container.
Never start background load you cannot stop.
Trade a little speed for a lot of reliability. A slower run that finishes beats a fast one that hangs.
Watch: tuning Docker Desktop on a Mac
If you would rather see the Docker Desktop settings than read about them, this short walkthrough from Luke Urban goes through the resource settings on a Mac. Its headline matches our experience: the answer is not the one you expect.
The Mac is quiet now. Docker runs in 10 GB, the CI VM hums along on 8, and the agent works through the night at a load that would have looked impossible a week earlier. In the morning there are green ticks, and a short list of questions only a human can answer. The 64 GB were always enough; we just had to stop handing them all out before the work began.
Want a build pipeline that runs this calmly on your own hardware? Talk to us at Techpuvi.
