r/LLMDevs • • 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_RUN or TOOL_ABSENT instead 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?

5 Upvotes

19 comments sorted by

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/Gold_Exchange6103 7d ago

Per task(3,4) and per batch (2,3) counted seperately 

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/Gold_Exchange6103 8d ago

So it doesn't actually read any summary* , it just gets the diff , and then it reasons over it. And reviews the diff trying to find a hole.. and runs the gate (using the cli..)

1

u/Far_Reindeer8428 8d ago

right, the reviewer gets the diff text and the raw test output, nothing the agent wrote about its own work. the gate then runs from the cli

1

u/Gold_Exchange6103 8d ago

Ifydm like could u describe your own setup.. and the amount of review you give and how it merges

1

u/Far_Reindeer8428 8d ago

one module per lease, two independent reviewers on the diff, then a merge commit. i read maybe a quarter of the diffs and only the ones touching money, auth, or migrations

1

u/Gold_Exchange6103 7d ago

Oo.. that's interesting to have 2reviews.. I have it as one micro(on diff per task) and one macro(for 5-6tasks) which checks the seams .. thanks tho.. 

1

u/Far_Reindeer8428 7d ago

the macro pass for seams is a good idea, we only did that ad hoc. stealing it, the seams are where our one real incident came from

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/Gold_Exchange6103 7d ago

Ah..I'll try with tests ..I already use tdd , just not independent..

And mutation is already run per hunk inside the builders feedback loop

2

u/vladgladi 6d ago

Then you are already most of the way there. If mutation runs inside the builder loop, the one gap I would still close is who writes the tests that the mutants are checked against. When the same agent writes both, the mutants just confirm its own understanding of the task. Even a short list of cases written before the build, by you or a separate prompt that only sees the spec, changes that a lot.

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.

1

u/Gold_Exchange6103 7d ago

Actually.. i tried independent authorship for tests but it was burning a lot of tokens in context rediscovering.. (both builder and test writer spend time finding the same context).. so I settled on ast semantic conparisons against patterns of weak assertions and mutation i run it in the inner loop.. the builder can't say it's done until the policy defined number of mutants are killed (a threshold is set for each.. and if it doesn't meet so the gate fails automatically and the builder keeps trying till it's token budget allows)

I already have schemathesis,I'll add hypothesis on the tests..

And I'll do the graphing..that's an awesome idea.. Thankss..

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.