← Agentic engineering

Module 8 · Ship it and run it

Keep test and production apart by credentials, know what a rollback does not undo, keep logs an agent can read, watch three numbers behind one alert, let an agent triage while a person makes the calls, and end the post-mortem in a check.

Facts checked

The engineer who directed the agent is the one paged when the change fails in production, often for a service in a stack they did not grow up in. The agent can help at that moment, and it can also make the incident worse with one confident suggestion.

By the end of this module you can keep an agent away from production by where the credentials live, say before a deploy what a rollback would not undo, set up logs and three numbers that tell you something is wrong, use an agent to triage an alert while you make the decisions, and write a post-mortem that ends in a check.

Before you read
1.

A release went out twenty minutes ago with a migration, and errors are climbing. You redeploy the previous release. Which of these does that not undo?

2.

What makes a log line useful to an agent investigating an incident?

3.

Ten minutes into an incident the agent says: "The cause is the last release. I recommend rolling back now." What do you do first?

Credentials are the wall between test and production

An instruction does not keep an agent away from production. In July 2025 the founder of SaaStr reported that Replit's agent had deleted his production database after he had told it to freeze all changes. The Register covered the exchange on 22 July 2025. Replit's chief executive called it "unacceptable and should never be possible", and the company's response was structural: it began separating development databases from production ones automatically.

What keeps an agent out is where the credentials are kept. The agent's environment holds what it needs for the test environment and nothing for production. Production's credentials live in the deploy pipeline and the secret store. A deploy promotes the build that passed on test, and the pipeline runs production's migrations. No person and no agent runs them from a laptop.

Two details from one team's unpublished record are worth copying. A deploy aimed at the wrong project once applied one product's migrations to another product's production database, which is why a pipeline should check which database it is connected to before it migrates. And a deploy stops any scheduled job that is partway through, so every job has to be safe to start again.

The agent can still do most of the work of shipping. It writes the pipeline, the migration and the rollback script, and it runs all of them against test. Security of the code and the agent covers the other limits on what it can reach.

flowchart LR
  A[Agent's environment<br/>test credentials only] --> T[Test environment]
  T --> C{Checks pass?}
  C -- yes --> P[Deploy pipeline<br/>holds production credentials]
  P --> L[Production]
  C -- no --> A

What a rollback does not undo

Rolling back means running the previous build again. It changes the code that is running and leaves the rest as the new release left it.

  • The schema. A migration that has run stays run. If it removed or tightened something the previous code depends on, the previous code now fails.
  • The data. Rows written since the deploy are in the new shape. Rows the new code changed stay changed.
  • Anything sent. Emails, payments, webhooks and messages on a queue have left.
  • Clients you do not deploy. A mobile app on a user's phone and a partner's integration keep sending what they sent yesterday. They cannot be rolled back or forward by you.

This is where the specialties differ. A frontend deploy replaces everything a browser loads. A mobile release sits on phones for months. A database change outlives every version of the code.

Before a deploy, ask the agent to answer one question in the pull request: if this is rolled back ten minutes after release, what stays changed, and does the previous code work with it? The rule that makes the answer "yes" is the one in Data and migrations: each release works with the schema before and after its migration, and nothing is tightened or removed in the release that starts using it.

Rehearse the rollback on a quiet day and time it. The first rollback should not happen during an incident.

Logs an agent can read

During an incident the log is the record of what happened, and an agent reads it far faster than a person can. That only helps if the lines can be searched and joined.

Write one event per line in a structured format such as JSON. Give each line the time in UTC, an id shared by every line of the same request, the release that produced it, the client and version that sent the request, the route, the outcome and how long it took. On failure add the error's type, its message and where it was raised.

Keep the detail. Martin Fowler's note of 21 October 2026 summarises a long article by Cindy Sridharan on debugging with agents. People want less data, she writes, and aggregation is what makes a dashboard useful to them. An agent needs the raw data, and aggregation often destroys the signal it would have used.

Give the agent read access to the logs through a query tool, scoped to the service it is working on. Keep secrets and personal details out of the lines themselves. Log an account's id and never its contents, because logs are pasted into agent sessions and those sessions are stored.

Three numbers and one alert

Someone has to remember to look at a dashboard, but an alert is sent to them. If you run a service outside your specialty, set up an alert on three numbers.

Is it answering? A request from outside your network, every minute.

How often does it fail? The share of requests in the last five minutes that ended in an error.

Is the thing it exists for still happening? One number from the business that should be moving: orders placed, bookings made, messages delivered. This one catches the failure the other two miss, where the service answers, reports no errors and has quietly stopped doing its job.

Give each number a threshold taken from its own history for that hour and day, and send a breach to a phone. One alert per symptom is enough. If one fault sends ten alerts, people learn to ignore all of them.

Measure, and do not rely on how things feel. METR ran a controlled trial with early-2025 tools and published it on 10 July 2025. Sixteen experienced open-source developers worked through 246 issues in their own repositories, each issue randomly assigned to allow AI tools or not. With AI allowed they took 19% longer. They had expected to be 24% faster, and afterwards they still believed they had been 20% faster.

The 19% is a snapshot of those tools and should not be quoted as current. In February 2026 METR reported a second study with 57 developers and later tools. Its raw estimates pointed towards a speed-up, and METR called them only very weak evidence. Between 30% and 50% of the developers said they had held back tasks they did not want to do without AI. What has lasted from the 2025 study is the gap between what the developers felt and what was measured. The same gap applies to "it seems stable since the release".

Agent-assisted triage, and where a person must check

An agent with read access to the logs, the deploy record and the diff of the last release does the slow parts of triage quickly. It finds when the errors began and which change came just before. It groups the failures by what they share, drafts the timeline, and later drafts the fix, its regression test and the post-mortem.

Sridharan calls an investigation that starts by reading the code an anti-pattern, and Fowler's summary gives her routine. Collect the evidence first and form hypotheses afterwards. Find a control, meaning a case where the system does not show the fault: requests that still succeed, the previous build, another environment. Then compare the two. Of the three bugs her article works through, she writes that her most useful contributions were picking a control, choosing a constraint, and rejecting a hypothesis that had not been validated.

A person must check at five points.

  • Any action on production. The agent proposes a rollback, a configuration change or a data repair. A person decides and runs it through the pipeline. The agent's access is read-only.
  • The stated cause. Ask what evidence separates it from the next most likely cause, and reproduce the fault on test before accepting it.
  • What the action leaves behind. Ask the rollback question before rolling back.
  • The impact figures. Run the query yourself. These numbers go to customers.
  • A repair to data. Run the script against a restored copy first.

Agents are also used to review the write-up. Cloudflare wrote on 4 August 2026 that its incident-report reviewer had assessed more than 200 reports since May 2026 and had flagged missing follow-up actions, incomplete timelines and detection signals that were left out.

A blameless post-mortem that ends in a check

Google's site reliability book defines a post-mortem as a written record of an incident, its impact, the actions taken to mitigate or resolve it, the root causes, and the follow-up actions to prevent it from recurring. It is blameless when it identifies the contributing causes without indicting any individual or team for bad behaviour. People who expect blame stop reporting what they saw.

The same applies when an agent wrote the change. "The agent got it wrong" is not a cause anyone can act on. The causes are what let the change through: what the brief left out, which check did not exist, what the review did not look at.

Write five parts: the impact in numbers checked by query, the timeline with clock times, the causes, what went well, and what changes. The last part is a check that would have caught this fault: a test, a rule in continuous integration, or an alert. Run it against the release that failed and see it fail. People forget a resolution such as "be more careful with migrations" within a month. Guardrails covers turning a rule into a check.

Tuesday, 13:47: bookings from the carrier app are failing

A scenario. A freight depot runs a booking service: carriers reserve unloading slots from a web page or from the drivers' mobile app. The engineer on call this week builds the web page and has never been on call for the API. All times are local. Say what you would do at each step before you read it.

  1. 1 · 13:40. Release 214 goes out

    An agent built it and it passed review. Every booking now records a dock zone. The release adds a dock_zone column to bookings, fills it for existing rows and makes it required, all in one migration. The API now reads the zone from each request, and the web page sends it. The first failing request is logged at 13:41.

  2. 2 · 13:47. The alert fires

    The error rate has been above 5% for five minutes, and the engineer's phone rings. The three numbers: the service is answering, 18% of requests are failing against a usual 0.3%, and bookings made in the last fifteen minutes are well below a normal Tuesday afternoon.

  3. 3 · 13:49. Evidence first, and a control

    The engineer asks the agent, which has read access to the logs and the deploy record, for the facts before any theory. It reports that the errors began at 13:41, one minute after release 214. All of them are on POST /bookings. Every failing request carries client=carrier-app/3.8, and the error is a null value in the required column dock_zone. The control is in the same logs: requests from client=web to the same route are succeeding, so what differs is the client. Version 3.8 of the app does not send a zone. Version 3.9, which does, is still waiting for app-store review.

  4. 4 · 13:53. The agent proposes a rollback, and the person asks what it would leave

    "Roll back to release 213." Release 214's migration has already run, and dock_zone is now required. Release 213's code never writes that column. After a rollback every booking would be rejected, from the web page as well as from the app. The engineer rules the rollback out.

  5. 5 · 13:58. Choose the smallest reversible change and try it on test

    One statement makes dock_zone optional again. On the test environment a request without a zone fails as in production. After the statement, the same request creates a booking with no zone, and the depot's screen lists it under "Unassigned". The engineer decides to ship that now and to fix the API afterwards.

  6. 6 · 14:04. Mitigate through the pipeline

    The engineer runs the one-statement migration on production through the deploy pipeline. The agent drafted it and does not hold the credential to run it. By 14:06 the error rate is back at 0.3%, and it stays there. Bookings from the app succeed, without a zone.

  7. 7 · 14:10. Tell the people affected, with numbers you ran yourself

    The agent's draft says "about 60 bookings were lost". The engineer runs the query. Between 13:41 and 14:04, 57 requests from the app failed, from 31 carriers. The note to depot staff says that bookings from the carrier app failed for 23 minutes, that web bookings were not affected, and that drivers who saw an error need to book again. By 15:00, 22 of the 31 carriers have rebooked. Staff phone the other 9.

  8. 8 · 15:20. Fix, with a test that fails on the fault

    Release 215 makes the API fill in the depot's default zone when a request has none. Its regression test sends a request shaped like version 3.8's. The test fails against release 214's code and passes against 215's. The 38 bookings made without a zone between 14:04 and 15:20 are filled by a short script, run first against a restored copy. Making the column required again waits until no supported version of the app omits the zone, and ships as a change of its own.

  9. 9 · Next morning. The post-mortem, ending in two checks

    Impact: 23 minutes, 13:41 to 14:04. 57 failed booking requests from 31 carriers, 9 of whom were phoned. Timeline: 13:40 release 214 goes out, 13:41 first failed request, 13:47 alert, 13:53 rollback questioned, 14:04 mitigated, 14:10 carriers told, 15:20 fix shipped. Causes: release 214 made a new field required in the API and in the database at once, while a client the team does not deploy was still sending the old shape. The tests used only the new shape, and nothing listed the API's clients. What went well: the alert fired six minutes after the first error, the control gave the cause within minutes, and the rollback was questioned before it was run. What changes: a contract test replays recorded requests from every supported client version against each new build, and a check fails any migration that makes a column required in the same release that starts writing it. Both are run against release 214, and both fail.

Try it

Fill the gaps in this incident routine, kept in the repository where the on-call engineer and the agent both read it.

# When the alert fires

1. Read the three numbers: is it answering, how often it fails, is the business number moving.
2. Ask the agent for the ______ before any theory: first error, last change
   before it, what the failures share.
3. Find a ______: requests that still succeed, and what is different about them.
4. Before rolling back, write down what the rollback would not ______.
5. Mitigate with the smallest reversible change, tried on test, run through
   the ______ by a person.
6. Check the impact figures by ______ before telling anyone.
7. Fix with a test that fails on the fault. End the post-mortem in a ______.
The misconception

If a release goes wrong, we roll back, and the service is as it was.

Why it’s wrong

A rollback returns the code to the previous build. In the worked example it would have turned a partial failure into a total one, because the migration had already made a column required that the previous code never wrote. The rollback command gives no warning of that, and an agent reading the error rate will recommend it.

People go on believing this because most rollbacks do work. Most releases change only code. The ones that fail badly are the ones that also changed the schema, the data or what clients must send.

The correct model

Decide what a rollback would leave behind before the deploy, while there is time to think. Ship schema changes so that the previous code keeps working. During an incident, check the last release for a migration before you roll back. When there is one, the safe move is often a small change forward.

Check yourself
  • What keeps an agent from changing production, and what does not?

  • Name four things a rollback does not undo.

  • What are the three numbers, and what does the third one catch?

  • What did METR's 2025 study find, when, and why is the 19% not quoted as current?

  • In agent-assisted triage, what is a control, and at which points must a person check?

  • What is the last section of a post-mortem, and how do you know it is good enough?

Before the check

The agent works against test, and production's credentials live in the pipeline. Before a deploy you know what a rollback would leave behind. Structured logs and three numbers tell a person that something is wrong. During an incident the agent gathers evidence and compares failing requests with a control, while a person decides, acts on production and checks the figures. The post-mortem names causes without blame and ends in a check that has been seen to fail on the fault.

Check yourself before you go on:

  • Could a command run by your agent reach your production database today?
  • For your last release, what would a rollback ten minutes later have left changed?
  • Which single number from the business would tell you that your service has quietly stopped doing its job?
  • Which clients of your API can you not redeploy, and does any test send what they send?
  • What check came out of your team's last incident, and has anyone seen it fail?
Sources
1 lab

Labs

Lab 1

Practise this: Run an incident drill

A drill, worked on paper. You are on call this week for the appointment-reminder service of Tallow Dental, a group of nine dental clinics in Sydney. The service texts each patient two hours before their appointment. Sydney is on daylight time in December, UTC+11; the logs are in UTC and everything else is in Sydney time. It is 08:31 on Tuesday 1 December 2026. This is everything you have.

The alert

PAGE  appointment-reminders  Tue 1 Dec 2026 08:16 AEDT
Reminders sent, last 15 minutes: 1,217
Usual range for a Tuesday 08:00-08:15: 30 to 75
Service answering: yes    Error rate, last 5 minutes: 0.2% (usual 0.1-0.4%)

The deploy record

Time (AEDT)What
Mon 30 Nov, 16:40Pull request #412, release 57, merged after review
Tue 1 Dec, 07:52CI passes for release 57: 412 tests (runner ubuntu-latest, clock in UTC)
07:58Deploy of release 57 starts. Migration 0031_appointment_times_utc runs
07:59Release 57 live on both servers (servers run with TZ=Australia/Sydney, set in 2019 for the clinic reports)
Previous deployRelease 56, Thu 26 Nov, 08:05: a wording change to the booking confirmation email

Release 57's pull request

#412 Store appointment times in UTC (written by an agent from the ticket "Store times in UTC so the new Perth clinic works")

Converts appointments.starts_at and appointments.remind_at from Sydney time to UTC for every appointment from today on, and makes the booking screen and the booking API write UTC and show local time. Files: migrations/0031_appointment_times_utc.sql, booking/screen.py, booking/api.py, tests/test_booking.py. All 412 tests pass.

The reminder job

# reminders/job.py, unchanged since March. Runs every 5 minutes.
def run(conn, sms):
    now = datetime.now().strftime("%Y-%m-%d %H:%M")
    due = conn.execute(
        "SELECT id, clinic, phone, starts_at FROM appointments "
        "WHERE remind_at <= ? AND reminder_sent_at IS NULL", (now,)
    ).fetchall()
    for appointment_id, clinic, phone, starts_at in due:
        sms.send(phone, f"Tallow Dental: your appointment at {clinic} is today at {starts_at[11:16]}. Reply C to cancel.")
        conn.execute("UPDATE appointments SET reminder_sent_at = ? WHERE id = ?", (now, appointment_id))
        conn.commit()

A reminder is due two hours before the appointment: remind_at is starts_at minus two hours. A reply of C cancels the appointment and frees the slot.

The logs (an excerpt the triage agent pulled, oldest first; the first two lines are from the same time last Tuesday)

{"ts":"2026-11-23T21:00:02Z","release":"55","event":"reminder_run","due":48,"sent":48,"failed":0}
{"ts":"2026-11-23T21:05:01Z","release":"55","event":"reminder_run","due":11,"sent":11,"failed":0}
{"ts":"2026-11-30T20:55:01Z","release":"56","event":"reminder_run","due":13,"sent":13,"failed":0}
{"ts":"2026-11-30T20:58:09Z","release":"57","event":"migration","name":"0031_appointment_times_utc","rows":9870,"took_ms":41022}
{"ts":"2026-11-30T21:00:02Z","release":"57","event":"reminder_run_start","now":"2026-12-01 08:00","due":1214}
{"ts":"2026-11-30T21:00:03Z","release":"57","event":"sms_sent","appointment_id":88412,"clinic":"Bondi Junction","starts_at":"2026-12-01 03:30","remind_at":"2026-12-01 01:30","provider_status":202,"attempt":1}
{"ts":"2026-11-30T21:00:03Z","release":"57","event":"sms_sent","appointment_id":88413,"clinic":"Bondi Junction","starts_at":"2026-12-01 03:30","remind_at":"2026-12-01 01:30","provider_status":202,"attempt":1}
{"ts":"2026-11-30T21:00:04Z","release":"57","event":"sms_sent","appointment_id":88257,"clinic":"Parramatta","starts_at":"2026-12-01 07:15","remind_at":"2026-12-01 05:15","provider_status":202,"attempt":1}
{"ts":"2026-11-30T21:00:04Z","release":"57","event":"sms_sent","appointment_id":88102,"clinic":"Manly","starts_at":"2026-11-30 23:00","remind_at":"2026-11-30 21:00","provider_status":202,"attempt":1}
{"ts":"2026-11-30T21:01:52Z","release":"57","event":"reminder_run_done","due":1214,"sent":1214,"failed":0,"took_ms":110204}
{"ts":"2026-11-30T21:02:30Z","release":"57","event":"http_summary","window":"5m","requests":2210,"errors":4}
{"ts":"2026-11-30T21:05:01Z","release":"57","event":"reminder_run","due":3,"sent":3,"failed":0}
{"ts":"2026-11-30T21:06:12Z","release":"57","event":"sms_reply","appointment_id":88412,"text":"C","action":"cancelled"}
{"ts":"2026-11-30T21:10:01Z","release":"57","event":"reminder_run","due":0,"sent":0,"failed":0}
{"ts":"2026-11-30T21:15:01Z","release":"57","event":"reminder_run","due":0,"sent":0,"failed":0}
{"ts":"2026-11-30T21:29:58Z","release":"57","event":"sms_reply_summary","since":"2026-11-30T21:00:00Z","replies":212,"cancelled":37}

The chat so far

  • 08:19 Jo (on call this week; builds the patient web app, first time on call for this service) acknowledges the page.
  • 08:21 Jo asks the team's triage agent, which has read access to the logs and the deploy record, what is going on.
  • 08:24 Triage agent: "Likely cause: the SMS provider retried a batch of messages (a retry storm), which inflates the sent count. Release 57 only changed how times are stored and all 412 tests passed. Recommended action: roll back to release 56 to rule it out, and open a ticket with the provider."
  • 08:26 Bondi Junction front desk, by phone: two patients have called asking whether their appointment has moved to 03:30, and one says she replied C by mistake.
  • 08:31 The SMS provider's status page shows no incidents. You take over from here.

Work it the way the module does: evidence first, a control, and a person checking at each point where it matters. If you want an agent's help, give it these materials and hold it to the same standard. Then write, in the box below:

  1. Diagnosis. What caused this, with the log lines and the code that show it, and a control: a case where the fault does not appear, compared with one where it does. Say whether the agent's stated cause holds, and what evidence decides it.
  2. Impact. Who is affected and how many, and the queries you would run yourself to get the numbers you give to the clinics. Say what will happen next if nothing is done, and when.
  3. The rollback decision. Answer the agent's proposal. What would rolling back to release 56 change, and what would it leave as it is? What do you do instead, in what order, and which of those steps a person must decide and run?
  4. Who is told what. The clinics, and the patients: draft the message the patients get, and say who checks it before it is sent.
  5. Timeline. From the merge to the moment you would call it resolved, in Sydney time, with the log lines' UTC times converted.
  6. The post-mortem's check. Blameless causes: what let this change through, not who. Then the check that would have caught it: a test, a rule in CI, or an alert, written out precisely enough that someone could add it today. Say how you would show it fails against release 57.

Your mark is based on the criteria listed under "What you are marked on".

Open the lab · needs a free Tarmac account to have your work marked