On 28 October one branch started its gate five times. Four times someone stopped it by hand to squeeze in another commit. The host ran 62 gates that day, and fixes that were already finished sat in the queue for hours.

This is what happens when AI agents write code in parallel. Writing costs almost nothing, so changes arrive faster than anything can check them. In the week of 14 to 20 September our verify step ran 1,209 times: median 250 seconds, 90th percentile 863, 113.4 machine-hours in all. Two slots gave us at most 48 machine-hours a day, and 14 September alone asked for 58.5. The queue had nowhere to go but up.

Here is what we changed so the queue stays short and every wait has a reason.

A worktree for every change

At first every person and every agent session edited the same folder on the same machine.

On 8 September a commit bounced four times because the shared copy held somebody else's half-finished package. The fix went into the setup. Every change now starts with bin/work, which gives the session its own folder and a branch cut from a fresh origin/main. The gate and the push run there.

A worktree needs its dependencies too. On 14 October a plain git worktree add produced a tree where the pre-commit check died on a missing package. Now bin/ready installs them, and agents are told never to symlink node_modules.

One gate per change

On 21 September a three-line fix went through four review rounds and three gate runs. Every review finding killed a gate already in progress, and each gate cost 4 to 10 minutes plus the wait for a slot.

The order is fixed now. Related tests run first. The reviewer reads the diff, every finding we keep gets fixed in that same round, and only then does the one gate start. The gate is short on purpose, since the full test suite runs every 3 hours on the deployed main.

After 28 October we stopped relying on discipline alone. The launcher script refuses to start on a dirty tree, on a conflict with origin/main or on a lint error. Starting the same tree a third time in one day requires a written reason, and so does every stop. Both go into the log. Anything found while a gate is running goes into the next change. Data jobs never wait for a gate, they run from a copy of the code.

A restart is a decision, so it leaves a line in the report.

Detached, on rented servers

The launcher runs each gate under setsid and nohup, with a 5,400-second timeout and a log in a fixed folder. A hook blocks direct bin/pr calls, so nobody skips the launcher by accident.

When the main host gets crowded, the gate moves. On 22 November host load sat between 30 and 46 and was killing gates, so we let agents rent temporary Hetzner Cloud servers for gates on their own. The one condition: no server sits idle. We learned that the hard way. An earlier test server outlived its shutdown timer by 3 hours 23 minutes, because the timer had been started by the session that died. A cleanup job on the main host now runs every 10 minutes as a backstop.

A verify run on a rented server counts as proof for one hour, and only while origin/main still points at the commit it checked. On 22 November main moved three times during one wait, and two of three server runs went to waste. So the merge gate starts the moment the proof lands. Across the journal, 35 remote runs took 16.4 minutes at the median.

A train for merges, a timer for shipping

On 15 September four pull requests landed within an hour, and each one broke the running merge on "main moved". Every break cost about 25 minutes of verify. Now one session owns all merges. The others push, open a pull request without auto-merge and send READY with the head commit. The gate starts on GO, and a LANDED line reports the commit and how many gates it took.

Shipping was a manual step, and it got skipped. Eight of the ten production alerts between 21 and 30 September were commits that had merged and never shipped. Since 30 September a guardian checks every 15 minutes. When main is 10 or more minutes ahead of production, it ships the site itself, at most once every 30 minutes and never right after a failed deploy.

Between 00:00 and 05:15 UTC the morning run works from the deploy copy, so night merges use --no-ship and restart nothing. On 26 October we saw the seam. The morning fix merged at 05:25 and reached production at 05:42, riding along with another branch's gate. Closing that 17-minute gap would have taken 3 hours of work plus a gate run. It caused no measurable harm, so we left it open.

Read the journal, not the logs

Until 23 November, answering "why do gates restart" meant reading 5,975 log files by hand. Now each gate run is one row in the run journal, with a cause picked from a fixed list. We pulled 90 days of rows and counted:

  • 4,220 gate runs from 27 September to 23 November, a median of 57 a day across 53 active days.
  • 1,583 merged, or 37.5%. The other 2,637 were refused, held or red.
  • A merged gate took 18.2 minutes at the median and 53.3 at the 90th percentile.
  • No free slot was the top cause, 1,378 rows or 52% of the runs that didn't merge. Genuinely red code was 439 rows, 10% of all runs.
  • On the busiest day, 17 November, 486 of 539 rows were no-slot refusals.

Most runs that didn't merge never looked at a line of code. They were waiting for a free machine. That is why rented servers and a short gate came first.

A fix has to say why

On 24 September a test went green and the fix still failed in production. The test had skipped the launcher that production uses, so it proved a path nobody runs. Tests now go through the same entry point as production. After a merge, the proof comes from the journal of a live run.

The root-cause rule is enforced by a hook. A commit whose subject starts with "Fix" is refused unless the message has a line beginning Root cause:. A stopgap writes Root cause: open, and says so. The hook can't tell whether the cause is the real one. It does make sure someone answered the question, in the place the next person will look.

The first version had a hole. Until 15 October, a message the hook couldn't read, such as one piped through stdin, counted as empty and passed. One fix commit landed that way with no cause line. Unreadable messages are refused now too.

If you want to borrow any of this, start here:

  • One worktree per change, cut from a fresh main, with dependencies installed by a script.
  • One gate per change. New findings go into the next change, and a restart needs a written reason.
  • Run the gate detached from the session and block direct calls.
  • Rent capacity for gates, delete it when the job ends, and keep a cleanup job on a timer you control.
  • Send merges through one queue and let a timer ship what merged.
  • Log every gate run with a cause from a fixed list, and answer questions from that log.
  • Refuse fix commits without a root-cause line, and test through the production entry point.

Want your agents shipping through a pipeline like this? Book a call at spicegtm.com.