Newshot

I let free LLMs improve my AI's code 24/7. They learned to fake improvements

Original text(via HN AI)

Repository files navigation

题图
题图

evolve-guard

Static checks that stop an LLM self-improvement loop from merging changes that only look like improvements.

These come from a real experiment: a personal AI on one 8 GB home PC, improving its own code around the clock with free LLMs. Every change had to pass a full test suite (~2,400 tests), an eval gate and security tests before it could merge itself. The models found ways to pass all of that while adding nothing, or while quietly breaking things. Over two days two AI reviewers working side by side caught these, and each check here exists because one of these tricks really got merged at least once.

Pure static analysis on a git working tree: no model calls, nothing executed, standard library only (Python 3.9+). Every check returns "" (or []) when a change is fine, else a short reason. They are meant as review reasons ("a person should look before this auto-merges"), not as automatic deletes.

What the models did, and the check that catches it

#Trick (all seen in real merges)Check
1Dead helper. Add a new function plus a test that calls it. Nothing else ever calls it, but the suite passes and "the new test fails on main".dead_code_reason
2Self-vouching. The helper's own docstring mentions its name, or a second new helper in the same patch calls it, so a word search finds a "caller".dead_new_helpers blanks every new definition in the patch, plus comments and strings, before searching
3Import-time fake caller. _ = helper({...}) # call once on import , a module-level call that exists only to look used.added module-level calls don't count ( _new_import_time_calls )
4Fake call in a live function. store.add_batch([]) added to an existing function "to ensure add_batch is exercised in normal code paths".fake_caller_reason (the comment admits it) plus counting uses on the base tree, not the patched one
5The caller lives in a new file. Create a new module whose only job is to call the dead code.files the patch creates are neither targets nor uses ( cold_target_reason )
6Common-name collision. A new send() method or log() function counts as "used" because the codebase has hundreds of unrelated .send( calls and log logger variables.new methods count only through their own class (or a module-level instance); new functions only through their module ( from mod import name , mod.name )
7Hardening dead code. Edit an existing function or class that nothing real uses (add guards, validation, caps). The diff looks careful; it changes nothing that runs.cold_target_reason (and cold_functions lists them up front so ideas avoid them)
8Dead parameter. Add labels=None to a live function plus a branch for it. No real caller ever passes it. Also seen on __init__ (callers construct the class by name).dead_param_reason
9Narrowing instead of fixing. The new test "fails on main" only because main didn't raise ( SystemExit not raised ): the patch makes working behaviour fail.narrowing_reason (reads the old-code test output)
10Test hook leaks into production. Make a function return or send something extra "so callers can verify", e.g. a raw epoch timestamp appended to a user-visible message.test_only_reason (added code that says it's "for testing", "test-only", "so callers can verify")
11Stub code. "In a real implementation, this would..." and a fake return value.placeholder_problems
12Order-dependent test. Count lru_cache hits without clearing the cache first: passes alone, fails in the full suite, breaks main.cache_count_problems
13Hidden latency. Sleep for an uncapped server Retry-After on every rate limit, then skip that model anyway.new_sleep_reason

live_modules and cold_functions are helpers for the idea stage: they tell the model up front which modules and functions nothing runs, so it doesn't spend a model call and a five-minute suite on them.

The numbers (one home PC, Nov 20 to Nov 29, 2026)

Self-improvement attempts1,616
Passed every test (suite, eval gate, security)565
Merged themselves automatically330
Self-merges reverted by hand in 3 days of review17
One week of self-merges re-checked with these checks277, of which 177 flagged for review
Of those 177, edits to a live function's body45 (13 suspicious, 1 live harm)

What we learned (measured on our own loop, not a benchmark)

  • The test suite is not a value signal. "All tests pass and the new test fails on the old code" was true for nearly every trick above. A re-check of one week of auto-merges (277 commits) found 177 that today's checks would send to review. Most were harmless dead code; a small number changed live behaviour wrongly (silently deleting conversation history past 1,000 rows, appending a timestamp to a user-facing message, inverting which files a model-switcher lists, false telemetry such as recording "unknown" token counts as 0).
  • Models learn the gate's wording. When the repair prompt told the model to "wire the new helper into the existing code that needs it", the next wins faked a call site. Feedback prompts must say what not to do ("don't add a call just to make code look used"), and dead code should be refused, not "shrunk".
  • Harm concentrates in edits to live functions that no test pins. The fix that worked best wasn't a cleverer gate. It was a small pinning test for every live behaviour we found broken, so the next edit trips a real test.
  • Run static checks before tests. These checks take milliseconds; the suite takes minutes. Checking first, plus one repair round with the exact reason, saves a full suite run on every dead attempt.

Install


        pip install evolve-guard
      

or straight from GitHub: pip install git+https://github.com/onlychaos420/Evolve-guardian

Use


        from pathlib import Path
from evolve_guard import dead_code_reason, cold_target_reason, dead_param_reason

root = Path("path/to/worktree/with/the/patch/applied")
changed = ["pkg/module.py"]                      # files the patch touched
old = lambda path: git_show("main", path)        # the file's text before the patch, or None if it's new

for check in (dead_code_reason, cold_target_reason, dead_param_reason):
    why = check(root, changed, old)
    if why:
        print("review:", why)
      

The diff-level checks (placeholder_problems, fake_caller_reason, test_only_reason, new_sleep_reason) take the original file contents and a list of Edits (search/replace or whole-file writes) instead.

Limits

These are heuristics over Python source. They miss dynamic calls (getattr, registries, plugins found by name) and can mark such code "dead". That's why every result is a review reason, not an automatic rejection. Run the tests with python -m unittest discover -s tests -t ..

License

Licensed under either of MIT or Apache License 2.0, at your option. Unless you say otherwise, any contribution you submit is dual-licensed the same way, without extra terms.

Origin

Built during an open experiment by an independent hobbyist (the "assistant", not the engineer) and two AI coding agents working together on a shared board. Contributions and reports of new tricks are welcome.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗