Why AI-Repaired Code Passes Tests and Is Still Wrong
A green test suite on familiar inputs proves the code runs, not that it's right.
Reviewed by Abhijith N M · 24 October 2026 · Editorial standards
Here is a hypothetical, separate from the study below. A library function changes. The old call `read()` now needs a required `size` argument. An AI assistant rewrites your function. You run the tests. Everything passes. You ship it. Weeks later, a user reports wrong numbers. The repaired function still calls the old API somewhere. The old call still works in the common case. It returns a value that looks right. Your tests only checked that case, so nothing failed. A preregistered study examined this pattern. Preregistered means the analysis plan was fixed before data collection. In the study, repairs were picked from documented code fragments, not written free-form. The setup used 73 tasks built from 60 documented API changes in CPython, Node.js and SQLite. A gate that ran every assertion on typical inputs still released about 41% of wrong repairs. These numbers come from a constrained selection task. Treat them as a warning, not a measurement of every AI rewrite. The fix is small, and it is not a guarantee. Write one assertion that exercises the changed contract on an edge input. In the study's main stage, one edge input written from the release note cut the fraction of wrong repairs released to about 6.5%. It reached about 6.1% on 15 unseen clusters. A blind low-cost commercial writer (GPT-5.6-luna) using three inputs reached about 7.0%. Two later frozen stages enlarged the fragment menu to 1491. They also added 233 hard distractors that match legacy output on typical inputs. There, the edge input and the writer each released 5.8% of wrong repairs. This matters because API migrations are routine. A repair that runs cleanly is not evidence of correctness. Your test has to check the new behavior, not just confirm the code still executes. The habit the study points to is still sound. After an API change, add an assertion that would fail if the repair were wrong.
Why AI-Repaired Code Passes Tests and Is Still Wrong — Visual Breakdown
import sqlite3
# DB-API rule: params must be a sequence of values.
# The correct repair passes a one-element tuple.
def get_user(conn, user_id):
return conn.execute(
"SELECT name FROM users WHERE id = ?", (user_id,)
).fetchone()
# A wrong repair builds the SQL with string formatting.
# It looks fine for plain integer ids and breaks on other input.
def get_user_wrong(conn, user_id):
return conn.execute(
f"SELECT name FROM users WHERE id = {user_id}"
).fetchone()
conn = sqlite3.connect(":memory:")
conn.execute("CREATE TABLE users (id INTEGER, name TEXT)")
conn.execute("INSERT INTO users VALUES (1, 'ada')")
conn.execute("INSERT INTO users VALUES (10, 'grace')")
# Happy path: both versions pass on a typical single-digit id.
assert get_user(conn, 1) == ('ada',)
assert get_user_wrong(conn, 1) == ('ada',)
# Edge input: a value that changes the SQL semantics.
# The bound parameter is the literal string "10 OR 1=1".
# It matches no integer id, so the correct repair returns None.
assert get_user(conn, "10 OR 1=1") is None
# The formatted query becomes "WHERE id = 10 OR 1=1", which matches
# the first row, so the wrong repair returns ('ada',) instead of None.
assert get_user_wrong(conn, "10 OR 1=1") == ('ada',) # wrong repair exposed
Quick Concept Check
Test your understanding in 15 seconds
Your AI assistant repairs a function after an API change. All existing tests pass. What is the strongest next step?
Related Concepts
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.