DEV Community

Sandscale
Sandscale

Posted on Originally published at sandscale.dev

Why a coding agent's edit-test loop should not wait on CI

There is a pattern that shows up when a team first lets coding agents work on real repositories without running them on anyone's laptop. Nobody wants the agent running tests on a developer's machine, so the agent pushes a commit, CI runs, the agent reads the result, edits, and pushes again. CI becomes the agent's test runner.

It works, in the sense that the tests do run somewhere safe. This post is about why it is the wrong loop, and what to do instead. It is not about how to configure CI for agent pull requests; our post on GitHub Actions and agent pull requests covers triggers, tokens and the pull_request_target trap.

What goes wrong when CI is the loop

Every iteration pays the whole pipeline. An agent's loop is many small steps: change one function, run its tests, read one failure. A CI run is built for the opposite: check out, install, build, run everything, report. When the agent needs the answer to one test, it waits for all of it, plus the queue in front of it.

The feedback is harder to read. On its own machine, the agent runs a command and reads the output directly. Through CI, it has to find the run, fetch the logs through an API or a CLI, and dig the failure out of output written for humans scrolling a web page. Agents are good at many things, and parsing CI logs reliably is not one of the easy ones.

The history fills with noise. "fix test", "try again", "fix lint" become commits on a branch, and sometimes in the pull request everyone reviews. Squashing helps at merge time; it does not help the reviewer reading the branch today.

It spends shared capacity. CI runners and minutes are shared by the whole team. Five agents each pushing every few minutes can crowd out the people waiting for their own checks.

It mixes two jobs. CI is the gate a change must pass before it merges. When it is also the agent's scratch runner, a red build can mean "the agent is still working" or "this change is broken", and people stop trusting red.

Where each kind of check belongs

Split the checks by what they are for:

Check Purpose Where it runs
The tests for the code the agent just changed Fast feedback while editing The agent's own machine
Lint and type checks Fast feedback while editing The agent's own machine
The full suite before a pull request Confidence before asking for review The agent's machine, or a larger leased machine for heavy suites
The required checks on the pull request The gate before merge CI

The first two rows are the loop. They should take as little ceremony as possible, so they belong where the agent already is. The last row is the gate. It should be independent of the agent, run from a clean checkout, and be the same for people and agents.

For the third row, when the full suite is heavier than the agent's machine, our post on leasing a build host for a full test suite shows how to run just that step on a larger machine and release it afterwards.

Why this needs a machine per agent

The reason teams fall back to CI is usually not a love of CI. It is that the alternative was the laptop: a developer's machine, with their credentials, shared between several agents fighting over ports and CPU. CI was the only separate machine available.

Give each agent its own machine and the loop has somewhere to run. On Sandscale, each agent gets a workspace: its own Firecracker microVM with its own disk, ports, CPU and memory, where the repository, installed dependencies and the agent's session persist between sessions. Dependencies are installed once, so running one test file is just running one test file.

sandscale workspace create --name agent-search --template-id TEMPLATE_ID
sandscale workspace ssh agent-search
Enter fullscreen mode Exit fullscreen mode

A reviewer can rerun the agent's checks on the same machine without trusting the agent's word for it. workspace exec runs one command there as you and returns the exit code and output; it asks for confirmation first:

sandscale workspace exec --ws-id WORKSPACE_ID --command '["sh", "-c", "cd ~/app && npm test -- src/search"]'
Enter fullscreen mode Exit fullscreen mode

The AGENTS.md lines

Claude Code, Codex and Cursor all read AGENTS.md. These lines make the split explicit:

## Testing
- While working, run the tests for the files you changed: `npm test -- <path>`.
- Run `npm run lint` and `npm run typecheck` before each commit.
- Do not push to find out whether tests pass. Push when the checks above pass locally.
- Before opening a PR, run the full suite once: `npm run test:all`.
- CI on the PR is the gate. If CI fails on something that passed for you, report the difference in the PR; do not push guesses.
Enter fullscreen mode Exit fullscreen mode

The important line is the third one. Without it, an agent that hits a hard failure may start pushing guesses and waiting for CI, because that is what it has seen work.

What stays in CI

Everything that makes CI a gate: the required checks, a clean checkout, the same rules for people and agents, and the protections around tokens and triggers. Moving the loop out of CI makes CI more trustworthy, not less. Red means the change is broken, because the agent already ran its checks before it pushed.

Agents iterate quickly when each loop is cheap and the output is readable. Their own machine gives them that; CI keeps the gate. With both in place, the team gets more done without the agents queueing behind each other.

Originally published on the Sandscale blog.

Top comments (0)