T0ha666

T0ha666

A $63 Mistake in Production: How an AI Agent's Loop Escaped Without Guards

An automated trigger fired every two minutes for 8 hours. 243 agent runs. 31M tokens. $63 wasted. The problem: nobody noticed until morning.

This is a case study in production safety when AI agents are on the loop — and a cautionary tale about human approval gates.

The technical breakdown:

  1. An Ash/Oban cron trigger polling GitHub every 2 minutes — seemed fine on review
  2. The check was level-triggered (state-based) instead of event-triggered
  3. GitHub review feedback is immutable history, not a dismissable flag
  4. So the agent kept trying to fix the same feedback, over and over
  5. No cost counter, no alert, no visibility — just a morning invoice

Why the existing guards failed:

  • Freshness check existed but lived on an unreachable code path
  • Attempt counter got reset to 0 on every pass (accidentally disarmed)
  • Branch order made recovery impossible once one reviewer approved

The real lesson: when you put an expensive actuator (LLM tokens) on a loop, “harmless redundancy” stops being a category. Every pass has to earn itself.

Full postmortem:

Built with Elixir/Phoenix/Ash, and the hardest part wasn’t the code — it was the code review.

Most Liked

aicost_tools

aicost_tools

$63 / 31M tokens is about $2.03 per million blended across those 243 runs, so each pass averaged roughly 127k tokens — exactly the kind of loop where a level-triggered poll quietly becomes a meter. Two cheap guards that would have caught this before morning: a hard spend or token ceiling on the actuator itself (kill the Oban job when the cumulative prompt+completion for that trigger crosses a few dollars), and an alert on “same review thread / same feedback hash seen N times,” because immutable GitHub review history will never clear a level check. Seat plans hide this until the invoice; an API key at least makes every retry visible as line items, but only if something is watching the running total rather than a single-request freshness flag that can be skipped. The attempt counter resetting to 0 is the scarier bug than the missing alert — once the safety latch disarms itself, redundancy stops being free.

Where Next?

Popular Ai topics Top

tonyxrandall
The rapid development of AI (artificial intelligence) has opened up new ethical frontiers at a startling pace. As the impact of AI is so ...
New
masterhood13
[Project Update] Part 2 of My Dota 2 Match Outcome Predictor – Now Available! Hey DevTalk community! I just published the second part o...
New
ozornin
I recently wrote an essay on effects of AI, how it all can become real bad, and how we can avoid it. I started writing the post intend...
New
John-BoothIQ
TL;DR: Good: AI is great at Elixir. It gets better as your codebase grows. Bad: It defaults to defensive, imperative code. You need...
New
vipulbhj
Agents execute at scale. Accountability doesn’t transfer. The founder who delegates everything to AI doesn’t become a CEO with thousands ...
New
aralroca
I wrote about a different approach to AI agents. Instead of building bots that screenshot your screen and click buttons (like OpenAI Oper...
New
xiji2646-netizen
I have been evaluating the three major AI video generation APIs for a project and figured this might save others some research time. Curi...
New
xiji2646-netizen
Anthropic announced Claude Mythos Preview this week – and then said it will not release it to the public. Their reasoning: the model’s cy...
New
alvinkatojr
Found this article a refreshing take on this obsession with AI tokens and “tokenmaxing”. Read and enjoy! :slight_smile:
New
T0ha666
An automated trigger fired every two minutes for 8 hours. 243 agent runs. 31M tokens. $63 wasted. The problem: nobody noticed until morni...
New

Other popular topics Top

PragmaticBookshelf
Learn from the award-winning programming series that inspired the Elixir language, and go on a step-by-step journey through the most impo...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
PragmaticBookshelf
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1147 29994 760
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New
PragmaticBookshelf
Overarching tutorial for Python beginner and intermediate developers that teaches web development with the Flask framework. Miguel Gr...
New
PragmaticBookshelf
Fight complexity and reclaim the original spirit of agility by learning to simplify how you develop software. The result: a more humane a...
New