AI

One ADR made a US$ 0.25 AI review beat the US$ 25 one

On this page

Recently I got to work on a tiny project we use internally. I added a couple of features and realized the dev environment didn’t have the best DX.

Working on it, I found a few interesting bugs. An email that should go out on the last business day of the month was never sent. Even worse, because of one rule, a job was dispatched 10 million times.

"Damn, AI is terrible. I hate this kind of slop…" – you might think.

I have to tell you: AI has nothing to do with it. A human did that.

While investigating, with the help of AI, I realized the bug had been in the codebase since December 2021. It stayed inert for about four years, until February 2026 came.

Yeah, this and other critical bugs are spread across human codebases. But this article is not about what humans or AI can do.

Our job is done by AI. Every single engineer at Codeminer42 is proficient at agentic work, and the history behind this bug tells why.

Let’s find out.

The bug

The bug happens in the flow that sends reminders on the last business day of the month. The code has a snippet like this:

def end_of_month_notification
  last_day = last_business_day()

  if last_day.today?
    # send the emails
  else
    # reschedules itself to the last business day
    EndOfMonthReminderJob.set(wait_until: last_day.noon).perform_later("end_month")
  end
end

This code got to main. It has good enough tests, but it missed a crucial thing: code review.

Yeah, I found this by investigating. But I went further with the following question: would a code review have caught it?

We will answer that soon.

Why didn’t it break for years?

Okay, you got the bug. But why did it work all those years? The answer is simple. Finding the pieces to answer it wasn’t.

I realized the issue only happened in February 2026. But why?

Well, the job is first triggered by a scheduler that sits in Heroku. That scheduler runs it as a rake task on the 28th of every month:

if [ "$(date +%d)" = 28 ]; then bundle exec rake notification:end_of_month_notification; fi

Every month, regardless of the year, has at least 28 days, so it makes sense. There’s a case the author didn’t take into consideration, though: in 2026, February 28 falls on a weekend, so February 27 is the last business day.

If you’re following, you’ve noticed we get an infinite loop here. The job execution looks like this:

Feb 28 - last business day is Feb 27, not today -> schedule for Feb 27 12:00
Feb 27 12:00 is in the past -> Sidekiq runs it now
Feb 28 - last business day is Feb 27, not today -> schedule for Feb 27 12:00
... (until midnight)
Mar 1  - last business day is Mar 31 -> schedule for Mar 31, loop ends

It ran ten million times. Not that harmful: it just burned some CPU cycles doing it.

Would a code review catch this bug?

A human code review, with context, could catch such a specific bug, of course. It depends on the context: whether it’s been a long Friday or not, and so on.

But what about an AI code review?

I’ve been experimenting with and tuning code review in some of the teams I lead here at Codeminer42. So I’m very interested in this kind of experiment.

I put it to the test. I set the codebase back to the commit right before the one that introduced the bug, created a repo with it, and opened a PR with the broken commit.

NOTE: what a great time we live in, when we can set up this kind of experiment. Amazing!

With everything in place, I asked Claude Code to review it using its /code-review skill. I repeated this process a few times, all on Opus 5.5:

EffortRunsCaught the loopAvg cost per runAvg time per run
medium53US$ 0.140.7 min
high55US$ 0.170.9 min
max33US$ 25.2338.7 min

max is pretty effective, but it’s way more expensive: US$ 25.23 per run on average, against cents on high and medium.

Wall time is also an important component: max took almost 39 minutes per run. It really does a lot of things!

It’s important to say that it only had the codebase and the PR. It knew nothing about when the job would run. It was only asked to review the PR, not to look for this bug specifically.

  • Prompt: /code-review [medium|high|max] PR #1
  • Environment: sandboxed, no WebFetch, no WebSearch, no other skills or MCP servers

Can we make it better?

8 out of 10, summing high and medium, is about 80% accuracy. Kind of good, but I think my bag of matrices can do better, and my job as a human is to make that happen.

Allowing your agent to do a better job reduces your cognitive load.

In the context of this PR, there’s one thing the agent doesn’t know: the date the scheduler triggers the job. I didn’t know it either, and it was pretty bad.

This happens from time to time in software teams. Some decision is made in an obscure call, and a week later nobody remembers why things are the way they are.

For example: why isn’t the job scheduled for the last business day right on the first day of each month? Why does it trigger on the 28th and not on any other day close to the end of the month?

These are reasonable questions. They might have clear and reasonable answers that assume some trade-off, but we won’t know them. I don’t even have a way to contact the dev who implemented it, or whoever decided how it works.

Effectiveness of ADRs

Recording decisions, with their pros and cons, is a way to keep the whole team on track, including your agent. If the Heroku Scheduler entry had been written to the repo as a record, I’d have had an easier life while debugging this.

If it’s good for me, it’s good for the agent. That’s why ADRs are mandatory in Codeminer42 projects.

So I set everything up again. This time the PR carried ADRs, the ones we set up with our ADR skill.

# ADR 0002 - End-of-month fill punch reminder

## Decision

1. `EndOfMonthReminderJob` sends the reminder on the **last business day** of the month.
   If that day is not today, the job schedules itself for noon of that day.
2. A new rake task, `notification:end_of_month_notification`, enqueues the job.
3. A new Heroku Scheduler entry starts it on the 28th:

   | Command | Frequency |
   |---|---|
   | `if [ "$(date +%d)" = 28 ]; then bundle exec rake notification:end_of_month_notification; fi` | Daily at 12:00 UTC |

With that in place, I ran the experiment again. Regarding the loop, Claude got it 10 out of 10. I didn’t even run max: high was good enough.

Not only did the accuracy improve, it also said the bug would happen in February 2026, every single time. In some runs it even named other future dates when the loop would happen!

Conclusion

AI code review caught the 10-million-jobs loop and found about four more issues. I validated those issues, and they were very important fixes.

You must invest in the harness of your project. You must use ADRs. They’re good for you and for your team, and they guide the agent to a better job while writing and reading code.

ADRs and other ways of improving any project’s harness are what we deliver in our repo of skills. Check it out.

Thanks for reading! See you next time.

We want to work with you. Check out our Services page!

We want to work with you

The engineers who write here are the same ones who join client teams. Let’s build something that grows with your business.

Book a call