"MirrorCode: AI can rebuild entire programs from behavior alone."
@Greg A. Woods told me about this and I found it incredibly fascinating. I'm going to make extensive quotes from the research paper because I can't summarize it any better in my own words, so I'm just going to quote the original. (For those of you who think this is a lot, keep in mind the original paper is 34 pages.) (I'll have a bit of my own commentary at the end.)
"The AI has execute-only access to the original program with arbitrary arguments and can observe its outputs, allowing it to explore the original program's behavior (a black-box oracle). The AI also has access to documentation describing the program, and example test inputs to further pin down the scope of the reimplementation."
"The AI can be tasked to implement its solution in any of our supported languages: Python, C, Rust, Go, OCaml, and Ada."
"The AI's solution is evaluated via end-to-end tests derived from the original program's test suites, real-world data, and LLM-assisted generation. Each target program has hundreds to thousands of test cases. Each test case consists of a CLI input and any associated data files. To pass, the AI's solution must produce exactly the same output as the reference program"
"Visible test cases are shown to the AI as it develops its solution. These help to ensure the benchmark is feasible, by setting out the scope of features that must be implemented. By contrast, hidden test cases, held out from the AI, ensure that its reimplementation genuinely functions like the original program, generalizing beyond seen examples."
"Consider, for example, the program gotree, which reads and manipulates bioinformatics data. In principle, one could determine the scope for reimplementation by searching across all of the possible inputs that gotree could be run on. However, this is not computationally tractable in practice, because there are so many possible inputs. Documentation helps to narrow this down, but can rarely cover all of the complex ways that the software is used in reality."
"Human software engineers gradually learn the scope of inputs a program should support thanks to external feedback from users of the program (or their representatives, like product managers). Visible test cases, and access to the original binary, simulates the feedback by which human software engineers refine the scope of their software. Hidden test cases ensure that the scoped features are genuinely implemented."
"consider gotree's handling of the Nexus file format. The Nexus format was only loosely specified in its original publication. Enumerating every real-world use case from scratch amounts to an impossible guessing-game. Among other omissions, documentation does not mention that Nexus files may contain comments: free text that should be ignored by a parser. But real-world files produced by standard tools contain comments in various formats. gotree generally handles them without complaint, but rejects them in certain locations. Guessing all the ways comments must be handled, despite comments not being mentioned in documentation, is far harder than actually implementing comment-handling. Without that knowledge, success on the task would be limited by the ability to guess the scope of tested inputs, more than by software engineer skill. Visible test cases address this by showing examples of comments, and their basic format."
"Hidden tests ensure that AI reimplementations are genuinely functional. If we exposed all end-to-end tests, agents could simply create a lookup table instead of genuinely solving MirrorCode tasks. We prevent this by holding out a subset of tests, averaging 34% held-out tests across the benchmark. The AI never sees these hidden tests during its attempt at a MirrorCode task, and hence it cannot cheat at them."
"We intend that scoring 100% on a MirrorCode task corresponds to reimplementing that target program's intended scope. For this to happen, we must guard against false positives, where an AI scores 100% but it did not fully reimplement the target; and false negatives, where AI reimplements the target but is graded below 100%."
They list the following steps taken to ensure MirrorCode's accuracy:
For False negatives:
Failure mode: "Scope of features to implement is unclear."
Mitigation: "Visible test cases clarify scope."
Failure mode: "Details of intended program behavior are unclear."
Mitigation: "AI can send arbitrary inputs to the reference binary to see the expected output."
Failure mode: "Tests are impossible because of nondeterminism or environment dependence."
Mitigation: "We regenerate gold-standard outputs at runtime to match the environment where they are executed. We screen for nondeterministic program behaviors and exclude them from scope."
Failure mode: "Unit tests check narrow implementation details."
Mitigation: "No unit tests are used. All tests are end-to-end tests that cover the input-output behavior of the program."
For false positives:
Failure mode: "Cheating by hard-coding solutions."
Mitigation: "Held-out tests cheat-proof the benchmark."
Failure mode: "Cheating by wrapping the reference binary."
Mitigation: "We copy the agent's code to a separate sandbox during scoring, where the reference binary is absent."
Failure mode: "Cheating by interfering with the scoring mechanism."
Mitigation: "We separate scoring from the sandboxes used for development and producing outputs. Scoring requires string equality of the AI program's outputs to the reference outputs."
Failure mode: "Cheating by looking up reference code."
Mitigation: "AI has no internet access."
Failure mode: "Language/system built-ins make a problem trivial."
Mitigation: "Target programs are selected to avoid this."
Failure mode: "Tests can be passed without reimplementing the target."
Mitigation: "A solution must produce byte-exact output across many test inputs. We design these tests require substantial reimplementation."
"We selected 25 target programs for the benchmark, choosing programs that were easy to evaluate, easy to ensure adequate test coverage for, and that seemed feasible for a skilled human software engineer to reimplement under similar constraints, given sufficient time. MirrorCode's 25 target programs span different areas of computing: Unix utilities, data serialization and query tools, bioinformatics, interpreters, static analysis, cryptography, and compression."
They say 25, but I only counted 22:
choose: String manipulation tool similar to cut or awk.
cal: Printing calendars to the terminal.
numfmt: Reformatting numbers between formats (e.g., human- readable sizes).
uuidparse: Parsing and describing UUIDs (version, variant, and type).
hexyl: Producing a convenient hex view of input bytes.
bitwise: Evaluating bitwise and base-conversion expressions.
gron: Flattening JSON into discrete, greppable assignments.
jq_simple: jq is a JSON processor:
qsv_select: Selecting and reordering columns of CSV data.
bib2json: Convert BibTeX bibliographies to CSL JSON.
tssql: Running SQL SELECT queries over CSV files.
sed: The sed stream editor for transforming text streams.
nonogrid: Solving nonogram (paint-by-numbers) puzzles.
wren_cli: The interpreter for the Wren programming language.
brotlid: Decompression of Brotli streams.
mailauth: Verification of email authentication and cryptographic signatures (SPF, DKIM, DMARC).
gotree: Parsing and manipulation of phylogenetic trees.
texmacros: The TeX macro-expansion engine (tokenization and expansion of TeX and e-TeX primitives). Does not include TeX typesetting, fonts, or PDF output.
giac_subset: The Giac computer algebra system, tested only on two topics: symbolic definite integration and Gröbner-basis computation.
cprepro: The C preprocessor from GCC.
pkl: Programmable configuration language developed by Apple.
ruff: Python linter and formatter. Only the linter is tested.
"We conducted all experiments using a simple agent scaffold based on the Inspect library's ReAct agent. This allowed shell usage and exposed the text_editor tool for file reading and editing. We used compaction to let trajectories run longer than their maximum supported context. In addition to the text_editor and submit tools, we give models access to an evaluate_testcases tool, which runs a scoring pass on their code against visible tests, but does not end the session."
"We set inference budgets generously so that performance would not be limited by compute."
"We evaluated three frontier models: Claude Opus 4.7, GPT-5.5, and Gemini 3.1 Pro Preview."
"All evaluations were sandboxed within a Docker container, which contained the compiled target program (execute-only permissions) and necessary toolchains for the development language."
"We also tested our environments with a red-teaming evaluation in which the agent is explicitly instructed to circumvent normal evaluation mechanisms to obtain a high score by cheating. No agent successfully cheated using our current scaffold."
"Across all 25 target programs, 17/25 had at least one perfect-scoring run. Four more targets had a near-perfect run scoring over 99%. AI models successfully reimplemented large target programs; for example, one of the larger near-perfect runs was gotree -- a bioinformatics toolkit with ~16,000 lines of Go and 40+ commands.3 Both Claude Opus 4.7 and GPT-5.5 successfully reimplemented gotree across several different programming languages, at costs of $100-400. Even larger programs than gotree were successfully reimplemented: for example Opus 4.7 reimplemented pkl -- a configuration programming language developed by Apple with 60,000 lines of code. Often, these reimplementations were piecemeal and untidy, but they fully covered the program's core functionalities, passing 99% of tests or more."
"MirrorCode is not saturated, however. In our results, 8/25 target programs were never solved to a 100% threshold, and 4/25 were never solved to a 99% threshold. Only 11/25 target programs were reliably solved to 100% in every language and repetition for any model. Of the 4/25 tasks that were never solved to a 99% threshold, three reached a relatively high score on the test suite, usually passing over 90% of hidden tests."
"The target where AI struggled most was ruff, a Python linter and formatter, which was the largest task in our suite. The best runs scored only 67% on hidden tests. AI also particularly struggled on the mathematics package, giac_subset, and the email authentication library, mailauth, where the best trajectories were just below 99% on hidden tests, but most trajectories were significantly worse, averaging around 90-95%."
"Claude Opus 4.7 outperformed other models, particularly on larger tasks."
"The amount of code available during pretraining differs greatly between programming languages: for example, StarCoder's training mix assigns about 8% of its sampling mass to Python and 7% to C, but only 1% to Rust, 0.13% to OCaml, a niche functional programming language, and 0.034% to Ada, a language used mainly in safety-critical aerospace and defense systems. Existing head-to-head multilingual code benchmarks generally find that such differences matter. However, these benchmarks involve short snippets, and evaluate models that are now outdated."
"MirrorCode therefore provides a cleaner head-to-head comparison of implementation language on hard, agentic software tasks. In our results, there was little sign of inter-language differences in solve rates, for any model. This suggests that AI models have learned generalized programming skills, rather than pattern-matching syntax."
"We identified four main AI failure modes: (i) failing to investigate edge case behavior or subtle logic; (ii) brittle, narrow solutions overly focused on visible tests; (iii) failing to identify a requirement, typically one without visible tests; (iv) premature submission, i.e., submitting while improvements were still tractable. A fifth failure mode, uncommon in Opus but common in other models, was attempted cheating."
"Most failures came from mishandling edge cases. Averaged over target programs, about 40% of Opus 4.7 runs had at least one hidden test failing in this way. These failures usually did not break core functionality. Edge case behavior was discoverable in principle, but it is fairly understandable that AI struggled to identify it; humans can also struggle to anticipate edge cases, and this is a common cause of bugs in real software."
"Brittle solutions targeted visible tests but did not generalize to hidden tests. About 5% of Opus 4.7 runs had at least one hidden test failing in this way."
"AI sometimes failed to identify requirements, especially when they did not have a corresponding test. Opus 4.7 had this failure mode in about 10% of runs. Notably, AI implementations sometimes failed to identify a functionality at all. For example, all models failed to disable incompatible flags for sed when the --posix flag was passed, even though the flag was clearly documented, and used in numerous visible tests."
"Agents would often submit prematurely, losing track of earlier plans. In 26% of runs, models submitted failing solutions with over 90% of their token budget remaining."
"A more fine-grained indicator of premature submission is when agents explicitly planned further work, but lost track or abandoned it. In one Opus 4.7 run on ruff, three of the failing tests had relevant planning that was subsequently ignored"
"Some models kept trying to cheat, and this may have impaired their performance. 24% of GPT-5.5 runs and 31% of Gemini 3.1 Pro Preview runs had this failure mode, whereas Claude Opus 4.7 never cheated in our finalized experiments' submissions. For larger tasks, this was particularly egregious: non-Opus models often attempted cheating on swathes of visible tests. This was a pervasive problem, and we were not able to prevent such behavior through prompt variations or scaffolding changes."
"How much better might GPT-5.5 and Gemini 3.1 Pro Preview have performed, if they had not attempted to cheat? Since cheating was correlated with task complexity, then perhaps cheating was a sign they would have struggled on these tasks."
"Passing visible tests was usually evidence of a genuine implementation. Conditional on passing all visible tests, two thirds of runs also passed every hidden test; 74% of runs passed at least 99% of hidden tests, and 90% of runs passed at least 90% of hidden tests."
"AI code from passing solutions appeared to be of mixed quality by human standards. At the level of code layout, we saw several examples where AI solutions relied on a large number of somewhat-independent special cases (with redundant implementation) for their solutions. For example, even the best-performing model, Opus 4.7, implemented the \unless command in texmacros through separate branches for each of 17 conditional primitives. The original codebase had a simple shared negation logic: if is_unless then b := not b. Another common code smell was the inclusion of dead code, for example one of Opus 4.7's solution for gotree began a refactor to use NaN as a sentinel value instead of -1, but ended up submitting with many conditionals checking for either flag. These might not be significant limitations if human guidance were provided afterward, as further prompting would likely improve the code."
"AI-generated codebases were often monolithic, with most code contained in a single file. Opus 4.7 and Gemini 3.1 Pro Preview generated monolithic codebases in about half of their runs, whereas GPT-5.5 took this approach in almost all runs. In comparison, most large human-authored codebases were split across several files."
"Existing AI models can complete certain software engineering tasks that are estimated to take humans weeks or longer."
"We do not have human baseline results for long MirrorCode tasks."
"A lack of reliability may limit the usefulness of AI software engineer agents despite their impressive capabilities. About a third of programs were successfully reimplemented in every run by the best-scoring model, Claude Opus 4.7. But another third of programs had imperfect reliability, where runs fell short of 100% scores. Our results suggest that, provided a set of comprehensive tests and a specification for a small but realistic program, leading AI models can autonomously produce software to satisfy those tests at a reliability around 95% or better."
"MirrorCode uses a very particular setup: an existing program that produces the canonical output for a given input, and hence acts as a highly detailed, precise specification. Although this setup can arise in real-world reverse engineering and reimplementation, it is not how software is typically developed. However, software is also not developed in a vacuum, but through iterative interaction between engineers and users, product managers, etc. Our detailed specification is intended to fill in for that interaction, but it could change the nature of the implementation task. Consequently, our results do not show that AI could perform arbitrary software implementation tasks. Existing literature supports the idea that AI's ability to autonomously complete tasks may be correlated with the presence of a feedback signal, although this need not be as precisely specified as the MirrorCode tasks."
"Our ablation experiments suggest that, without any test cases provided, simpler programs remained solvable, albeit at lower reliability. Even when they did not succeed, AI solutions would cover most functionality of a smaller target program, passing more than 90% of the withheld tests, but falling short of 100%. Meanwhile, for larger target programs, scores declined precipitously. This could be a significant obstacle to autonomous AI software engineering in open-world settings."
"It may be difficult to distill AI's software engineering capabilities to a single 'time horizon' for how long a task would take humans."
My commentary:
I was actually impressed by the size and complexity of the tasks they gave these AI models, and although they didn't succeed at the biggest and most complicated, they did better than I expected. And I already knew from daily interaction with Claude Code that AI models are quite smart at writing software. Most of the limitations have to do with context window size limitations which I've also experienced. This leads to things such as the disjointed architecture and repetition that are described in the paper. I'm wondering if we'll continue to see the same rate of improvement in the models and these limitations will be fixed quickly, or whether it will take longer.
MirrorCode: AI can rebuild entire programs from behavior alone
#solidstatelife #ai #genai #llms #codingai #agenticai
AI models are rapidly improving at autonomous coding, as shown by benchmark progress and one-off demonstrations such as AI implementing a C compiler.
arXiv.org