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...
A field workbook for engineering with AI coding agents
Interested in this book? Show your support by saying what you'd like to pay for it!
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:
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
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.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
Who it is for
You need a terminal, Node.js 22.18 or later, git and some patience with small scripts.
Who it is not for
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.
About the Author
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.
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
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
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
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.