Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
ReleaseInsight · On RadarHabr AI→ original

Mistral Ported 40,000 of 300,000 Lines of Fortran to C++ with Agents

Mistral set out to port an oil and gas reservoir simulator to C++: about 300,000 lines of Fortran, with no tests. In the first sprint, the team moved 40,000 lines (about 13%). When the agents were given full freedom, they simply copied the old global variables and GOTO jumps into C++ syntax. What helped were tests that compare numerical results, unified documentation, and modules of up to 10,000 lines with human review. For legacy code, the tests need to come before the agents.

AI-processed from Habr AI; edited by Hamidun News
Mistral Ported 40,000 of 300,000 Lines of Fortran to C++ with Agents
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1More than a hundred agents documented the code from the leaves of the call tree up to the root
First attemptone agent per subroutine, a week for each
Checkthe gas density from the Fortran code (42.71834) must match in C++

The Mistral team helped a European energy company update the development simulator for an oil and gas field. The program performs complex physical calculations and is written in Fortran: about 300,000 lines, with no proper tests and documentation scattered across old PDFs. The goal was to port it to modern C++. In the first sprint, the agents moved 40,000 lines, or about 13% of the codebase. The first result revealed an unpleasant fact, however: AI agents rewrite syntax well, but they drag the old architecture along with them. Instead of new code, they produced global variables and GOTO jumps (commands that "jump to the line with such-and-such label"), only now in C++.

Why a "working" port turned out not to be modernization

Fortran 77 appeared in 1977, and code written in it reflects the constraints of that time. The language has no modules and no composite types. Program state is stored in COMMON blocks, that is, in global memory accessible to the whole program. A variable's type is determined by the first letter of its name, so a typo doesn't break compilation but silently creates a new variable. Names are at most six characters long, which accounts for cryptic names like RHOG and DROG.

In the example from the article, a subroutine calculates gas density using a first-order Taylor formula and writes the result into a global array. In C++, the same logic becomes a function called gasDensity: scattered arrays are merged into a GasProperties structure, the loop over grid cells moves into the calling code, and the result is returned from the function. There is no longer a line-by-line correspondence between the two versions. That makes such a port harder to verify than a simple translation.

In the first attempt, each subroutine was assigned a separate autonomous agent, which spent a week porting it on its own. The code worked, but the COMMON blocks turned into global structures almost one to one, and the GOTOs stayed where they were. The result was Fortran written in C++.

What worked: tests, documentation, modules

The first step was an equivalence check. The agents added state dumps to the Fortran code at key points chosen by the client's engineers. A C++ test framework then loaded these snapshots as reference values. For example, in one run the gas density RHOG equaled 42.71834, and the ported module had to produce the same value. The authors advise starting any modernization project this way: long agent runs become safer, and the word "ported" acquires a measurable meaning.

The second step was assembling documentation. A program written in a procedural language can be represented as a call tree: which subroutine calls which. The team built one with its own parser and ran more than a hundred agents through Vibe CLI. They worked from the leaves to the root, read the required PDFs via Mistral OCR, and each subagent submitted its description of a section as a separate pull request. A reviewer agent ran on a schedule via cron: it checked new PRs and opened tasks for corrections. A side benefit was unified documentation next to the code, with contradictions removed.

The third step was building the process. The second attempt, with a set of roles (planner, developer, tester, reviewer), improved quality, but the agents got stuck on complex code, cycled through fix options, and had no one to help them. The final scheme added a human:

  • Independent modules of roughly up to 10,000 lines of Fortran are identified from the call tree;
  • The agent generates the target C++ architecture, and a simulation engineer approves it;
  • The work is split into tasks in a queue, and each one goes through a "plan, implement, test, repeat" cycle;
  • A human reviews the PRs and requests changes until they are ready to merge.

Limitations and takeaways

The authors are candid that conditions were favorable: the Fortran version is self-contained and runs. For systems with external dependencies, without a working original, or with physical models that are nowhere documented, the job would be harder, and those cases are not covered in the write-up. The article gives no data on token or infrastructure costs, so the project's economics cannot be assessed from it. It also does not say how much time went into human review, which is likely the main hidden cost.

The practical takeaway for teams with legacy code comes down to three steps. First, build tests that compare the numbers of the old and new versions. Then get the documentation in order: if nobody understands the code, an agent won't understand it any better. Finally, don't let agents run free. Agree on the target architecture before work begins, cut the system into modules, and keep a human on review and at the sticking points. The cheapest approach turns out not to be the highest degree of autonomy, but the one where the result can be merged into the main branch without a rewrite.

Story

Key Questions Answered

Why a "working" port turned out not to be modernization?

Fortran 77 appeared in 1977, and code written in it reflects the constraints of that time. The language has no modules and no composite types. Program state is stored in COMMON blocks, that is, in global memory accessible to the whole program. A variable's type is determined by the first letter of its name, so a typo doesn't break compilation but silently creates a new variable. Names are at most six characters long, which accounts for cryptic names like RHOG and DROG.

What worked: tests, documentation, modules?

The first step was an equivalence check. The agents added state dumps to the Fortran code at key points chosen by the client's engineers. A C++ test framework then loaded these snapshots as reference values. For example, in one run the gas density RHOG equaled 42.71834, and the ported module had to produce the same value. The authors advise starting any modernization project this way: long agent runs become safer, and the word "ported" acquires a measurable meaning. The second step was assembling documentation.

What are the key details on Limitations and takeaways?

The authors are candid that conditions were favorable: the Fortran version is self-contained and runs. For systems with external dependencies, without a working original, or with physical models that are nowhere documented, the job would be harder, and those cases are not covered in the write-up. The article gives no data on token or infrastructure costs, so the project's economics cannot be assessed from it. It also does not say how much time went into human review, which is likely the main hidden cost.

ZK
Zhemal Khamidun — Head of AI at Alpina Digital · MIPT (academic supervisor of the Tech Entrepreneurship department). Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Mistral Ported 40,000 of 300,000 Lines of Fortran to C++ with Agents https://news.hamidun.com/en/news/18325/mistral-ported-40-000-of-300-000-lines-of-fortran-to-c-with

What do you think?
Loading comments…