I've realized that the agent doesn't write 'good' code, instead my vague understanding of what I expect makes me think it does. When I look at the AI code, I see that there are more nuances and decisions that needed to be taken before writing the code. One would say that a spec would suffice, but then I remember TLA+, developed by Leslie Lamport to help developers think critically about their programs/algorithms. Sitting down and formally writing what I want to do helps me better understand the problem and come up with a real -not vaguely defined- solution.
No one writes 'good' code. Everyone only writes 'good enough' code. You should always assume the existence of flaws and bugs.
You call "good" code the one that doesn't have the mistakes you know. But you'll never know everything, even if you are as smart as Dijkstra.