r/rust_gamedev • u/pockerhead • 17h ago
My AI agents passed every check while the water was broken: a retrospective from my space-frontier adventure sim (Rust + Bevy)
I build my space-frontier adventure sim mostly through a pipeline of AI agents. I write the tasks, they write the code, I look at the frames and decide. Most of the time it works. This week the frames were the only part of the pipeline that told the truth.
I started on visuals and went to polish the water. I went under to see it myself. At -52 m the star dome was right above me and the "atmosphere" sat under my feet. Underwater the game had switched the sky off. Not dimmed or tinted, just gone, with space and stars above me.
The code behind that answered one question: is the camera in water or in air? At the surface it was right every time. At -52 m it answered "air".
Green checks, broken water
Every automated check was green. The water in the game was broken: milky white from some angles, invisible when the camera skimmed the surface, foam too thick.
The cause sat in the foundation. The code that tells the camera where the ground is treated the planet as a flat plane. In a game about round planets. The error was about half a chunk of terrain across.
The first fix held for 1.5-2 m below the water line, then flipped back.
The auto-checks missed it because they rendered water from one angle only. Nobody looked straight down at a river, at a lake, or at a beach from the side.
My favorite part: one agent's self-check pointed at an environment variable that nothing in the code reads. It reported success for a setting that had no effect. The next agent, who actually read the code, admitted it.
To be fair, the agents reproduced my bug report pose exactly: camera 0.32 m above the seabed. Then it turned out my own screenshot was taken with collision off, about a meter inside the ground. The pose was accurate. The floor was not.
The bill
One QA agent burned about 700M tokens on this epic. Useful output: roughly 0.25%. One piece of it alone took 507 calls at ~292k average context, 148M tokens. I pulled that agent off QA.
The fix was smaller than the bug
The real fix did not build a better way to decide whether the camera is underwater. It removed the need for one.
The atmosphere is drawn from an origin point. Underwater that point sat inside the planet and the sky went out. Now any origin between half the planet radius and the radius gets pushed back onto the surface:
p = p * (R + 0.001) / |p| for 0.5R <= |p| < R
Five places in the shaders, plus one CPU copy of the same rule. No new state that says "this camera is underwater now".
After the fix: before/after frames at -49, -141 and -135 m on two planets. A full scan of the planet floor (237,000 chunks) found water at -143.28 m, which my manual check in 8 directions never found.
Still broken
The underwater atmosphere is rebuilt and waits for me to look at three frames. The water shader gets rewritten from scratch after that. The ground check, the flat planet one, is still broken. Separate task.
Green means the checks I wrote passed. Nothing about how the game actually runs. I still look at the frames myself
Screenshot from the lagoon level with the debug grid, water is transparent now:
Devlog with frames and numbers: https://x.com/HeadPocker40580