Building Software
Sections

Contents Section 9, Delegating to Agents

Accountability: Owning Code You Did Not Type

What stays yours when agents do the work: the approval, the incident, the license and the dependencies, plus the skills to act on them yourself.

Section 9 of 9, subsection 6 of 6. Depth: do. Core 25 of 25. A 9-minute read.

Mistakes to catch in review

  1. An agent change approved with no evidence behind it: no criterion or eval covers the new behavior, and nobody read its risky code.

  2. A postmortem that names 'AI-generated code' as the root cause, with no owner and no change to tests, review or gates.

  3. A function reproduced nearly verbatim from a copyleft-licensed project and merged into proprietary code with no license review.

  4. An agent stuck in a fix-and-retry loop on a problem it does not understand, with nobody stepping in to take over.

The Change Is Yours Once You Approve It

On Friday afternoon your agent opens a pull request that reworks the invoice page of your billing app. It is 600 lines across eleven files. The tests pass, the description is tidy, and you want to leave. You skim the file list for a minute, click approve, and it ships.

On Saturday morning support escalates to you, because you are on call. Customers in the United States are seeing a red "Overdue" banner on invoices that are due today, along with a warning about late fees. Some have paid twice to be safe. Customers in Europe see nothing wrong.

The agent wrote the code. You are the one being paged, and by Monday someone will ask you why this was approved.

Approval makes you accountable

The service needs a named person or team for incident decisions and follow-up, and a record of who responds and what evidence supported the approval. Approving makes you accountable for that review decision. The team that owns the service remains responsible for operating the result, whoever or whatever produced the diff.

So an approval is a claim: I believe this change is correct, and here is the evidence I relied on. Try saying that about the Friday approval.

The minute it took is beside the point. A one-minute approval can be sound when every criterion the change was built against has an eval, the evals ran on the final diff, and the risky part was small enough to read. The Friday approval rested on the green checkmark and on the description the agent wrote about its own work. The checkmark covered what the tests covered, and no criterion or test said what an invoice due today should show a customer in another time zone. Nobody read the date logic either. That is approval without evidence.

A meaningful approval can name its evidence, in this order:

  • The criteria the change was built against, and the evals or tests that check each one, run on the final diff.
  • The parts you read line by line because no criterion reaches them or a miss would be costly, such as date handling, money, or anything touching permissions.
  • Whether you ran the change yourself.
  • The dependencies, configuration and database changes it added.

Criteria and evals come first because they check every later change against the same target. Reading goes where they cannot reach. If you cannot name evidence for the behavior that worries you, ask for the missing criterion and an eval that exercises it, or read that part yourself. If the evidence is still insufficient, hold approval. That costs less than this approval cost your customers.

On call for code you did not write

In 1985 Peter Naur argued that a program is really the theory in its programmers' heads: why it is shaped the way it is, what each part is for, how it would change to meet a new need. The source code is a partial record of that theory. When an agent writes the code, the theory lives nowhere unless someone builds it.

Writing the criteria and reading the risky parts are two of the ways you build it. An approval with neither leaves you on call for a program nobody understands.

So the skill that matters on Saturday morning is diagnosing a bug yourself, without asking an agent to guess.

Start from the symptom and the pattern. Only customers in the United States are reporting it, and only around the due date. A bug that depends on where the user is suggests time zones. The banner comes from a function the agent added:

TypeScript
export function daysUntilDue(dueDate: string, now: Date = new Date()): number {
  const due = new Date(dueDate);            // dueDate looks like "2026-02-09"
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  return Math.floor((due.getTime() - today.getTime()) / 86_400_000);
}

The page shows "Overdue" when this returns a negative number. Read each line and ask what value it produces. JavaScript parses a date-only string like "2026-02-09" as midnight UTC. The today line builds midnight in the browser's local time zone.

In New York in February, midnight UTC on 9 February is 19:00 on 8 February local time. So due is five hours before today, the difference is negative, and Math.floor rounds it down to −1. The invoice is due today and the page calls it overdue. In Berlin, midnight UTC falls after local midnight, the difference is positive, and the bug hides.

Two timelines running from earlier to later. New York, UTC −5: a purple 'due, midnight UTC = 19:00, 8 Feb' comes 5 hours before 'today, local midnight, 9 Feb', leading to a purple 'Overdue, Math.floor gives −1'. Berlin, UTC +1: 'today, local midnight, 9 Feb' comes before 'due, midnight UTC, 9 Feb', leading to 'Positive, the bug hides'. A note reads 'behind UTC, due comes first'.
In New York, midnight UTC lands five hours before local midnight, so due comes before today and Math.floor turns the gap into −1. In Berlin the order flips and the bug hides.

Next, reproduce it in a test before you fix anything. The test suite passed because CI runs in UTC, where the two midnights are the same. Setting the time zone for the test run exposes it:

TypeScript
// due.test.ts, run with: TZ=America/New_York bun test ./due.test.ts
import { expect, test } from "bun:test";
import { daysUntilDue } from "./due.ts";

test("an invoice due today is due in 0 days", () => {
  const now = new Date(2026, 1, 9, 10, 0); // 9 Feb 2026, 10:00 local time
  expect(daysUntilDue("2026-02-09", now)).toBe(0);
});

Under TZ=UTC this passes. Under TZ=America/New_York it fails with Expected: 0 and Received: -1. Now you have the bug pinned down in a form that will stay caught.

For this product an invoice is overdue by the viewer's local calendar date. The fix extracts that date from now, then represents both dates as UTC midnights so the subtraction is a whole number of days:

TypeScript
const DAY_MS = 86_400_000;

export function daysUntilDue(dueDate: string, now: Date = new Date()): number {
  const [y, m, d] = dueDate.split("-").map(Number);
  const due = Date.UTC(y, m - 1, d);
  const today = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate());
  return (due - today) / DAY_MS;
}

Both values are now midnight UTC on a calendar date, so the difference is always a whole number of days, including across daylight-saving changes. The test passes in New York and in UTC. Add a CI job that runs the date tests under at least one time zone behind UTC and one ahead of it, so the next change to this code gets the same check.

A playground cannot change your browser's time zone, so the block below models each viewer with a fixed offset from UTC and runs both versions for an invoice due today:

TypeScriptRuns in your browser
const DAY_MS = 86_400_000;
const HOUR_MS = 3_600_000;

// A playground cannot change your browser's time zone, so this models one:
// a viewer whose clock is offsetHours from UTC (February, so no summer time).
// It returns the viewer's local year, month and day for an instant.
function localDate(instant: number, offsetHours: number): [number, number, number] {
  const shifted = new Date(instant + offsetHours * HOUR_MS);
  return [shifted.getUTCFullYear(), shifted.getUTCMonth(), shifted.getUTCDate()];
}

// The agent's version: the due date at midnight UTC, today at the viewer's local midnight.
function buggyDaysUntilDue(dueDate: string, now: number, offsetHours: number): number {
  const due = new Date(dueDate).getTime();
  const [y, m, d] = localDate(now, offsetHours);
  const today = Date.UTC(y, m, d) - offsetHours * HOUR_MS; // local midnight as an instant
  return Math.floor((due - today) / DAY_MS);
}

// The fix: both calendar dates as UTC midnights.
function fixedDaysUntilDue(dueDate: string, now: number, offsetHours: number): number {
  const [dy, dm, dd] = dueDate.split("-").map(Number);
  const [y, m, d] = localDate(now, offsetHours);
  return (Date.UTC(dy, dm - 1, dd) - Date.UTC(y, m, d)) / DAY_MS;
}

const viewers: [string, number][] = [["Los Angeles", -8], ["New York", -5], ["London", 0], ["Berlin", 1], ["Tokyo", 9]];
for (const [city, offset] of viewers) {
  const now = Date.UTC(2026, 1, 9, 10) - offset * HOUR_MS; // 10:00 on 9 Feb, local time
  console.log(`${city.padEnd(11)} buggy: ${buggyDaysUntilDue("2026-02-09", now, offset)}  fixed: ${fixedDaysUntilDue("2026-02-09", now, offset)}`);
}

Every viewer behind UTC sees the invoice as a day overdue under the agent's version, and every viewer at or ahead of UTC sees it correctly. That split is why European customers saw nothing wrong.

A postmortem that changes something

On Monday a draft postmortem appears. Its root cause reads "incorrect date logic in code generated by the agent", and its only action item is "hotfix deployed".

That line names the function and whoever typed it. A person could have written the same function, and the next one will pass through the same gaps. The useful question is which defences were in place and why each one let the bug through. Richard Cook's "How Complex Systems Fail" makes the point that failures in complex systems have several contributing causes, and that picking one of them as the root cause is a story told after the fact.

Tests ran only in UTC, so a whole class of time-zone bugs could not fail in CI. The approval had no evidence for the date logic: no criterion covered an invoice due today in another time zone, and nobody read the code. The change went to every customer at once. A staged rollout would have limited the exposure, but nothing throws in this bug and the error rate stays flat, so noticing it also needed a check of invoice status for users in an affected time zone.

Left to right, `daysUntilDue`, the agent's function, gets past three defences, each with a gap: tests that ran only in UTC, an approval given with the date logic unread, and a rollout to every customer at once, reaching US customers, who see Overdue. Under each of the three defences a dashed arrow leads to its corrective action and owner: a New York test, billing maintainer; read line by line, team lead; a staged rollout, release owner. A note reads several causes, no single root.
The bug got past three separate defences on its way to customers. Each gap gets its own corrective action with an owner, instead of one root cause.

Each of those becomes a corrective action with an owner and a date. The billing maintainer adds the criterion "an invoice due today shows as due today in every time zone", checked by a New York regression test, by Friday. The team lead adopts a review rule that date and money code is read line by line. The release owner puts billing changes behind a staged rollout with that status check.

Writing "AI-generated code" as a root cause leaves the failed review and test controls unexplained, so assign an owner and a date to each corrective action instead.

Agent output as supply chain

Review an outside contribution for its source, license obligations and added dependencies. Agent output deserves the same review, for a concrete reason: models can reproduce code they were trained on, sometimes nearly word for word, and most often when that code is common in public repositories.

If a function in the agent's diff matches code from a GPL-licensed project, pause the merge and have the licensing reviewer establish its source, its license and whether permission is needed. If you distribute a combined program that incorporates GPL-covered code, GPL obligations generally apply to the combined program, including making its source available to the people who receive it. Private use and separate, independent programs need a different analysis.

AGPLv3 also requires a modified covered program that supports remote interaction to offer its corresponding source to those network users. For a proprietary product, a real match is a conflict someone has to resolve, by removing and rewriting the code, by getting permission, or by complying with the license. How the code is used and distributed in your product is a question for whoever handles licensing at your company, and you are the one who has to raise it.

A suspect function (copyright line, odd style) points to Search public code, which points down to a purple Licensing reviewer box (merge paused on a GPL match). The reviewer branches into three outcomes: Rewrite, Get permission and Comply.
A copyright line or an odd style sends the reviewer to search public code. A GPL match pauses the merge until the licensing reviewer decides to rewrite, get permission or comply.

You can catch this in review. A function with unusually specific comments, a copyright line, or a coding style that does not match the rest of your project deserves a search against public code. Snippet-matching scanners exist that compare code against open-source projects, and some coding assistants can block suggestions that match public code. None of them sees everything, so the reviewer's eye still counts.

Dependencies are the other half. An agent that adds a package to fix a small problem has brought in a new maintainer, a new license, and every package that one depends on. Read the dependency diff as carefully as the code diff.

Keep a record of where each change came from. Record the agent and model in a commit trailer, and list the verified licenses of new dependencies in the pull request. When a license question or a bad model version turns up months later, that record tells you which commits to look at.

Knowing when to take the controls

In 1983 Lisanne Bainbridge described what she called the ironies of automation. Designers automate the tasks that are easy to automate and leave the operator the rest, which are the rare, hard cases. At the same time, the operator no longer practices the everyday work that would keep their skills ready for those hard cases. In aviation it shows up as pilots losing hand-flying skill, and in 2013 the US Federal Aviation Administration urged airlines to give pilots more chances to fly manually.

The same thing happens when agents write most of your code. You spend your days reviewing and prompting, and then an incident arrives that the agent cannot solve, and you are out of practice. Regularly fix bugs and write features without assistance. Read the code those changes depend on.

There are also clear signals that it is time to stop directing and do the work yourself:

  • The agent has tried to fix the same failure three times and it still fails.
  • You cannot explain why its last attempt did not work.
  • The problem is new to this codebase, with no similar code for the agent to follow.
  • The code controls security or money.

If repeated patches fail and the agent cannot say what each result establishes, stop the loop. Keep the useful tests and observations, remove the speculative changes, and reproduce the failure yourself the way you did with the invoice bug.

Recovery before approval

Recovery is part of what you approve. Before approving, record which deployment you would restore, and check whether reverting or disabling the feature is safe with the data as it is now. If the change ran a migration that a revert cannot undo, name the forward fix instead. A forward fix restores service without rolling anything back.

Put the recovery steps and the team on call for the service in the pull request description, next to the new dependencies and their licenses.

Check your understanding

8 questions on this lesson. Pick an answer to see whether it holds and why.

  1. 1You are on call. Users in California report that Saturday, 7 March 2026 is treated as a weekday by this agent-written helper. Users in Germany see it as a weekend. What is the cause?
    TypeScript
    function isWeekend(dateStr: string): boolean {
      const day = new Date(dateStr).getDay(); // dateStr looks like "2026-03-07"
      return day === 0 || day === 6;
    }
    Show the answer

    Answer A. new Date("2026-03-07") is midnight UTC, which is 16:00 on Friday 6 March in California, so getDay returns 5. In Germany the same instant is already Saturday. getDay counts from Sunday as 0, and a date-only string parses fine; it just parses as UTC.

  2. 2A colleague asks why you approved a 300-line agent change to the payment retry logic in five minutes. Which answer describes an approval backed by evidence?
    Show the answer

    Answer C. Evidence is something checked against the target: criteria with evals that ran on the final version, plus a line-by-line read of the code where a mistake moves money. Five minutes is enough when that evidence exists. A green build covers only what its tests cover, the description is the agent's account of its own work, and a track record says nothing about this change.

  3. 3An agent's diff for your company's proprietary desktop app, which ships to customers, adds a retry helper that starts like this. What do you do?
    TypeScript
    /*
     * Copyright (c) 2014 The Fastqueue Authors
     * SPDX-License-Identifier: GPL-3.0-or-later
     */
    export function backoffDelay(attempt: number): number {
    Show the answer

    Answer B. The header says this code likely came from a GPL project, and the app is distributed, so the license may impose obligations on the whole program. Deleting the header hides the evidence without changing where the code came from. Credit alone does not meet the GPL's terms, and the model having typed it does not erase the original authors' rights.

  4. 4An agent has made four patches for a checkout test that fails about one run in five. Each time it says "this should fix the race", and the test still fails. What do you do?
    Show the answer

    Answer C. Four failed patches with no account of what each one ruled out means the agent is guessing. Retrying the test hides a real race from everyone, including the customers who hit it. Reproducing the failure yourself rebuilds the understanding nobody on the team has yet.

  5. 5An agent-written migration dropped a column that a nightly reporting job still read, and the reports were blank for two days. Which postmortem action item makes the next one less likely?
    Show the answer

    Answer D. A person could have written the same migration, so banning agents leaves the gap open: nothing checked whether anything still read the column. A check with an owner and a date closes that gap for every author. The hotfix restored service, and a reminder to be careful changes no test, review or gate.

  6. 6An agent-written change includes this migration. Before you approve it, what is the recovery plan?
    SQL
    ALTER TABLE invoices DROP COLUMN legacy_status;
    Show the answer

    Answer B. Reverting the code does not run the migration backwards, and the column's data is gone once it runs. A feature flag can switch off new code but cannot restore a dropped column either. Recovery is part of what you approve, so the plan belongs in the pull request before the merge.

  7. 7Months from now a model version is found to have produced subtly wrong date handling. What record lets you find every commit it wrote?
    Show the answer

    Answer A. A trailer travels with each commit, so a search of the history finds every change that model produced. Transcripts on laptops get deleted and are not tied to commits, titles do not name the model, and logs kept for 30 days are gone by the time the question comes up.

  8. 8Two agent changes to subscription billing were approved this week. Priya approved a 400-line renewal change in four minutes: every criterion for it, including "a renewal never charges a cancelled subscription", has an eval that passed on the final diff, and she read the 30 lines that move money. Sam approved a 120-line grace-period change after an hour of scrolling, and no test or criterion covers the grace-period rule. Which statement is accurate?
    Show the answer

    Answer B. The failure is approval without evidence, and time spent proves nothing by itself. Priya's criteria and evals check the behavior on the final diff, and she read the part where a mistake costs money. Sam's hour of scrolling left the grace-period rule with nothing that checks it, now or on the next change. A second agent reading the same diff adds an opinion with no independent check behind it.

You understand it when you can

Drill

An agent-written change to a refund service caused a weekend outage, the draft postmortem says 'root cause: AI-generated code' with no action items, and the same change added a 200-line function copied from a GPL-licensed project. Find what the postmortem gets wrong about ownership, the licensing problem you now own, and the evidence the approval was missing that would have caught both.

Topics

Owning the Result
Responsibility for a change stays with the person or team that approved it, whoever or whatever typed it.
On Call for Code You Did Not Write
Being the one paged means understanding agent-written code well enough to diagnose it under pressure.
Provenance, Licensing and Generated Code as Supply Chain
Treating agent output like any third-party contribution, reviewed, attributed and traceable to its source, including the license obligations of code a model reproduces and a record of which agent and model produced each change.
Meaningful Approval
Approval as a decision backed by evidence: the change's criteria and their evals first, then line-by-line reading where risk demands it, and the willingness to say no.
The Ironies of Automation: Deliberate Practice and Taking the Controls
Bainbridge's 1983 finding that automation leaves people the hardest tasks with the least practice, the regular hand-flying that counters it, and the signals (novel problems, security-critical code, repeated agent failure) that tell you to do the work yourself.

Further reading

Start here

Short reads

Watch

  • Children Of The Magenta Line. Capt. Warren Vanderburgh, 1997. 26-minute talk.

    An American Airlines training captain explains how pilots who lean on automation lose the ability to take over, and teaches choosing the level of automation that fits the situation, including flying by hand.

  • Velocity 2012: Richard Cook, "How Complex Systems Fail". Richard Cook, 2012. 28-minute talk.

    The author of 'How Complex Systems Fail' explains to an operations audience why a single root cause like 'AI-generated code' is a misleading story, and why the people at the sharp end are what keep the system safe.

  • SREcon26 Americas - The Ironies of AI². J. Paul Reed, 2026. 41-minute talk.

    A resilience-engineering practitioner applies Bainbridge's ironies of automation to AI in operations: how AI changes who can diagnose failures and what the on-call engineer is left doing.

Books

  • The Field Guide to Understanding 'Human Error'. Sidney Dekker, 2014, 3rd edition.

    Shows why labelling a cause as 'human error', or by extension 'AI error', ends the investigation too early, and how to write a postmortem that changes tests, reviews and gates instead of blaming someone.

  • The Glass Cage: Automation and Us. Nicholas Carr, 2014.

    Uses aviation and medicine to show how automation wears down the skills of the people supervising it, which is why an engineer needs regular practice doing the work without assistance.

  • Software Supply Chain Security: Securing the End-to-End Supply Chain for Software, Firmware, and Hardware. Cassie Crossley, 2024.

    Covers provenance, SBOMs and third-party code intake. The same controls apply when agent output is treated as an outside contribution that must be attributed and license-checked.

Primary sources