"Just Retry" Is Not Error Handling: Building AI Agent Workflows That Survive 3am
An agent workflow that can't tell you what it did, can't be replayed, and can't fail gracefully isn't production — it's a demo. Everyone's shipping AI agents now. Most of them share the same three hidden bugs, and al
An agent workflow that can't tell you what it did, can't be replayed, and can't fail gracefully isn't production — it's a demo.
Everyone's shipping AI agents now. Most of them share the same three hidden bugs, and all three show up the week you stop watching:
- A provider outage eats the run silently — no log, no retry, no trace
- One flaky endpoint fails the whole pipeline — because there's one path and no fallback
- Secrets live in the workflow JSON — and get exported, shared, committed
Here's the checklist I run before calling any agent workflow production-ready.
1. Every run writes a trace before it does anything else
First line of the run: JSON object with a run id, timestamp, and input. Every step appends: model used, tokens, latency, outcome. Crash mid-run? The trace shows exactly where and lets you re-run from that step.
{"run": "r-881", "ts": "2026-11-29T02:14:01Z", "step": "route", "tier": "fast", "endpoint": "prov-a", "ok": true, "ms": 812}
{"run": "r-881", "ts": "2026-11-29T02:14:03Z", "step": "extract", "endpoint": "prov-a", "ok": false, "err": "HTTP 429"}
{"run": "r-881", "ts": "2026-11-29T02:14:07Z", "step": "extract", "endpoint": "prov-b", "ok": true, "ms": 1543}
Two lines of code per step, and suddenly "it failed last night somewhere" becomes a 30-second diagnosis.
2. Failover is a routing decision, not a try/except
The naive version:
try:
return call(provider_a, task)
except:
return call(provider_b, task) # provider_b is also down at 3am
The production version consults live health data (a probe sampling every endpoint every few minutes) and picks the next healthy endpoint in the same tier — with exponential backoff on 429 and tier escalation on repeated 5xx. "Just retry" against a dead provider just burns your rate limit.
3. Bounded retries with a terminal state
Unbounded retry loops are how you turn a provider outage into a $400 bill. Every step gets a retry budget (3 attempts, backoff 1s/2s/4s), and when the budget is spent, the run enters a terminal failed state — logged, alertable, re-runnable. It does not spin.
4. Secrets never live in the workflow
n8n workflows get exported and shared. Node scripts get committed. The workflow JSON should contain placeholders, and credentials come from environment variables or a credentials store at runtime. This takes five extra minutes and saves you from rotating every key you own because one file left the building.
5. Idempotency for anything with side effects
If a step sends an email or writes a row, a re-run must not double-send. Key the step by run id + step name and check "did I already do this?" before acting. Boring, and the difference between "re-run the failed batch" being safe or terrifying.
6. The human handoff
Whoever maintains this after you is not you. That means: a README that says what each workflow does, where secrets live, how to re-run a trace, and what "healthy" looks like. If your handover doc is a Slack DM, you don't have a handover doc.
All six are mechanical once you've done them a few times — which is the point. Agent workflows aren't hard because of the AI part; they're hard because of the 3am part.
I build these for clients on n8n, Node.js, and Python — routing, failover, traces, docs, and a training session so your team can maintain it: workflow build here.
First post in this series: the endpoint health probe that feeds this system's router.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.