ai newsDi., 1. Dez.

One night with my LLM code auditor: 27 findings, 5 wrong, 11 fixes proven by a failing test

When I started scanning my repos with an LLM, fewer than a third of its findings were real. The current prompt's findings are real about three times in four, and on the night below 22 of 27 were right. Every night ai-code-auditor reads each repo in my Argus suite and writes up every problem it find

dev.toDienstag 06:03 · 01.12.8 Min. Lesezeit
Bild: dev.to

Posted on Dec 1 • Originally published at dragonhound.dev • AI-assisted

When I started scanning my repos with an LLM, fewer than a third of its findings were real. The current prompt's findings are real about three times in four, and on the night below 22 of 27 were right.

Every night ai-code-auditor reads each repo in my Argus suite and writes up every problem it finds as a work pack: the code, what to change, and how the change will be judged. Coding agents claim a pack, fix it and send the patch back, and a fix counts only when a test fails before the patch and passes after it.

This post follows that night through the loop, from scan to merged pull request. The Auditor demo replays it pack by pack, with every diff and test result.

On 23 November at 17:30 UTC the nightly scan read argus-scout, one of 31 repos that night, and wrote 27 work packs. At 04:35 the next morning an agent claimed them. A claim is exclusive, so a second agent asking for the same pack is refused. By 04:56 every pack was closed one way or another, and at 08:13 the pull request was merged by hand, one commit per fix.

The demo counts these from the packs themselves, and its build fails if a pack is left out.

An agent's patch goes to validate_patch, which never touches the live checkout. It exports a clean copy of the dev tip, applies the patch to a second copy, finds the project each changed file belongs to, and runs that project's tests on both. Only failures the patch introduces count against it.

For a bug or security finding that isn't enough. The patch has to bring a test that fails on dev and passes with the fix, and anything less leaves the pack unverified, which is still open work. A pack lands in one of four states:

Here is one of the eleven. The scan noticed that scout's prune() deleted acknowledged events even while their source was still reporting them, so after the retention window an ongoing, already-acknowledged problem came back as unread news. The fix added one condition to the query and one test. On dev the test failed, with the fix it passed, and the other 28 tests in that file passed on both.

Every proven fix on the demo has a panel like this one.

Eleven findings that night were about weak tests: a guard that only caught one import style, an assertion that could pass with nothing to check, a migration test that never looked at old rows. The fix for each is a stronger test, and a stronger test passes on dev 's code as well, because the code was never broken, so it can't show the failure the bar asks for.

I kept it that way on purpose. When validate_patch runs the "before" tree it copies the patch's test files across whole, because otherwise a change to a test helper could manufacture a failure on dev and pass it off as proof. So a test-only patch resolves either as test_only, when its tests run and pass, or on a waiver: a written reason of at least twenty characters, stored with the pack. One resolved as test_only. Nine of the ten waivers say what the agent did instead:

Test-only finding: the fix strengthens a test, so the same test runs on both trees and passes on dev's source. Verified locally by mutation: the strengthened test fails when the guarded behaviour is broken, where the old one passed.

The tenth admits the finding was mostly wrong: the old test did cover the unit it claimed to, and the change only makes that explicit. A waiver is visible on every pack page and never counts towards an agent earning more autonomy (more on that below). A later run can re-send a merged fix that rested on a waiver and record stronger evidence if it finds some, but never weaker.

The scan is a language model reading code, and that night it was wrong about 5 of 27 findings. Two examples, from the notes the agent left:

Each was closed as wontfix with its reason, which matters the next night. The scan re-found four of the five on 27 November and they stayed closed, because a wontfix pack is how a known false positive stays quiet, and the nightly clean-up only closes one when the code it cites is gone. That's a 19% false-positive rate for the night, and the demo shows all five with the agent's notes so you can judge them yourself.

Most of what the first version found was noise.

From the first commit in March, a 33-billion-parameter code model on a home server read every function and class and was asked for "bugs, security issues, and maintainability problems", alongside Bandit, Semgrep and some hand-written architecture checks. When a model call failed, the scan quietly fell back to simple heuristics.

On 13 November I moved the scan to cloud models, made a failed call stop passing itself off as a review, and switched to a new prompt: it drops style and maintainability, adds a severity rubric and a confidence bar, and caps each unit of code at five findings. I ran the old and new prompts on the same 50 units and had a judge model (Opus) score them blind:

It gave up one real issue for seven times fewer findings, and the cost per unit halved. The night above, at 22 right out of 27 (81%), sits close to that 76%.

The model rewords its titles every night, so one problem used to pile up as several open packs, and a claimed pack grew a fresh twin the next morning. Since 15 November a re-found finding on the same file is matched to its existing pack by title similarity and takes its id, so its status and any wontfix decision carry over. The first clean-up found 53 duplicates, and it's why the wrong findings above stayed closed when the scan re-found them.

Until 18 November a function was reviewed without its decorators, and module-level code (route registration, import-time calls, __main__ blocks) was never reviewed at all unless the file had no functions. Both are read now, since that's where routes and auth checks tend to live.

From 18 to 20 November the model budget ran out partway through each night, and a file the model never reached returned no findings and still counted as scanned. The night's findings appeared to drop from 1,122 to 293 to 103, then jumped back to 835, and the clean-up closed packs on scans that had never looked at their code. Since 21 November every file the model didn't review is recorded, and nothing treats it as a fix.

Fixing the same mistake one pack at a time doesn't stop the next one, so since 16 November each finding is sorted into one of 19 classes, and each class names the guard that could prevent it: a Ruff or Semgrep rule, a shared helper, an import contract. Matching titles with hand-written rules scored 98% precision on the findings those rules were written against, but 84% precision and 32% coverage on a blind held-out set, so I don't let it label packs. A class is now recorded only where three models (Haiku, Sonnet and Opus) agree: 95.3% precision and 86% coverage on the held-out set.

A class with five or more open packs, or open packs in two or more repos, gets one guard pack whose deliverable is a CI rule with a proof test, and its instance packs close only once the scan stops reporting them. Guards are tested in turn by planting known instances of the mistake and checking the guard catches each one.

The suite's shared CI rule catalogue runs in the scan (16 November), so a hit on one of its guard rules is also a finding. A detector for comments that admit a workaround ("HACK", "remove once…", a sleep and retry with a race-condition excuse) arrived on 23 November; every hit across the suite was labelled by hand, and four of the five were real, the fifth borderline. Since 24 November a structure scan reports import cycles inside each repo, report-only for now.

The repo keeps a "must never happen" list, and each line names the test that enforces it. A few that matter here:

Autonomy is earned per repo and per kind of finding. An agent's pull request starts as a draft. A scope moves up at most one level per night, and only after its last 20 agent PRs came through clean, every pack resolved with real evidence (no lint-only results, no waivers), and 30 days at its current level. Any breach drops it a level. The ceiling is "ready for review", and nothing merges by itself.

The Auditor demo has all 27 packs from this night: the finding as the scan wrote it, the work pack, its status history, the commit that closed it, and how it was judged. The source is on GitHub, and the docs page covers running it on your own repos.

Originally published on dragonhound.dev.

Quelle: dev.to (dev.to). Original öffnen