Skip to content
James Ross
articlePublished Updated 9 min read

Multi agent orchestration: running AI coding agents on remote Linux machines

By James Ross

Multi agent orchestration on a separate Linux machine turns the workstation into a control plane: SSH launches a detached agent, a PID file and a git snapshot replace log-watching, and stall detection catches runs that quietly stop working. The fleet moved off a 16 GB laptop after seven parallel browser agents crashed it, then reached eight agents on the remote box.

A control workstation cabled to a rack of machines each running a small agent robot, depicting multi agent orchestration on remote Linux.

This multi agent orchestration setup is part of the wider method in shipping a SaaS product with a fleet of AI coding agents.

Why move coding agents off the laptop?

Because the bottleneck is the machine, not the model. Each agent that runs a web app, tests or a browser is a full development environment, and several compete with the editor, the browser and the container runtime already open.

The documented failure: seven read-only QA agents driving Playwright, plus one local dev server, crashed a 16 GB Mac. The container runtime was also consuming close to a full core while mostly idle, and every agent that started its own dev server and browser multiplied the memory footprint. The guidance after that incident was blunt: four or five agents on a laptop, not eight; quit the container runtime when no agent needs it; one shared dev server or one port per agent; cap browsers in the brief.

A separate Linux machine has its own RAM, browser processes and disk, and a crashed run does not take the operator’s session with it. The workstation writes the briefs, launches the runs, reads the reports and does the merges. It stops being where the work happens.

What stays on the workstation?

The control plane: briefs, launches, review and merges. If the workstation still runs the tests and holds the build cache, moving the agent buys much less.

Three things stay local. The briefs, written from facts the lead already has. The launch command, one script per project so every agent starts the same way. The check-in, one background job that reports when any agent stops or every fifteen minutes. The merge and release gate stay too: lint, typecheck, tests and the production build, run by the lead on the integration branch. Everything else happens remotely.

How do you launch a detached agent over SSH?

You launch it as a background process that does not depend on the SSH session staying open, then record its PID. The SSH command returns immediately; the agent keeps running.

A minimal launcher (the CLI is agent-cli; paths are placeholders):

# 1. Copy the brief to the box.
scp briefs/<name>.md build-box:/srv/agent/briefs/<name>.md

# 2. Launch detached, in the agent's own worktree, and record the PID.
ssh build-box 'cd /srv/work/<name> && \
  setsid nohup agent-cli -p "$(cat /srv/agent/briefs/<name>.md)" \
    --print-timeout 90m --mode accept-edits \
    > /srv/agent/logs/<name>.log 2>&1 < /dev/null & \
  echo $! > /srv/agent/logs/<name>.pid'

# 3. Ten seconds later, confirm it is alive.
ssh build-box 'kill -0 "$(cat /srv/agent/logs/<name>.pid)" && echo alive'

The script must survive the connection closing, avoid holding stdin, and leave a PID that can be checked later; each piece provides one property.

Piece What it does Why it matters here
setsid Starts the program in a new session (setsid(1)) Unties it from the login session SSH created
nohup Makes the command immune to hangups (nohup(1)) A dropped connection does not kill a long run
< /dev/null Detaches standard input The agent cannot wait on a terminal that is gone
echo $! Writes the background job’s PID to a file The PID file is the only reliable handle on the run

$! is the PID of whatever the shell started, which may be a wrapper. With nohup the wrapper execs the program, so the PID is the agent’s. If another process sits between them, confirm with ps -o pid,ppid,command.

pgrep has the same trap: matching pgrep -f 'agent-cli -p' also matches the waiter loop or the SSH command containing that string, so counts come back one high. The PID file avoids the guessing.

How do you tell whether a remote agent is working?

Read git, not the log. The agent writes its report when it exits, so a 0-byte log after thirty minutes is normal for a running agent. A log that never grows tells you nothing.

Three numbers from the agent’s worktree tell you almost everything:

# commits the agent has made on its branch
git -C "$WT" log --oneline main..HEAD | wc -l
# files changed but not committed
git -C "$WT" status --short | wc -l
# files touched in the last 15 minutes, ignoring dependencies and build output
find "$WT" -path '*/node_modules' -prune -o -path '*/.next' -prune \
  -o -path '*/.git' -prune -o -type f -mmin -15 -print | wc -l

git status --short is the machine-readable working tree state (git-status), and find -mmin selects files modified within the last N minutes (find(1)). Together they distinguish four states:

  • Productive: commits rising, uncommitted files changing, or files touched in the last fifteen minutes.
  • Finished cleanly: process gone, at least one commit, clean tree, sentinel line in the log.
  • Finished uncommitted: process gone, zero commits, many changed files. Send a continuation brief.
  • Stalled: process alive and no files touched for two consecutive fifteen-minute checks.

The check-in should be one background job: it wakes when any agent stops, or every fifteen minutes with a snapshot of every run, and restarts after each wake because it exits on the first event.

What does a stalled agent look like?

It looks alive. The process exists, the log is empty and the result file is missing. Two patterns account for most of it.

Idle on its own background task. The agent starts a long command — a production build, an end-to-end suite, a dev server — as a background task and then waits for it. One run sat there until the print timeout killed it, after the real work had passed. The fix belongs in the brief: run every command in the foreground, give long commands and browser steps a timeout, and kill every server or browser the run starts. When it happens anyway, kill the stray process on the port and send a continuation brief.

A dispatch loop. The agent’s task dispatcher re-dispatched the same sub-task six to twenty times in two minutes, each attempt reporting “completed” while nothing happened. The signal is the same: no files touched for fifteen minutes. Kill it and relaunch with a narrower brief; one area per agent made the loop rarer.

The continuation brief is the recovery for both, and for a timeout with the work done but uncommitted. It runs in the same worktree, treats the uncommitted changes as the previous run’s work, and asks the agent to finish rather than start over:

**CONTINUATION (read first)**
A previous run implemented most of this work but exited before verifying and committing.
The uncommitted changes are that work. Do NOT start over and do NOT discard them.
1. Review the changes against the brief; finish what is missing or broken.
2. Run the full verification in the FOREGROUND with timeouts.
3. Commit, write the result file, and print the DONE line.

Rename the old log before relaunching so the first attempt’s output survives. A continuation costs one brief; a fresh start costs the whole workstream.

How do you clean up after a run?

You kill the processes the agent forgot. A stray dev server blocks the next run’s port; a stray browser recreates the memory problem the box was meant to solve.

The rules that held:

  • One port per agent, written into the brief (3041, 3042, and so on).
  • Max two browsers at once, thirty seconds per Playwright step.
  • Kill every server and browser you start before finishing. State it as a completion condition, not a suggestion.
  • Check the ports before a QA wave. A leftover server on the shared build’s port stops it binding, and the audit fails for a reason unrelated to the product.
  • Send TERM first, then KILL if the agent does not exit; kill sends TERM by default (kill(1)).

Scratch files belong outside the repository. Screenshots, browser scripts and captured mail go to a per-agent directory, which keeps git status clean.

Where should verification run?

On the box, against the branch, with its own test database. The workstation can run a final integration check; the per-worktree verification is the work that does not fit on a laptop.

Three practices made it trustworthy:

  1. One test database per worktree. The name gets the agent’s name with hyphens converted to underscores, because Postgres identifiers cannot contain hyphens. Parallel agents sharing one database produced false failures.
  2. Reset on every full verify. A persistent test database filled past a row cap, and nine worker tests that pass on a fresh database started failing. It looked like a regression from the latest merge and was not.
  3. Make a failed pull loud. A locally modified lockfile blocked git pull, and the verify silently tested a stale commit for several rounds. The script discards that file first and prints PULL-FAILED on any pull error. The first line of every verify output is the commit hash, checked against the branch tip.

The box also ran builds: a production build measured about two minutes there against about seven on the application host (from the project’s decision log). That was a side effect, not the reason to add the machine.

Which machine should run the fleet?

Laptop Remote Linux box Hosted CI
Concurrency About 4–5 agents 8 in the recorded build Queue-bound per runner
Blast radius of a bad run The operator’s session The box The pipeline
Browsers and dev servers Compete with daily work Isolated Usually unsupported
Best for A small wave or a single fix Sustained fleets and verification Builds and tests, not interactive agent work

Which should you choose? Start on the laptop for one or two agents. Move to a remote box when the wave is larger than the machine, when browser work is involved, or when the operator must keep working while the fleet runs. Keep hosted CI for the deterministic gate — lint, typecheck, tests, build — because that part should be boring.

What broke and what we changed

A language-server discovery step hung the launcher. The old setup discovered a local port with lsof in every shell. It blocked once, so the agent never started, and returned an empty value once, so the agent died with no log and no PID file. Current versions of the tool run standalone, so the step was removed. If a value is set by hand, the launcher asserts it contains a port.

Five agents launched in the same second all exited with nothing. Empty logs, no commits, sometimes no PID file. Staggering launches and checking kill -0 ten seconds later turned a silent failure into a visible one. The rule: a 0-byte log, a dead agent and no commits mean a failed start, not a finished run.

A relaunch reused a worktree whose branch was already merged. “No commits ahead of main” looked like failure, but the work had landed. Fresh branch per run, and the brief names the exact output location. Another agent analyzed in a scratch folder because the brief never named the worktree; naming it fixed that.

Parallel agents’ tests shared one database. False failures, then a cleanup helper that deleted rows it did not own. The fix was per-worktree databases, reset on full verify, and test cleanup that deletes only the rows the test created.

Frequently asked questions

Do remote coding agents need a GPU?

No. Coding agents need CPU, RAM, disk and a browser, not a GPU. A machine that can run the application, its tests and a headless browser is enough. GPUs matter for inference or image generation, a workload that should not share a box.

Can agents keep running after the SSH session closes?

Yes, if launched detached. setsid puts the process in a new session, nohup makes it immune to hangups, and redirecting stdin from /dev/null stops it waiting on a terminal that no longer exists (ssh(1)). The SSH command returns; the agent continues remotely.

Why not just use tmux?

tmux works for an interactive session. A detached process plus a log file is easier to script and check from a monitoring job, and leaves a PID you can signal. The trade-off is losing the ability to attach and type, which is exactly what an autonomous agent should not depend on.

How do you stop a runaway agent?

Read the PID file, send TERM, wait, then send KILL if the process is still there (kill(1)). Then check the ports the brief assigned and kill any dev server or browser the agent left behind. Do not use a broad pattern match: it will also match your own waiter or the SSH command.

How much memory does each agent need?

Measure it on the work: the browser and the build dominate, not the model call. A browser-driven QA agent costs far more than a text-editing one. Start with four or five, watch memory and swap, then add one at a time.