← All notes

AI can rewrite your legacy system. Can you prove it's the same system?

Mistral's Fortran migration is being read as proof that agents made legacy modernisation cheap. What their report actually shows is that the translation was never the expensive part.

Mistral published an account recently of a legacy modernisation project for a European energy operator, and the version doing the rounds is that AI agents migrated Fortran to C++. They did, but that’s not what I found interesting.

The report is narrower and, to their credit, more candid than the summaries of it. The codebase was a physics-heavy reservoir simulator, around 300,000 lines of Fortran 77 with no test suite and no centralised documentation. 40,000 of those lines were migrated, which is impressive and also about 13% of the codebase. Neither the duration nor the cost of the migration was disclosed.

The first attempt turned the agents loose autonomously. What came back was Fortran retyped in C++ syntax with the old architecture intact - COMMON blocks became global structs and GOTO-driven control flow stayed as it was. Mistral’s own verdict is that the result was functional, “but it couldn’t be called code modernization”. The second attempt used a multi-agent pipeline, which improved matters and then hit a bug, tried a few fixes, and stalled with nobody there to unstick it.

What actually worked looks a lot like how a careful team would have done before “the AI age”.

Using the correct tooling

A custom parser modeled the procedural code as a caller-callee tree. Through this process they could pinpoint the modules that operated independently. They subsequently wrote subroutines that export the state of the running Fortran program at designated checkpoints. They also built a test framework that loads those checkpoints into the C++ code for comparison. The teams defined agreement as equality between the final results and the intermediate points that the client’s reservoir engineers had marked as critical.

It was at this stage that the agents proved valuable. Over one hundred agents, using Mistral’s Vibe CLI, documented the codebase beginning with the highest‐level components and proceeding downward. They processed paper documentation via optical character recognition (OCR). A human then coordinated a cycle of coder, tester, and reviewer agents, resolving issues and integrating the suggested changes. The reservoir engineers had already examined the planned architecture before any code was written.

Note the specific strengths of the agents. They were effective at producing documentation, mapping dependencies, and carrying out repetitive translation tasks within an established framework. Note the order of events.

You can’t test against something you can’t run

Each test needs an oracle: something that can tell you what the right answer is. When you’re writing new software the oracle is a specification, a product owner, or a decision somebody made in a meeting. When you’re porting old software, it is usually none of those things.

Twenty years of updates have replaced the original specification, and everyone who wrote it has retired. Whether or not they had, the parity harness is the load-bearing part of the job, and it means running the Fortran in isolation against inputs you control. Mistral calls its codebase self-contained and runnable, and describes that as a “favorable starting condition”. They also say migrations get harder when the code leans on external systems, has no runnable baseline, or hides physics nobody documented.

That is the most significant sentence in the article, and nobody has quoted it. An agent will build you a comparison harness in an afternoon. What it cannot do is generate the state to fill the harness. If the legacy system only runs inside a mainframe partition it shares with other processes, or its behaviour depends on a nightly feed nobody can replay, or the logic lives only in one engineer’s head, then the agents have no baseline to compare against. They will still write C++ code and it will still compile. You just won’t know whether it does the same thing as the system it replaced.

This kind of test isn’t a new idea

Mistral has built a particular kind of test, and it isn’t new. Michael Feathers named it in the 2004 book “Working Effectively with Legacy Code”: characterisation tests. They record what the code does today, bugs included, so you can see when a change alters that behaviour. They are not there to prove the code is correct. They are there to give you something to compare the new version against.

A parity harness is a characterisation suite for a simulator. Export the state, record the outputs, compare the results. Most legacy systems have none, because writing them was tedious and never shipped a feature. AI agents don’t care whether the work is boring.

Here is where the budget should go. In a normal quote, most of the money goes to the rewrite and a slice to testing. If translation is nearly free and the harness is what decides whether the project works, then the money belongs in archaeology: working out what the system actually does and how you will know. A bid with most of the spending in the translation phase is a bid from somebody who hasn’t looked at the legacy system yet.

Feathers identified a specific problem with this method. A characterisation suite records both the intended features and the existing bugs. If the system contains a rounding error from 2003 that downstream reports already account for, the test harness will treat that error as the correct behaviour. A person with domain expertise must decide which behaviours are part of the system design and which are mistakes. AI agents can spot that two numbers differ, but they cannot decide which number is correct for that project.

What this means for large code estates

The National Audit Office reported in January 2025 that government departments were using at least 228 legacy IT systems as of March 2024. There were no fully funded plans to modernise 120 of these systems. These are the specific systems that are currently being considered for migration to AI.

Try defining a runnable baseline for one of those. The business rules are decades of legislation, ministerial amendments and operational workarounds, and they exist nowhere except in the code and in the heads of the people who have maintained it since before most of the team joined. The systems swap nightly batches with other legacy systems. The test environment is a partial copy of production and always will be. Mistral lists knowledge trapped in one engineer’s head as an additional challenge. In a benefits system it is the standard condition, and in core banking the overnight settlement run is the real specification. I doubt anyone has read one of these codebases end to end in years.

Agents still help. Documentation and dependency mapping are exactly what they are good at, and on an estate this size just mapping what exists is a multi-year job. But the expensive parts don’t move. I’ve said before that public sector IT is hard because it has to account for the real world, and that the technology was never the difficult bit. Modernising a legacy system is the same problem: what does the current system do to the person on the end of it, and does the replacement still do that?

How I’d scope one of these projects

Start with a question that rarely comes up in the first meeting. Can you run the existing system in isolation, feed it controlled inputs, and record what comes out? On most systems I’ve met, the honest answer is “not without a lot of work”, and that work is phase one. It carries all the uncertainty in the project, so it should carry the pricing and the people. If the answer really is yes, you’re lucky, and the rest is ordinary engineering.

Build the harness before you translate anything. Use the agents for what they are demonstrably good at: reading the documentation that does exist, mapping the call graph, finding modules that stand alone, drafting the characterisation tests. Run plenty of them. That work is cheap now, and it is always the work that got cut before.

Then split the system and migrate it a module at a time. A person decides what “the same” means every time the harness finds a difference, and every difference is one of three things: a bug in the new code, a bug in the old code that the business has learned to live with, or a rule nobody had written down. That third category is the whole point. The discrepancy log is a more useful deliverable than the code.

AI agents have reduced the cost of rewriting legacy systems. However, they have not reduced the cost of determining how those systems currently function. A rewrite remains a significant risk based on incomplete information until you understand the original logic.

Got something you'd like to talk through?

[email protected] →