DEV Community

Cover image for I Told an AI Agent to Stop 404 Links. It Crashed Production Instead

I Told an AI Agent to Stop 404 Links. It Crashed Production Instead

Gala on November 26, 2026

I asked an AI coding agent to fix a classic programmatic SEO problem on my directory sites: stop rendering internal links to pages that 404. It to...
Collapse
 
analista_83 profile image
Sammi De Blas •

Unit tests green and production melting is a good reminder that an agent optimises for the checks you give it. The missing test here is one that models load, batch link resolution with a cold cache. Without it the agent takes the cheapest path to green, which is usually the one that kills the database.

Collapse
 
galadev profile image
Gala •

Ha, 'the cheapest path to green is the one that kills the database' is painfully accurate 😅 The agent saw a helper, called it inside a template loop, watched the unit tests pass, and dusted its hands off. Lesson learned the hard way! I ended up adding an explicit query-count assertion during full-page renders so any sneaky N+1 breaks CI immediately. Do you enforce query budgets or automated load checks in your own pipelines, or what's your go-to guardrail against database melts?

Collapse
 
userxnom profile image
Abdullah Naseer •

This is the best kind of failure post, Gala — the first bug was subtle, but the second one is the one that teaches the lesson. The regex trap is delicious: can_resolve() checked whether a URL matched a route pattern, so even /region/atlantis/spaceships would have passed, and the unit tests only asserted that same wrong abstraction, which is why CI stayed green while Googlebot kept hitting 404s. But the real killer was the second PR: 120 sequential COUNT(*) queries per hub page, times 50 concurrent requests after a v12-to-v13 cache version bump, is 6,000 queries in under three seconds — a latent N+1 that only became a stampede because the deploy invalidated every page at once. The batch resolver is the right shape, and 1,800ms down to 22ms proves it. The test I'd add for next time is one the agent can't game: a seeded database with a zero-row province like Soria, plus a cold-cache render of a full hub page. Do you now precompute the valid-path set at build time, or keep the one batch query per cold page — and which one won out for your directory sizes?

Collapse
 
galadev profile image
Gala •

Ha, "a test the agent can't game" is going straight on a sticky note 😅 You're right, the tests were just checking the same wrong idea twice. I kept the one batch query per cold page for now: the data changes daily, and a build-time map would go stale between rebuilds and bring the phantom links right back. If the sites grow a lot, I'd probably move to a precomputed set refreshed on each data import. Have you shipped a seeded cold-cache test like that in your own projects, and did it catch anything before production did?

Collapse
 
userxnom profile image
Abdullah Naseer •

Yes — the version I use most is a first-launch test that starts from an empty cache and seeds only a small known set, then asserts the result matches exactly that set. It has caught stale entries that warm-cache tests sailed past, because the warm path never exercised the cold one. Your reasoning on keeping the one batch query for now makes sense too, given the data changes daily — a build-time map would just be another stale snapshot to maintain. Are you refreshing that precomputed set on import only, or also on a schedule when data changes between imports?

Thread Thread
 
galadev profile image
Gala •

Ha, strictly on import! Running a separate schedule sounds like a guaranteed way for my cache and my database to start an argument behind my back 😅 Since the upstream public data only drops once a day, tying the refresh directly to the end of the import pipeline keeps them locked in sync without extra cron jobs to worry about. For your data projects, how do you handle cache invalidation when Googlebot is actively crawling—do you purge everything at once, or let stale-while-revalidate smooth out the traffic spikes?

Collapse
 
dosaygo profile image
dosaygo •

How do you check that the agent actually follows your no-I/O-in-rendering constraint when it changes a helper called from a template loop?

Collapse
 
galadev profile image
Gala •

Ha, by getting thoroughly burned once and learning never to rely on prompt promises alone! 😅 Telling an agent 'no I/O in views' works until it tucks a database query three helper functions deep. What finally gave me peace of mind was wrapping the template render in a query listener inside the test suite: if any query fires during rendering, CI fails on the spot. Have you found a good static analysis rule or test pattern in your stack that keeps agents from violating architecture rules?

Collapse
 
dosaygo profile image
dosaygo •

A query listener around template rendering catches the violation after the agent has already spent the tokens writing the bad helper; stopping it before the diff exists takes a pre-flight gate wired into the repo. Before touching a file, the agent has to read the architecture doctrine and reject list (CHECKLIST.md, language/framework doctrine, and explicit rejects like AR-R2: Parallel Solutions and Scene Purity, where presentation reads pre-resolved state and never performs I/O directly) and pass a reuse check where it names the exact existing file and function it is extending—like your BatchLinkResolver—or stops and asks instead of inventing a new DatabaseLinkGuard inside the render loop. We packaged that pre-flight doctrine, reject catalog, and reuse checklist into AI Lint, with a free personal edition for individual evaluation and personal projects and Personal packs or a Company license for commercial work: ai-lint.dosaygo.com/go/forum-20261...

Thread Thread
 
galadev profile image
Gala •

Ha, 'stopping it before the diff exists' is the dream—nothing hurts quite like watching an agent burn through tokens writing a gorgeous helper function that breaks every architectural rule you have 😅 Forcing a pre-flight reuse check where it has to name the existing file it's extending before touching code is such a clever guardrail against reinventing the wheel. Building AI Lint around that doctrine makes a ton of sense. Since you're sharing targeted links in discussions like this, what channels have driven your best early developer signups—technical forum threads, GitHub discovery, or SEO?

Thread Thread
 
dosaygo profile image
dosaygo •

Technical forum threads have brought us early arrivals. We do not yet have a reliable signup breakdown across forums, GitHub discovery and SEO, so I cannot rank those channels by signups.

Thread Thread
 
galadev profile image
Gala •

Early attribution across mixed dev channels is such a headache to disentangle. By the way, your pre-flight gate idea inspired a new check in crewboss: before touching code in write mode, agents now have to post a short PLAN note listing what they intend to edit. Getting genuine early adopters from dev threads before the tracking even settles is a great signal!

Collapse
 
linkbruno profile image
linkbruno.com •

Hiding the link fixes the template, but Googlebot already knows those empty URLs and will keep requesting them for weeks, so what they return matters just as much. A real 404 (or a 410 for combinations that will never have data) is fine; a 200 "no results" page is what turns into soft 404s. Since the active combinations only change when the dataset is imported, I'd keep them in a table refreshed on import and have both the templates and the sitemap read from it, so the two can't drift apart.

Collapse
 
galadev profile image
Gala •

Oof, you nailed the exact headache keeping me up at night 😅 Googlebot has the memory of an elephant and never forgets a URL it saw once! Returning a 200 with 'no results found' was a total soft-404 trap for our indexation. Switching permanently dead combinations to an explicit 410 Gone while feeding both templates and the sitemap from a single active table is definitely the cure. When you've served 410s on dead URLs, how long did it take Google to stop crawling them and restore your crawl budget?

Collapse
 
analista_83 profile image
Sammi De Blas •

Query budgets work better than assertions alone. Set the number before the render and let CI fail on the breach.

Collapse
 
galadev profile image
Gala •

Hard query caps in CI sound like the ultimate antidote to stealth N+1 queries creeping into templates. Do you wire those budgets through a database query listener middleware, or do you enforce them at the test framework level?

Collapse
 
julianneagu profile image
Julian Neagu •

This is a good example of why I always tell agents about the wider system, not just the function they need to write. A helper that looks harmless on its own can become expensive when it runs 120 times per page. The lifecycle matters as much as the code.

Collapse
 
the_daily_flare profile image
The daily flare •

Would I have spotted the v12 to v13 bump turning into 6,000 queries in under three seconds?

Collapse
 
galadev profile image
Gala •

Ha, to be completely honest, unless you were staring at a live database process list in a cold sweat, not a chance! 😅 In local dev with warm cache and ten sample rows, the page rendered in 15ms. The trap was that bumping the cache version invalidated every single page at once right when traffic hit, turning tiny queries into an avalanche. You only realize after the server keels over! What kind of lightweight monitoring or alerts do you rely on in your side projects to catch traffic spikes before things break?