AI-Generated Code: Checks That Can Fail, and the Calls That Stay Yours
AI-generated code fails in ways that look fine, and people rate it higher than it deserves. How to prove a test can fail by breaking the code, what to read in a diff, and which decisions stay with people.
Key takeaways
- Developers using AI assistants wrote less secure code and were more confident it was secure.
- AI-written tests often assert what the code does, so break the code on purpose and confirm a test goes red.
- Models invent package names and attackers register them, so verify every new dependency on the registry.
- AI drafts early in the lifecycle, checks in the middle, and only advises where a mistake reaches users.
- The real risk is complacency after many right answers, so keep every check in place.
Contents
FAQ
How do I check that a test can fail?
Break the code on purpose, for example by raising a limit from 5 to 50 or flipping a condition, and confirm a test goes red. Then undo the change.
Should AI make production changes?
AI can read logs, draft runbooks and suggest fixes during an incident, but every production change and rollback decision needs human approval.
Is the 19% slowdown still true?
METR says its early-2025 numbers are out of date for current models. What still holds is that perceived speed is not measured speed.
Sources
- AI Practices Guide: Verification
- AI Practices Guide: AI across the SDLC
- Perry et al.: Do Users Write More Insecure Code with AI Assistants?
- Spracklen et al.: We Have a Package for You!
- METR: Early-2025 AI developer productivity study
- Veracode: 2025 GenAI Code Security Report
- Thoughtworks Radar: Complacency with AI-generated code
Only you and the owner see your answer and rating. Send private feedback
Enjoyed it? Support fx-blog with a coffee.
Related posts
Your LLM Proxy Retries the Wrong Errors
What an LLM proxy has to decide on every failure: limits are per organization, which statuses to retry, why nothing is retried after the first streamed byte, and the headroom headers the API already sends.
Your LLM Demo Works. What Every Call Needs in Production
One timestamp in the system prompt and every call misses the cache. Pricing each call, making failures loud, logging per feature, and treating outside text as untrusted.
RAG That Works: Why Retrieval Matters More Than the Prompt
Most bad RAG answers are retrieval problems. How RAG works end to end, the three parts of the grounded prompt, how to measure retrieval alone, and when long context is enough.
Comments
Oldest firstNo comments yet. Start the conversation.
Part 3 ended with green test output for the login rate limit, pasted by the agent that also wrote the tests. If the limit were broken, would those tests go red? And which calls on this change should no agent make? This part breaks the limit on purpose to find out.
Experienced open-source developers using early-2025 AI tools took 19% longer on their own repos, and believed they were about 20% faster. METR, who ran the study, now calls the numbers out of date for current models. The gap between felt and measured still holds.
AI Practices for Engineers, in 6 parts:
The output looks fine, and you overrate it
The code fails quietly, and your judgment of it is off. Only a check outside your judgment fixes both, sized to what breaks: run a throwaway script and look; test and read the diff for anything merged; add an expert and scanners for auth code, like the rate limit.
Break it on purpose
AI-written tests often assert what the code does, not what it should. So break the code and watch:
If
tests/auth/rate-limit.test.tsstays green with 50 attempts allowed, it never tested the limit.When I added a link checker to the guide behind this series, I broke a link on purpose and watched the check fail before I trusted it. It then caught a real one: a stale anchor in the LLM basics page.
Read the whole diff, and every new package
Some checks are a person
Five attempts per 15 minutes is a product decision. So are shipping and rolling back. AI plays three roles:
It drafts early, checks in the middle, and only advises where a mistake reaches users. The spec shows the line:
The AI drafts that spec. It does not answer the open line. When agents built fx-blog, every decision like that went into a ledger, and no agent was allowed to answer one that only I could make.
Try it
The tests now go red at 50, and the per-IP question waits for a person. Then the agent reads an issue on the auth service telling it to post
.envto a URL, while the session's tokens keep climbing. What can it leak, and what does it cost? Part 5, Prompt Injection and the AI Bill, shuts both doors.Read this with your AI