Skip to main content

Building an always-on AI SRE

An agent that investigates incidents has to start working the moment an alert arrives, and usually nobody is at a computer then. This post covers the four parts Flashduty AI SRE needs to stay always on: an event-triggered loop in the cloud, an execution environment next to your data, dispatch across environments, and sessions that belong to no single machine.

Flashduty Engineering

Building an always-on AI SRE

An agent that investigates incidents has to start working the moment an alert arrives. Usually nobody is at a computer at that moment.

We looked at recent incidents on the Flashduty platform and split them into time bands by each account's own time zone. More than 60% of incidents happen outside working hours. The share is the same when you look only at the highest-severity incidents.

Coding agents such as Claude Code and Cursor run on your computer and start when you send a message. Close the laptop and they stop. AI SRE can't work that way.

This post covers the four parts we built to stay always on, and the failure each one prevents.

Always on means meeting four conditions at once

An incident-investigation agent that lacks any of these isn't always on:

  • It starts without anyone sending a message. An alert arriving, a question in a chat group, or a scheduled task coming due can each start an investigation.
  • It can reach your data. Your Prometheus, Kubernetes, and hosts mostly sit on an internal network, and the agent has to get in.
  • It survives any machine going down. The platform ships several times a day and machines fail. An investigation can't be lost because of either.
  • It needs no installation to start. The more setup steps you require, the fewer teams will try it.

These four conditions map to four parts: the loop in the cloud, the execution environment, dispatch across environments, and the session's mailbox and lease.

The four parts of AI SRE: the loop in the cloud takes in alerts, chat messages, and scheduled tasks; the loop uses the execution environment through a five-operation interface; the execution environment is a runner on the customer's internal network or a cloud sandbox; the session's mailbox and lease live in Redis

The loop lives in the cloud and starts from events

You can split an agent into two parts:

Agent   = model + harness
harness = brain (loop + context) + hands (tools + file system)

A model vendor provides the model. Everything you write around the model is the harness. The brain decides what to do next, and the hands carry it out. Anthropic's engineering post on Managed Agents uses the same pair of terms, brain and hands.

A coding agent has both brain and hands locally. To be always on, the brain has to live in the cloud, and events reach it directly without passing through anyone's computer.

Three kinds of events can start an investigation:

  • Alerts. When an alert arrives, notifying the on-call engineer and starting the investigation happen together.
  • Chat messages. Someone in a chat group asks it a question, or adds a lead in the middle of an investigation.
  • Scheduled tasks. Daily inspections are one example. Working at 3 a.m.: Five ways to use AI SRE Automations shows how.

By the time the on-call engineer is woken by a phone call and joins the chat group, a first assessment is already there.

The execution environment is an interface that sits next to your data

Once the brain is in the cloud, the first question is where the hands go.

If the hands are in the cloud too, they can't reach your internal network. For the cloud to query your internal Prometheus, you would have to open an access point to the outside, and most teams won't accept that.

We define the execution environment as an interface with five operations: read a file, write a file, find by name, search by content, and run a command. The loop calls only this interface and doesn't need to know which machine is behind it.

The interface has two implementations.

A runner on the customer's internal network. We modeled it on the GitHub Actions runner. You deploy one program in your environment, and it connects out to the cloud, so you open no inbound ports. Queries run on your network, and only results go back to the cloud.

A cloud sandbox. The sandbox runs the same runner program. Only the direction of the connection differs: a runner on your network connects out, and the platform connects to a cloud sandbox. Tasks that don't need your internal network can start without installing anything.

Three design decisions sit behind this.

We send over the whole hand, not just a network proxy. A runner could forward only network requests. But agents are best at reading and writing files, searching files, and running commands, so they need a file system. Files and commands therefore live on the runner side.

The runner stays thin. It holds no model, prompt, or session. The parts that change fastest, prompts and dispatch logic, live in the cloud, so upgrades need nothing from you. Since August this year, the cloud side has had about 10 times as many commits as the runner.

Whoever controls the startup initiates the connection. The platform creates the sandbox and knows when it's ready, so the platform connects to it. You decide when your runner starts, so the runner connects out.

You can leave environment choice to automatic mode. If the session's team has an online runner, it uses that. Otherwise it uses the account's shared runner, and only if there is none does it create a sandbox. If you name a specific runner and it's offline, the session returns an error and doesn't fall back to a cloud sandbox. You usually name a runner because the data exists only there.

One session can use several environments

One execution environment often isn't enough.

Many teams have several data centers with no network path between them. A runner deployed in one data center can't query the Prometheus in another. Other teams have production machines with no access to the internet, so tasks like reading code and opening pull requests (PRs) fit better in a cloud sandbox.

We let the main agent dispatch subagents to other environments. Dispatch takes one extra parameter. Leave it empty and the subagent runs in the current environment. Give a runner's name and it goes to that machine. Give cloud and a sandbox is created. Every dispatch checks permissions once.

The main agent dispatches subagents to different environments: one goes to a cloud sandbox to change code and open a PR, and two go to runners in different data centers to query their own Prometheus; results come back as text

Here's an example from our own account. The daily inspection task has to read code and open PRs, and one day the runner hosting the main session couldn't reach GitHub. The main agent dispatched three tasks to cloud sandboxes, and each opened one PR. In its report it stated that subagents had opened these PRs and that it couldn't verify them locally. An engineer reviewed the PRs before merging.

This design has two costs:

  • Environments don't share files. A subagent's results can come back only as text.
  • More dispatch isn't better. We tried making it dispatch subagents in parallel by default, and investigation time grew to three times what it had been. We reverted that policy after three days.

Today the model decides which environment to go to, and the dispatch tool checks whether it has permission to go there.

A session belongs to no single machine

Putting the brain in the cloud adds a job that local agents don't have.

Locally, an agent is a process on your computer, and the operating system keeps it running. In the cloud, a fleet of machines runs all the sessions. If a session's loop exists only in one machine's memory, the investigation stops when that machine goes down.

Our approach has three parts.

A mailbox. Messages go to the session, not to a machine. A message you send in chat, a new alert, a subagent's result, and a stop command all go into the session's mailbox.

A lease. Only the machine holding the lease can run the session. A lease expires after 30 seconds and needs continuous renewal, and only one machine holds it at a time.

Takeover. Once the lease is released or expires, another machine takes it and continues from the same step.

Takeover works differently in two cases:

DeployMachine crash
Old machineFinishes the current step, then releases the lease, waiting up to 60 secondsGets no chance to release
Unprocessed messagesStay in the mailboxStay in the mailbox
When the new machine takes overChecks every 5 seconds, and whichever machine gets the lease first takes overTakes over after the lease expires, 40 seconds without a heartbeat
Tool call that was mid-executionAlready finishedThe platform tells the model the result is unknown and asks it to verify before retrying

A subagent is also a session like this, and it can run on another machine. When it finishes, its result goes back into the main session's mailbox as a message.

This mechanism depends only on Redis and MySQL. For the implementation details, see Ordered, crash-safe AI agent sessions with one Redis lock.

The full path of one alert

Put the four parts together and an alert takes this path.

  1. An alert arrives. The platform notifies the on-call engineer by schedule and also puts the alert into the mailbox of a new session.
  2. One machine takes the session's lease and starts running the loop.
  3. The loop decides what to check first and sends commands through the interface to the runner on your internal network. The query runs there, and the results come back.
  4. When it needs to check another data center, the main agent dispatches a subagent there.
  5. If the platform is releasing at that moment, the current machine finishes its step and releases the lease, and another machine takes over.
  6. The conclusion goes to the chat group. When the on-call engineer joins the group, they can ask follow-up questions right away.

For investigations triggered automatically by alerts, the median time from the start of the incident to an AI SRE conclusion is 3.7 minutes, and the 90th percentile is 10.4 minutes.

One thing to try first

If your team is also building an agent that runs in the cloud, try this test: during a release, let one session stop partway through a step, and see whether it can continue on another machine.

The test checks where session state lives, whether messages get lost, and how half-finished operations are handled, all at once.

This is the first post in our series on building AI SRE. The next three cover evaluation, safety boundaries in production, and replies in chat groups.

Related articles

Less noise. Faster recovery.

Start free, no credit card required. Or book a demo to see the full incident workflow end to end.