How We Automated Our Infrastructure Loop with Agents

A

Anmol

Dec 3

How We Automated Our Infrastructure Loop with Agents

Coding agents are good at fixing things. They are much worse at knowing whether the fix worked.

While building Constructive, we ran the same loop every week. A user journey broke on our development environment. Someone read the pod logs, found the repo that owned the problem, asked a coding agent to fix it and watched CI. Then they cut a release, planned the rollout, applied it, and clicked through the app to see whether the problem was really gone.

None of those steps is hard on its own. Joining them up is the work: which commit was CI for, which release carried the fix, did the rollout apply what was approved, and can a user now do the thing that failed? The agent was fast. Everything around it was manual, and that is where mistakes slipped through.

Constructive Station is the system we built to run that loop for us. It is the inner loop of our software factory: a set of agent workflows on Kubernetes that fix, release, deploy and test Constructive. On top of it sits an outer loop that decides what to run and checks what comes back.

Two loops

We split the work into two loops, because doing the work and judging the work are different jobs.

  • The inner loop does the work. Each workflow gets a bounded task, inspects the evidence, makes a scoped change, and verifies it. The workflows run on a Kubernetes cluster, next to an engineer agent that holds the skills and repos, a QA runner that scales up from zero for each test run, a gateway that routes every model call, and a store that keeps every report, video and trace.
  • The outer loop judges the result. An owner and a supervisor agent pick what to run, read what comes back, and decide whether to close the problem, retry, or change the system.

The work lands somewhere else. Code goes to GitHub. Releases go to our DevNet, a separate AWS EKS cluster that serves as our development environment. Staging is out of the Station's reach.

Almost all of it is configuration. We define the agents, the workflows, the QA journeys and the rules they follow in one repository, and changing how we ship is a pull request.

Seven workflows, one job each

Every workflow replaces a piece of work we used to do by hand, and each one has a clear end:

  • Fix. Finds the repo that owns a problem, patches it, and merges on green checks.
  • Fix DevNet. Reads the environment's logs before the model starts, then fixes the cause where it lives, with a test.
  • Review. Lands a fix that another run opened or held, or comes back with one clear question.
  • Release. Builds a release from a green candidate and validates the rollout plan. Nothing is applied.
  • Deploy. Applies exactly the plan a person approved, then proves it.
  • QA. Tests the deployed app the way our users use it.
  • Work overview. Joins runs, pull requests, CI and QA into one board. It changes nothing.

Every model step gets one short task and one skill, and must end as done or blocked. There is no room for "I think it worked." Release, deploy and QA can run as one chain, and starting that chain is the approval.

Agents judge, scripts wait

A workflow is a short list of steps, run by an embedded Temporal interpreter. The split between step kinds is the core of the design:

  • Script steps run with no model: cleaning up, reading logs, checking an approval, posting a result.
  • Model steps give an agent a bounded number of turns.
  • Jobs are scripts with a deadline that a turn starts and then hands off to.
  • Checks run after the last turn and can fail a step even when the agent says it is done.

This came out of watching our runs. In one week, 617 model calls did nothing but ask whether a running command had finished. That was 23% of all input tokens, spent waiting.

Now a turn that needs CI hands the exact commit to a wait job and ends. The job follows the pull request's current head, waits until every check on that commit finishes, and returns the result with its evidence. The next turn starts from that result instead of guessing. On one recent fix, the job waited 10 minutes and 27 seconds, and no model ran while it did.

If CI is still running, another model completion won't finish the build.

Deploys need an approval and a proof

A release ends with a plan: the release, the commit it came from, a digest of the plan, and its mode. Nothing is applied until a person approves that exact plan.

The deploy then does three things before anything changes:

  • Plans again. Plans are tied to live cluster state and go stale. The deploy replans from the same commit and stops if the scope has grown.
  • Checks the approval. The plan on disk has to match the approved digest.
  • Applies through ClusterOps, an internal harness we built for reviewable Kubernetes changes. Each phase is validated again, targets outside the allowed namespaces are refused, anything destructive stops for a person, and each phase has to settle before the next one starts.

A finished apply doesn't count as a finished deploy. The deploy is done when a proof of 19 checks passes against the release on its public endpoints. Only then does the team hear about it.

Deploys come in two modes. A fresh rebuild wipes the environment and rebuilds it from empty, the way our release tests run. An in-place rollout keeps the data and changes only what moved. The plan names its mode, and the deploy refuses a plan in the other.

QA decides

QA runs as scripts, through SystemProof, the harness we built for it. Each lane tests the deployed app a different way:

  • API journeys sign in as a QA user, query an agent and round-trip an upload.
  • Desktop journeys drive the Constructive Desktop app with Playwright and record video.
  • Prompt-built apps ask Desktop to build real apps from fixed prompts, such as a photo app, a data room and a CRM, then check them before and after publishing.

Every journey ends as pass, fail or blocked. Blocked matters: it means a dependency stopped the journey, not that the product broke. A model only shows up to triage a run that didn't pass, and its findings become the facts for the next fix.

QA catches both kinds of broken:

  • A product bug. An image upload was confirmed, but the processed version never arrived. The cause was a missing function in the environment's configuration.
  • A test bug. A file upload worked, but the test was waiting for a download link that the screen never shows. The fix went into the test.

The same idea runs through Safegres: checks that give the same answer every time, with a model only where judgment is needed.

Green deploy, red QA

On one afternoon, a single fix went through the whole loop in about 90 minutes:

  • Fix. The agent patched the problem, handed CI to a wait job, and merged on green.
  • Release. The plan for the same commit was validated, with nothing applied.
  • Deploy. Five phases and 17 changes, with no data wiped and all 19 checks passing.
  • QA. The Desktop app passed 11 of 11 journeys and the photo app passed every checkpoint. The CRM was blocked by a pending member approval, and the data room's invite link returned a 404.

The deploy was green and QA was not, and that was the right answer. Each stage answered a different question: did the exact commit pass CI, did the approved change apply, and can a user actually do the thing? The two failures became the next fixes. Over time, QA became the eval set for our infrastructure.

The outer loop

The supervisor sits on top of the Station, and its job is to make the Station better, not to do its work. It follows a few hard rules:

  • The Station does the work. Diagnoses, pull requests, merges, deploys and proofs are all Station runs. The supervisor never does them by hand.
  • Facts, never a diagnosis. A run gets what was seen, where, and the IDs. Handing it a diagnosis would hide whether the system could have found it.
  • Approvals stay with a person. The supervisor never starts a deploy.
  • Fix it once. A failed run becomes a root cause and a change to the system, not a retry.

It scores every run on its outcome, wall time, turns, tokens and model calls made while waiting. Most of what makes the Station reliable came out of that scoring:

  • Agents polled their own scripts, so waits and applies became jobs.
  • A wait followed a commit that had already moved, so it now follows the pull request's current head.
  • A wait returned on the first red check while CI was still running, so it now waits for every check.
  • An agent retyped a commit hash and got it wrong, so the merge script now writes the full hash for it.
  • A pod restart lost a plan, so every output now goes to the store.

Model time turned out to be cheap. In one week, 97% of our agents' input tokens were cached. The expensive part was waiting inside a conversation, and the fix was to stop doing that.

What's next

The Station isn't autonomous, and some of that is on purpose. People still start most runs, workflows can't yet start each other, and QA runs one lane at a time. Next, we want:

  • alerts and failed journeys to start fixes on their own
  • workflows to chain inside the Station
  • QA lanes to run in parallel
  • a read-only audit workflow that reports drift and health
  • the same loop for staging and per-release environments

The lesson we keep coming back to: give the agent the parts that need judgment, give scripts the waits and the hard checks, and make every step bring back evidence someone else can disagree with.