Migrating Legacy COBOL to Java/Python with Codex: GPT-6.1 Sol Hands-On Steps, Choosing Reasoning Effort, and the Money Rounding Trap

On October 19, OpenAI reported that GPT-6.1 Sol scores 86.6% at low reasoning effort and 97.9% at high reasoning effort on its COBOL migration eval. In this post, we connect Codex to gpt-6.1-sol and migrate a COBOL program with fixed-point amounts and missing records to Python, report the measured time and test results at both low and high settings, and explain the truncation and rounding pitfalls.

9 分钟阅读
Migrating Legacy COBOL to Java/Python with Codex: GPT-6.1 Sol Hands-On Steps, Choosing Reasoning Effort, and the Money Rounding Trap

The short version: in its October 19, 2026 post "Advancing coding in low-resource programming languages," OpenAI reports that on its own COBOL migration eval, GPT-6.1 Sol reaches 86.6% accuracy at low reasoning effort, versus just 5.4% for the previous-generation GPT-5.6 Sol under the same setting. At a higher reasoning effort it reaches 97.9%. These are all numbers OpenAI measured itself.

We ran it ourselves too: using Codex connected to this site's gpt-6.1-sol, we migrated a small COBOL program with fixed-point amount calculations and missing-record handling to Python. Low reasoning effort took 113 seconds and high took 221 seconds. In both runs, the migrated program's output matched what GnuCOBOL produced by compiling and running the original program byte for byte, and every test each run generated passed.

For developers who maintain legacy systems in banking, finance, and traditional enterprises, this means AI migration of old code is now workable, with one condition: run the original program first to capture real output as the baseline, then have the AI migrate it, then compare byte for byte with tests.

Create an API Key and start using gpt-6.1-sol →

How to read the two evals

OpenAI ran two evals this time, and they measure different abilities:

  • COBOL migration eval: migrate an existing COBOL program to C++, Java, Kotlin, Python, or Rust. Hidden tests check the result, and observable output must match byte for byte. A migration counts as successful only if all tests pass. It measures "preserving the old program's behavior."
  • MultiLangBench: have a model write a SQLite-compatible database engine from scratch in a specified language, across 20 languages, with the pass rate checked by tests adapted from SQLite. It measures "writing new code in niche languages." OpenAI has put the test set on GitHub.
EvalComparisonOld modelNew model
COBOL migration (low reasoning effort)GPT-5.6 Sol → GPT-6.1 Sol5.4%86.6%
COBOL migration (higher reasoning effort)GPT-6.1 Sol—97.9%
MultiLangBench average across 20 languages (highest reasoning effort)GPT-5.6 Sol → GPT-6 Astra26.8%87.4%
MultiLangBench: COBOLGPT-5.6 Sol → GPT-6 Astra10.9%72.1%
MultiLangBench: FortranGPT-5.6 Sol → GPT-6 Astra21.4%83.5%
MultiLangBench: Visual BasicGPT-5.6 Sol → GPT-6 Astra27.5%89.4%
Source: OpenAI's official post https://openai.com/index/low-resource-programming-languages/ . All figures are OpenAI's own eval results. COBOL is still the hardest language in MultiLangBench.

OpenAI also specifically warns in the post that COBOL fixed-point arithmetic by default drops extra decimal places unless ROUNDED is written explicitly. If a rewrite switches to rounding, the program still runs without errors, but the amounts will differ. Expert review is still needed before production, along with tests based on the system's business rules and dependencies.

Hands-on: migrating a COBOL program with Codex + gpt-6.1-sol

① Create an API Key

After signing up and logging in on this site, go to the console, create an API Key, and copy it for later.

Create an API Key →

② Configure Codex

For how to install Codex, see Codex setup guide. Once it's installed, edit the global config file ~/.codex/config.toml:

toml
model_provider = "aicodewith"
model = "gpt-6.1-sol"
model_reasoning_effort = "low"

[model_providers.aicodewith]
name = "aicodewith"
base_url = "https://api.aicodewith.ai/chatgpt/v1"
wire_api = "responses"
experimental_bearer_token = "sk-你的Key"

Replace sk-你的Key with the Key you copied in the previous step.model_reasoning_effort is the reasoning effort. Eitherlow or high works. You can also leave the file alone and switch temporarily on the command line with -c model_reasoning_effort=high. For more options, see config.toml configuration explained.

In our test, we first called the API directly once, and the model id returned was gpt-6.1-sol, and the Codex run log also showed model: gpt-6.1-sol.

③ Prepare the COBOL sample and capture the original program's baseline output first

The sample program reads two files: accounts.dat holds accounts and rates, and txns.dat holds transaction amounts. Each transaction accrues interest at the account's rate (COMPUTE has no ROUNDED, so it truncates). A transaction whose account isn't found is counted as one missing record and skipped. Totals are printed at the end.

cobol
       IDENTIFICATION DIVISION.
       PROGRAM-ID. INTEREST.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT ACCT-FILE ASSIGN TO "accounts.dat"
               ORGANIZATION IS LINE SEQUENTIAL.
           SELECT TXN-FILE ASSIGN TO "txns.dat"
               ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  ACCT-FILE.
       01  ACCT-REC.
           05 A-ID          PIC X(4).
           05 A-RATE        PIC 9V9999.
       FD  TXN-FILE.
       01  TXN-REC.
           05 T-ID          PIC X(4).
           05 T-AMT         PIC 9(7)V99.
       WORKING-STORAGE SECTION.
       01  WS-EOF           PIC X VALUE "N".
       01  WS-N             PIC 99 VALUE 0.
       01  WS-I             PIC 99.
       01  WS-FOUND         PIC X.
       01  WS-TABLE.
           05 WS-ENT OCCURS 20 TIMES.
              10 WS-ID      PIC X(4).
              10 WS-RATE    PIC 9V9999.
       01  WS-INT           PIC 9(7)V99.
       01  WS-TOTAL         PIC 9(9)V99 VALUE 0.
       01  WS-MISS          PIC 99 VALUE 0.
       01  D-AMT            PIC Z,ZZZ,ZZ9.99.
       01  D-INT            PIC Z,ZZZ,ZZ9.99.
       01  D-TOT            PIC ZZZ,ZZZ,ZZ9.99.
       PROCEDURE DIVISION.
           OPEN INPUT ACCT-FILE
           PERFORM UNTIL WS-EOF = "Y"
               READ ACCT-FILE
                   AT END MOVE "Y" TO WS-EOF
                   NOT AT END
                       ADD 1 TO WS-N
                       MOVE A-ID TO WS-ID(WS-N)
                       MOVE A-RATE TO WS-RATE(WS-N)
               END-READ
           END-PERFORM
           CLOSE ACCT-FILE
           MOVE "N" TO WS-EOF
           OPEN INPUT TXN-FILE
           PERFORM UNTIL WS-EOF = "Y"
               READ TXN-FILE
                   AT END MOVE "Y" TO WS-EOF
                   NOT AT END PERFORM PROCESS-TXN
               END-READ
           END-PERFORM
           CLOSE TXN-FILE
           MOVE WS-TOTAL TO D-TOT
           DISPLAY "TOTAL INTEREST " D-TOT
           DISPLAY "MISSING ACCTS  " WS-MISS
           STOP RUN.
       PROCESS-TXN.
           MOVE "N" TO WS-FOUND
           PERFORM VARYING WS-I FROM 1 BY 1
                   UNTIL WS-I > WS-N OR WS-FOUND = "Y"
               IF WS-ID(WS-I) = T-ID
                   MOVE "Y" TO WS-FOUND
                   COMPUTE WS-INT = T-AMT * WS-RATE(WS-I)
                   ADD WS-INT TO WS-TOTAL
                   MOVE T-AMT TO D-AMT
                   MOVE WS-INT TO D-INT
                   DISPLAY T-ID " " D-AMT " INT " D-INT
               END-IF
           END-PERFORM
           IF WS-FOUND = "N"
               ADD 1 TO WS-MISS
               DISPLAY T-ID " MISSING ACCOUNT - SKIPPED"
           END-IF.

The two data files look like this. Note that account A009 in the third transaction doesn't exist:

text
accounts.dat
A0010035
A0020125
A0030399

txns.dat
A001000123456
A002000099999
A009000050000
A003001234567
A001000000099

The baseline output must come from a real compiler. Don't let the AI "work it out". Install GnuCOBOL on Debian/Ubuntu, then compile and run:

bash
sudo apt-get install -y gnucobol
cobc -x INTEREST.cbl
./INTEREST > expected_output.txt

The real output from GnuCOBOL 3.2.0:

text
A001     1,234.56 INT        43.20
A002       999.99 INT       124.99
A009 MISSING ACCOUNT - SKIPPED
A003    12,345.67 INT     4,925.92
A001         0.99 INT         0.03
TOTAL INTEREST       5,094.14
MISSING ACCTS  01

The first two lines show how much truncation matters: 1,234.56 × 0.035 = 43.2096, COBOL gives 43.20, while rounding would give 43.21; 999.99 × 0.125 = 124.99875, COBOL gives 124.99, while rounding would give 125.00.

④ Have Codex migrate to Python and generate byte-for-byte comparison tests

In the directory containing these files (it's best to git init commit once first so you can review the changes later), run:

bash
codex exec "把 INTEREST.cbl 迁移成 Python 3(interest.py),要求输出和原 COBOL 程序逐字节一致(包括定点运算截断、金额格式、缺失账户处理)。expected_output.txt 是用 GnuCOBOL 编译运行原程序得到的真实输出。再写一个 test_parity.py:运行 interest.py,把 stdout 和 expected_output.txt 逐字节比较,并额外构造几条会暴露“四舍五入 vs 截断”差异的测试数据,用 cobc 编译原程序跑出期望值做对比。最后运行测试并报告结果。"

To migrate to Java, swap out Python 3 and the file names in the prompt. The comparison-test approach is the same. For everyday interaction with Codex, see How to use Codex.

Here is the core calculation generated in the low-effort run. It works in integer cents and implements truncation with integer division, and the comment explains why:

python
amount = number(record[4:13])
# No ROUNDED clause: discard fractional cents before adding to total.
# Assignment to unsigned PIC fields also discards excess high digits.
interest = (amount * rates[account] // 10_000) % 1_000_000_000
total = (total + interest) % 100_000_000_000

The generated tests pick boundary values where truncation and rounding give different results (for example, products that come out to 0.5 cent, 1.5 cents, or 0.9999 cent). For each case, they compile the original program with cobc on the spot to get the expected value, rather than hardcoding the answer.

⑤ Run once at low and once at high

Using the same prompt and the same files, run once with -c model_reasoning_effort=low and once with -c model_reasoning_effort=high. Results:

Reasoning effortTimeGenerated testsByte-for-byte match with original program
low113 seconds6 tests, all passedYes
high221 seconds11 tests, all passedYes

After the runs, we also checked in the terminal ourselves, comparing the output of python3 interest.py with expected_output.txt using cmp. Both runs matched exactly.

The difference between the two levels is mainly test coverage. High additionally tested file-format edge cases such as Windows line endings, a missing newline on the last line, and overlong lines being split into multiple records, and it also ran a comparison on 5,000 random transactions. For a program this small, low is enough. The bigger the program and the more edge cases it has, the more worthwhile high becomes.

Pitfalls you need to know about

Truncation vs. rounding

In COBOL, COMPUTE without ROUNDED truncates, whereas Python's round() and Java's BigDecimal.setScale(2, RoundingMode.HALF_UP) are rounding. This kind of difference throws no error. It just leaves the last cent of some accounts off. Say "keep truncation" explicitly in the prompt, and put data in your tests that specifically exposes this difference.

Missing records

In legacy programs, rules like "skip and count if not found" or "use a default value if not found" are often the business rules themselves. During migration they are the easiest to "improve while you're at it" into thrown exceptions. In our example we deliberately included a transaction for an account that doesn't exist.

Add tests to the legacy system first, then migrate

Without a baseline, you can't tell whether the migration is correct. First run the original program through a real compiler on a range of inputs and save the outputs, then start migrating. For how to have Codex add tests to legacy code, see Using Codex to fix real bugs and run tests; to clear out unused sections before migrating, see Using Codex to clean up dead code.

Code that runs is not the same as code that behaves the same

New code that compiles and runs only shows the syntax is right. Details like field width, high-order digits dropped on overflow, and amount display format only show up when you compare output byte by byte. OpenAI's evaluation also counts a run as successful only if all tests pass byte for byte.

Choosing a model: gpt-6.1-sol or gpt-6-astra

  • Migrating existing COBOL code with behavior unchanged: use gpt-6.1-sol. OpenAI's COBOL migration evaluation reported its results with this model.
  • Writing larger new features in niche languages like COBOL, Fortran, and VB: you can try gpt-6-astra. Its MultiLangBench score was achieved at the highest reasoning effort.

For a comparison of gpt-6.1-sol and Claude, see GPT-6.1 Sol vs. Claude Opus 5.5.

Common errors

FAQ

Can Codex migrate an entire COBOL system in one go?

You can migrate one program at a time, but each program needs baseline output from a real compiler and comparison tests first. OpenAI also states clearly that before use in production systems, expert review is still required, along with testing against business rules and dependencies.

I don't have a COBOL compiler installed. Can I have AI infer the original program's output as the baseline?

Not recommended. The point of a baseline is "real behavior," and AI-inferred output can itself be wrong on truncation or formatting. GnuCOBOL is free and installs with a single command.

Should I choose low or high reasoning effort?

For small programs with simple logic, start with low, which is about twice as fast. For larger programs with many file formats and edge cases, use high, which adds more edge-case tests on its own. In this run, both levels got the migration right on the first try.

Can I migrate to Java?

Yes. OpenAI's evaluation covers five target languages: C++, Java, Kotlin, Python, and Rust. Swap the target language in the prompt, and the comparison-testing approach stays the same.

View the gpt-6.1-sol model page →