Leanpub Header

Skip to main content

The Second Time Is a Bug

A field workbook for engineering with AI coding agents

The Second Time Is a Bug

Turn each repeated AI coding agent mistake into a small, tested guard.

Interested in this book? Show your support by saying what you'd like to pay for it!

$
PDF
EPUB
About

About

About the Book

The first time an AI coding agent makes a mistake, it is the model’s. The second time, it is a bug in your harness.

You ask your coding agent for a change. It reports success, and the diff looks right. Then you find the one line that is wrong: a price rounded through a float, a test quietly loosened, a button that renders but cannot be seen. A week later, in a new session, the agent makes the same mistake, and you fix it by hand again.

In the Stack Overflow 2025 Developer Survey, the most common frustration with AI tools, named by 66% of respondents, was output that comes close but misses the mark. This book is about closing that gap for good, one mistake at a time.

What the book teaches

One method, applied chapter by chapter. When an agent makes a mistake:

  • Log the incident and find the root cause in your harness, not in the model.
  • Choose a control: a guide that steers the agent before it acts, or a sensor that checks its work afterwards.
  • Choose where it runs: at edit time, at commit, in the build, at deploy, or against the live system.
  • Prove it works by planting the mistake on purpose and watching the guard refuse it.
  • Write down when you will delete it, because guards encode assumptions about models, and those assumptions expire.

The book is built from guards, not from tool features. A guard is a small, readable script with an exit code, so it works with whichever coding agent you use, with git hooks and with any CI system. The wiring for today’s tools sits in one dated appendix, so the rest of the book does not go stale when a settings file moves.

It is also measured. Chapter 12 reports 270 runs of three models on seven tasks, with and without a harness: where the harness made a difference, where it did not, and what it cost.

What is inside

  • 14 chapters in six parts, 252 pages (6 x 9 inches) with 38 diagrams, as PDF and EPUB.
  • 34 pattern cards. Each technique on one card with the same seven fields: symptom, drill, guard, proof, placement, kind of control, and when to retire it. The full cards come as a printable deck (A4 and US Letter, two cards per sheet) that you download as an extra with the book, and Appendix A in the book is a pattern card index, one line per card with its page.
  • 26 runnable drills. Each drill replays one agent mistake (a deleted test, a float in money code, an rm -rf, a package that does not exist, a 900-line diff) in a scratch copy of the companion code and shows the guard catching it. The mistakes are recorded as patches and scripted turns, so every drill runs offline, with no API key and no model, and gives the same result every time.
  • The companion code, free and public on GitHub (book-companion): Invoicer, a small invoicing app written for this book, a deliberately tangled legacy exporter, every guard, every drill, a toy agent loop of two dozen lines, an experiment kit for measuring whether your harness pays, and starter templates. TypeScript on Node.js, zero runtime dependencies, MIT licensed.
  • Templates: an instruction file starter, an incident log, a plan and handoff file, a harness review checklist and hook examples, printed in Appendix B and included as files in the companion code.

Every chapter opens with a failure you can reproduce, shows the control that stops it, and is honest about what that control costs and where it falls short. Each one ends with a checklist you can apply to your own repository this week.

For one reader or a team

  • The Book: the PDF, the EPUB and the printable card deck, for one reader.
  • Team Edition (10 copies): ten copies for people at one organisation. After buying, you get ten download tokens and send each one to a colleague by email, so everyone has their own copy and card deck.

Who it is for

  • Working engineers and tech leads who use a coding agent (Claude Code, Codex, Cursor, GitHub Copilot’s agent or similar) every day and lose time to output that is almost right.
  • Solo builders shipping real products with an agent as their main pair.
  • Anyone responsible for letting agents work in a shared codebase: tests, gates, permissions, dependencies, legacy code and unattended runs.

You need a terminal, Node.js 22.18 or later, git and some patience with small scripts.

Who it is not for

  • Readers looking for an introduction to AI or to prompting. The book assumes you already use a coding agent.
  • Readers who want a manual for one specific tool. The body is deliberately tool-agnostic.
  • Anyone hoping for a productivity figure. The book does not promise a speed-up; it shows you how to measure your own loop.
  • Builders of LLM applications. This is about engineering with agents, not building them.

Read a chapter first

Chapter 6, “Tests the Agent Cannot Game”, is free: download it from the book’s website, secondtimeisabug.com. It covers the seven ways an agent gets a green test run that proves nothing, and four guards that stop them: read-only tests, a test count ratchet, a mutation tester of about 100 lines and a hash-checked “done” file.

Sources

Every statistic and named incident in the book is cited to a published source, and the experiment in Chapter 12 is the author’s own.

Independent publication

This book is independent. It is not affiliated with, sponsored by or endorsed by Anthropic, OpenAI, Anysphere, GitHub, Microsoft, Google or any other AI vendor or tool maker. Product names are trademarks of their owners and are used only to identify those products.

Author

About the Author

Rakesh Menon

Rakesh Menon is the co-founder and product lead at Seerly and a software architect with fifteen years of experience building and scaling web platforms. Previously, he held senior engineering roles at Atlassian, A.P. Moller Maersk, and Publicis Sapient, working across frontend architecture, shared platforms, and engineering practices.

Today, he builds with AI coding agents as part of his everyday work. The Second Time Is a Bug draws on his experience to explore a simple engineering principle: the goal is not to prevent every mistake, but to build systems that stop the same mistake from happening twice.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub