2026-11-27 16:30 UTC

26 offline drills teach safeguards for AI coding-agent mistakes

state: expiredheat: lowuncertainty: mediumrelevance: mediumagent-testing failure-reproduction coding-agent-reliabilityrakeshmenon

What is this?

The GitHub repository is companion code for *The Second Time Is a Bug*, a field workbook about engineering with AI coding agents. It contains 26 drills that reproduce specific agent mistakes in throwaway copies and demonstrate guards catching them; the drills need no model, API key or network. The repo also includes a sample app, guard scripts, a toy agent and an experiment kit. This supports describing it as a hands-on reliability and testing resource, but the supplied evidence does not establish how well its approach improves outcomes in real projects.

Why it matters

A practical, unusually complete teaching resource for making coding-agent failures reproducible and checking that safeguards catch them. The drills span common risks—from weakened tests and money-handling bugs to destructive commands and irreversible migrations—and can run without a live model, making them useful for learning or adapting a reliability workflow. This is a book companion, not evidence that its guards measurably improve production outcomes or that the approach works across agents and codebases.

Current assessment

The repository describes 26 drills, each reproducing an agent mistake in a scratch copy and showing a guard catch it. It also provides guard scripts and a gate, a small app and legacy example, a toy agent, templates, and an experiment kit with seven tasks and hidden acceptance tests. Most drills require no model, API key, or network; two browser-based drills need Playwright Chromium. These are repository-author descriptions, not independently validated effectiveness results. The supplied search results do not establish adoption or comparative impact. Useful as a hands-on reference for engineering teams seeking concrete checks around AI-generated code; evaluating whether the harness pays off requires running the experiment and testing it in other projects.

Measured heat

no measured readings yet — the hourly heat pass fills this in

How the heat travelled

10-15 09:14⭐ origin directly observedShow HN: Reproducible failure drills for AI coding agents
rakeshmenon on hacker news
—
10-15 09:14amplified on hacker news 👑hn.story.50101157
rakeshmenon
peak 1 · 0 comments · 105% of case engagement
10-15 09:20our radar first saw it · +0.1hdiscovery anchor: hn.story.50101157—

Evidence (1) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hn ⭐Show HN: Reproducible failure drills for AI coding agents
Retrieved article excerpt

Open article · Retrieved 2026-10-15T09:28:05.293807+00:00

# The Second Time Is a Bug: companion code

Companion repository for the book *The Second Time Is a Bug: A field workbook for
engineering with AI coding agents*. Everything the book shows runs here:

- **Invoicer** (`app/`), a small invoicing app for freelancers, the running example.
- **billing-export** (`legacy/`), a deliberately tangled 2014 exporter for the legacy chapter.
- **Guards** (`guards/`), one small script per guard the book builds, and the gate that runs them.
- **Drills** (`drills/`), one per agent mistake. Each makes the mistake in a scratch
  copy and shows the guard catching it. No API key, no model, no network.
- **A toy agent** (`toy-agent/`), an agent loop of two dozen lines driven by a scripted fake model.
- **Templates** (`templates/`) to copy into your own repository, and an **experiment kit**
  (`experiment/`) for measuring whether the harness pays, with the author's own
  run records in `experiment/results/`.

TypeScript on Node, with zero runtime dependencies and no build step.

Book website: <https://secondtimeisabug.com>

The code the book quotes, and the messages the guards and drills
print, are kept within 64 columns, the width of the book's printed
page. Guard output wraps with a hanging indent
(`guards/lib/wrap.ts`).

## Requirements

- Node.js 22.18 or later. Node runs the `.ts` files directly (type stripping is on by
  default from 22.18). Check with `node --version`.
- git (the drills make throwaway git repositories in your temp folder).
- For the two browser drills (D13, D14) and `npm run e2e`: Chromium for Playwright,
  installed once with `npx playwright install chromium`.

## Quickstart

```
npm install            # dev tools only: typescript, @types/node, @playwright/test, axe-core
npm test               # unit tests and the legacy golden master
npm run typecheck      # tsc --noEmit
npm run gate           # every guard, fast ones first; refuses on any failure
npm run drill D06      # one drill: the float-money guard catches a parseFloat
npx playwright install chromium   # once, for drills D13 and D14
npm run drills         # all 26 drills and a summary table (a few minutes)
npm run e2e            # browser and accessibility tests
npm start -- --seed-demo   # Invoicer on http://127.0.0.1:3000 with a demo client
```

Without Playwright's Chromium, `npm run drills` does not run D13 and D14. It says
so and ends with exit code 1, because the run is not complete:

```
24 of 26 drills behaved as expected; 2 need Chromium (npx playwright install chromium).
```

Install Chromium and run it again. The runner's own tests, which are not part of
`npm test`: `node --test drills/test/*.test.ts`.

`npm run gate` compares your working tree with `HEAD`. Outside a git repository the
diff-based guards report "skipped" rather than guessing. In CI, set
`GUARD_BASE=origin/main` to check a whole branch, as `.github/workflows/gate.yml` does.

## Folder map

| Path | What it is |
| --- | --- |
| `app/src/domain/` | Pure rules: money in integer cents, totals, due dates, reminders, CSV |
| `app/src/db/` | node:sqlite storage and SQL migrations with up and down steps |
| `app/src/http/` | JSON API on node:http, including `/health` and `/version` |
| `app/src/ui/` | Server-rendered list page and the static invoice form |
| `app/src/jobs/` | Overdue-reminder job and a tiny scheduler |
| `app/test/`, `app/e2e/` | Unit tests (node:test) and browser tests (Playwright, axe-core) |
| `legacy/` | `billing-export.js` and its characterisation (golden master) tests |
| `guards/` | The guards, `gate.ts`, `seeded-defects.ts`, `guard-audit.ts`, shared `lib/` |
| `drills/` | `run.ts` and one folder per drill (`README.md`, `drill.json`, patch or script) |
| `toy-agent/` | `loop.ts`, `scripted-model.ts`, `tools.ts`, `unattended.ts` and scripts |
| `templates/` | `AGENTS.md` starter, incident log, plan, harness review checklist, hooks |
| `experiment/` | Chapter 12 protocol, seven tasks with hidden acceptance tests, `score.ts` |
| `plans/` | Where plan and handoff files go (`templates/plan.md`) |
| `.github/workflows/gate.yml` | CI: type check, tests and the gate against the branch's base, then browser tests and mutation runs |
| `.harness/` | Guard state: test baseline, approved dependencies; at run time, the guard log and test evidence |
| `AGENTS.md` | This repository's own instruction file, built from the template |
| `DRILLS.md` | Every drill's commands and real output, generated by `npm run drills:docs` |

## Drills

Run one with `npm run drill DNN`. Each folder's `README.md` says what the mistake is,
what you will see, and how to try the same mistake with a real agent.

| ID | Title | Chapter | Card |
| --- | --- | --- | --- |
| D01 | [Toy loop](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D01-toy-loop) | 1 | P01 |
| D02 | [Incident log](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D02-incident-log) | 2 | P02 |
| D03 | [Coupling](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D03-coupling) | 3 | P04 |
| D04 | [Instructions lint](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D04-instructions-lint) | 3 | P03 |
| D05 | [Plan required](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D05-plan-required) | 4 | P07 |
| D06 | [Float money](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D06-float-money) | 5 | P11 |
| D07 | [Gate](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D07-gate) | 5 | P12 |
| D08 | [Layer boundary](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D08-layer-boundary) | 5 | P13 |
| D09 | [Deleted test](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D09-deleted-test) | 6 | P15 |
| D10 | [Skipped test](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D10-skipped-test) | 6 | P14 |
| D11 | [Hollow assertion](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D11-hollow-assertion) | 6 | P16 |
| D12 | [False done](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D12-false-done) | 6 | P17 |
| D13 | [Hidden button](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D13-hidden-button) | 7 | P18 |
| D14 | [Accessibility](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D14-a11y) | 7 | P18 |
| D15 | [Smoke](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D15-smoke) | 7 | P19 |
| D16 | [Seeded defects](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D16-seeded-defect) | 7 | P20 |
| D17 | [Destructive command](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D17-destructive-command) | 8 | P21 |
| D18 | [Secret in diff](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D18-secret-in-diff) | 8 | P22 |
| D19 | [Irreversible migration](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D19-irreversible-migration) | 8 | P23 |
| D20 | [Phantom package](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D20-phantom-package) | 9 | P24 |
| D21 | [Dependency drift](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D21-dependency-drift) | 9 | P25 |
| D22 | [Legacy refactor](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D22-legacy-refactor) | 10 | P27 |
| D23 | [Diff budget](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D23-diff-budget) | 10 | P28 |
| D24 | [Bounded loop](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D24-bounded-loop) | 11 | P30 |
| D25 | [Merge gate](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D25-merge-gate) | 11 | P29 |
| D26 | [Guard audit](https://github.com/second-time-is-a-bug-book/book-companion/blob/main/drills/D26-guard-audit) | 13 | P34 |

## How the guards report

Every guard prints `name: ok (...)` or `name: FAILED` followed by one entry per problem:
where it is, what is wrong, and what to do next. They are written to be read by an
agent as much as by a person. Exit code 0 means pass, 1 means fail;
`destructive-command.ts` uses 2 to block, the usual convention for agent hooks. Each
time a guard fires it appends a line to `.harness/guard-log.jsonl`, which
`guards/guard-audit.ts` reads to find guards ready to retire.

## Network

Nothing here needs the network after `npm install`, except the optional
`node guards/package-check.ts --online`, which asks registry.npmjs.org.

## Licence

Code: MIT, see `LICENSE`. The book's text is not part of this repository.
rakeshmenon10

Interpretation history

Decision trace