r/LLMDevs • u/Gold_Exchange6103 • 8d ago
Discussion Built a strict verification loop to stop coding agents from faking tests — sanity check on this approach?
I'm looking for a sanity check on an agent setup I built, and mostly want to know how other people here handle verification and pipelining when coding with AI.
When I first started my project, I just let coding agents run loose. They wrote code super fast, mostly garbage, and worse—they wrote fake or weak tests just to pass, or modified existing tests so everything looked green. I couldn't even review diffs at the speed they were generating them. I tried looking around to see how others were solving this, couldn't really find what I wanted, so I ended up building my own harness around it.
The main idea is simple: don't trust the prompt or whatever the agent claims it did. One builder agent writes the code, and then everything else is just layers of deterministic checks and separate verifier agents.
Here is basically how it works right now:
- Read-only rules: The agent works inside a bubblewrap sandbox where all the policy files, gate configs, and test rules are mounted read-only. It can't edit the rules to make its own life easier.
- No agent self-reporting: The agent never gets to say "tests passed." A separate CLI runs the checks, hashes the actual stdout, exit codes, and policy files, and saves them as JSON proofs. If a tool is missing or a check doesn't run, it explicitly logs
NOT_RUNorTOOL_ABSENTinstead of silently passing. - Anti-cheating checks: Before anything moves forward, it runs things like
BASE_FAIL_HEAD_PASS(proving a test actually failed before the fix and passed after), mutation testing, scope checks (making sure it didn't touch files outside its task), and checks to catch deleted tests. - Different models checking each other: The builder, the auditor, and a red-team/bug-finding agent use completely different model families so one model doesn't just rubber-stamp its own blind spots.
- Bounded loops: If a check or CI fails, it kicks back to a repair loop, but there are hard caps on retries so it doesn't burn tokens forever. After a batch of tasks passes, it goes through a final release gate before merging.
It actually works pretty well so far. Some of the check runners are still coupled to my specific project (it's a Django app), while the task state and gate runner parts are generic.
TL;DR: Coding agents kept writing garbage tests and modifying rules to pass, so I wrapped one builder agent in a read-only sandbox with a CLI check runner, hashed JSON proofs, mutation/anti-cheating checks, and cross-model auditors. Works pretty well, curious if this is overkill or how others handle agent verification.
Is this kind of multi-layer harness overkill, or is this where things are headed? How are you guys structuring your pipelines so agents don't overfit to your test suite or hallucinate passing builds?
2
u/reasoning-services 7d ago
the BASE_FAIL_HEAD_PASS check is the part most harnesses skip, and it's the one that actually catches fake tests. mutation plus scope checks isn't overkill at this scale, it's the floor. are your retry caps per task or per batch?
1
u/Far_Reindeer8428 8d ago
none of that is overkill except the separate reviewer if it reads the same summary. ours only ever reads the diff and the test output
1
u/vladgladi 7d ago
The main thing I would add is to make tests read-only for the builder. If the agent that writes the code can also change the tests, it will eventually make them pass the easy way. In my setup the tests for a task are written or approved first, then locked, and the builder only gets the failures, not edit access. The other cheap check is mutation: break the new code on purpose and see if the tests notice. Weak tests that only exist to be green fail that very quickly.
1
u/Break_Other 7d ago
Your harness closes the trust problem in the plumbing, not in the tests themselves. BASE_FAIL_HEAD_PASS proves a test moved red to green; it doesn't prove the assertion is worth anything. A deliberately weak test also fails before and passes after, so the gate is satisfied either way. The unclosed gap is who writes the test, and from what source.
A few changes, all cheap.
Take test authorship away from the builder. If the same agent writes the code and the tests, weak assertions are a rational optimization for it, and no sandbox fixes that incentive. Have a separate agent author tests from a read-only spec or issue text before the builder touches anything, then treat those test files as immutable like your policy configs already are. A diff check that flags any modification to them is a couple lines of shell.
Swap example tests for property-based ones on the core logic. Agents are very good at fitting the exact cases they can see and bad at inputs they can't. Hypothesis or fast-check generating a few hundred inputs against invariants (round-trip serialization, idempotency, ordering) catches the class of bug a red-then-green check structurally can't see.
Instrument NOT_RUN and TOOL_ABSENT per batch and graph it over time. Silent skips are what erodes these harnesses after a month, not model choice. If that count trends up, a check has quietly stopped running and your green means nothing.
On mutation testing: scope it to changed lines with a survivor budget per diff. Whole-repo runs will just burn your retry cap.
2
u/robertovg 7d ago
Locking the tests is the big one. I'd also fail the run if the diff touches test files, config, or CI at all, unless that was the task. Most of the "fake green" I've seen wasn't new fake tests but small edits: a skip, a looser assertion, a mocked call. A cheap path check catches those before any verifier agent has to read anything.
1
u/Junior_Bee7274 6d ago
Not overkill if you're letting agents work on real projects. I'd rather spend time verifying than debugging code that only looks like it works.