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 |
|---|---|---|
| 1 | Dead 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 |
| 2 | Self-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 |
| 3 | Import-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) |
| 4 | Fake 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 |
| 5 | The 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) |
| 6 | Common-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) |
| 7 | Hardening 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) |
| 8 | Dead 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 |
| 9 | Narrowing 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) |
| 10 | Test 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") |
| 11 | Stub code. "In a real implementation, this would..." and a fake return value. | placeholder_problems |
| 12 | Order-dependent test. Count lru_cache hits without clearing the cache first: passes alone, fails in the full suite, breaks main. |
cache_count_problems |
| 13 | Hidden 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 attempts | 1,616 |
| Passed every test (suite, eval gate, security) | 565 |
| Merged themselves automatically | 330 |
| Self-merges reverted by hand in 3 days of review | 17 |
| One week of self-merges re-checked with these checks | 277, of which 177 flagged for review |
| Of those 177, edits to a live function's body | 45 (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.
Metadata
Release files for evolve-guard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| evolve_guard-0.1.0.tar.gz | 31.3 kB | With provenance | Details for evolve_guard-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| evolve_guard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for evolve_guard-0.1.0-py3-none-any.whl |
Total release size: 53.5 kB
Release files / evolve_guard-0.1.0.tar.gz
| Download URL | evolve_guard-0.1.0.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ac506ff7f2e3ced1addc3b98814184243ff1cdb20968273f12a887d1157413b
|
|
BLAKE2b-256 checksum How to use checksums |
5dd291dcc9cce019470400fa7efbb77fbdc8741367e4b29f50f8a65503262ef5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / evolve_guard-0.1.0-py3-none-any.whl
| Download URL | evolve_guard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a62585ff74f2446fcb845be5f85e31e3a61f8ff5305149f99bf17870f8da0b7
|
|
BLAKE2b-256 checksum How to use checksums |
42baadf71f8fc246d39b2377e09bad6c29a090905cecee4712922c090bc234ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for evolve-guard 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for evolve_guard-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.