Your AI Wrote the Code. Who Debugs It at 3 AM?
AI coding assistants have changed how fast we ship. A function that took an afternoon now takes a few minutes. That's great, until something breaks in production and the on-call person realizes nobody on the team has rea
AI coding assistants have changed how fast we ship. A function that took an afternoon now takes a few minutes. That's great, until something breaks in production and the on-call person realizes nobody on the team has really read it.
Code is now written faster than it can be reviewed, so more of it reaches production half-understood. The skill that matters most isn't writing code quickly anymore. It's explaining what code is doing once it's running.
Here's a practical approach for DevOps teams that want to keep up.
The review gap is real
Code review was designed for a world where the author understood their own change. With AI assistance, an engineer may approve a 200-line diff that looks right, passes tests, and still hides an edge case nobody thought about.
You can't fix this by reviewing harder. Reviewers are already stretched, and the volume is only growing. The more realistic fix is to assume some bugs will ship and make them cheap to find.
That means investing in what happens after deploy.
Habit 1: Tie every signal to a release
The first question in any incident is "what changed?" If answering it means digging through Slack and CI logs, you've already lost time.
Stamp your version onto your telemetry so every trace, log, and metric carries it:
import os
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
resource = Resource.create({
"service.name": "checkout",
"service.version": os.getenv("GIT_SHA", "unknown"),
"deployment.environment": os.getenv("ENV", "production"),
})
provider = TracerProvider(resource=resource)
Now when errors spike, you can filter by service.version and see whether they began at a specific deploy. Two lines of config can save an hour of guessing.
Habit 2: Instrument intent, not just requests
Auto-instrumentation tells you a request was slow. It doesn't tell you why your business logic made a bad decision. For code you didn't write yourself, add spans and attributes around the decisions that matter:
from opentelemetry import trace
tracer = trace.get_tracer("checkout")
def apply_discount(cart, code):
with tracer.start_as_current_span("apply_discount") as span:
span.set_attribute("cart.item_count", len(cart.items))
span.set_attribute("discount.code", code)
result = _calculate(cart, code)
span.set_attribute("discount.amount", result.amount)
return result
When a customer reports a wrong total, you can look up that exact trace and see the inputs and outputs instead of reproducing the bug locally. Keep attributes low-cardinality where you can, and never log sensitive data.
Habit 3: Alert on user impact
Plenty of AI-related failures aren't crashes. They look like a slightly wrong answer, a retry loop, or a quiet cost increase. CPU graphs and error rates won't catch them.
Alert on what users feel: failed checkouts, slow key actions, and the success rate of critical journeys. Pair that with a few guardrails for AI workloads specifically, such as token usage per request, cost per day, and retry counts. If an agent starts looping, you want to hear about it from an alert, not from the invoice.
Habit 4: Make the investigation fast
Most of an outage is spent finding the cause, not fixing it. The fix is often a one-line change or a rollback. So measure and shrink the search:
- Keep logs, metrics, and traces connected. If you need three tools open to follow one request, the tool sprawl is slowing you down.
- Propagate trace IDs into logs. Jumping from a slow trace to the exact log lines should take one click.
- Write blameless post-mortems. Record what made the cause hard to find, then fix that, not only the bug.
Track your mean time to resolution (MTTR) over time. If it's not dropping as your release speed rises, your debugging process is the bottleneck.
Where AI agents fit in
It's tempting to say the answer to AI-written bugs is more AI, and partly it is. Agents can read telemetry, correlate signals, and propose a fix faster than a tired engineer at 3 AM. But they work with the context you give them. An agent looking at unversioned, uncorrelated, unstructured data will make confident guesses. An agent looking at clean, connected telemetry can find real causes.
Treat agent suggestions like any other change: review them, test them, and keep a human in the loop, especially for production code. The groundwork above is what makes the agents useful.
A quick checklist
- [ ]
service.versionis set on every service - [ ] Trace IDs appear in logs
- [ ] Business-critical functions have spans with useful attributes
- [ ] Alerts are tied to user impact, not only infrastructure
- [ ] AI workloads track token usage, cost, and retries
- [ ] You measure MTTR and review it regularly
Final thoughts
AI isn't making debugging go away. It's moving it later in the process, from the editor to production. The teams that do well won't be the ones who write the most code. They'll be the ones who can explain their systems quickly when something goes wrong.
If you want a single platform for logs, traces, metrics, and an AI-assisted investigation, tools like Middleware are built for this, and OpenTelemetry keeps you from being locked in to any one of them.
What's the strangest bug you've had to debug in AI-written code? Share it in the comments.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.