A shift register, written in Structured Text. The reference implementation assigns the bits in reverse order, which preserves the old values. The model-generated one assigns them forward, starting with Q0 := D0. Both compile. Both run. Both end with the same output.
At scan 11 the set branch drives the register to 1111. At scan 12, a shift with D0 = 0 produces 0111 in the reference and 0000 in the candidate — the new value walked across all four bits. At scan 14 the reset branch makes them agree again.
If your acceptance test is "imports with 0 compile errors", this program passes. If it's "check a few properties", it depends on which property. If it's "look at the final outputs", it passes too. Only a per-scan comparison catches it.
That's the whole argument of a 2026 paper from Beihang University — Compilation Is Not Correctness: Scan-by-Scan Evaluation of LLM-Generated PLC Programs (arXiv:2610.28675) — and the numbers are worse than the anecdote suggests.
What they built
CycleBench: 301 Structured Text tasks (287 function blocks + 14 programs), 684 scenarios, 61,424 scans. Each task ships with a reviewed public spec (behaviour requirements, POU identity, I/O interface, initial values, parameters), a hidden reference implementation, hidden input scenarios, and the expected per-scan output trace.
The evaluator compiles both sides with a pinned Matiec → C → GCC pipeline, drives reference and candidate in fresh sessions with identical inputs, identical public initial values and a virtual clock advanced one scan interval at a time, then compares every declared output and inout after every scan. No trajectory alignment. The first scan counts. All tasks stay in the denominator — missing candidates, interface violations, build failures and runtime failures are all failures, classified by stage.
The gap: 11.92 points
Across 8 LLMs × 4 baseline methods = 9,632 results:
| Compiles | Passes execution | |
|---|---|---|
| All baseline results | 83.99% | 72.07% |
| Best method (CycleGen) | 94.89% | 83.31% |
That's 11.92 points (95% bootstrap CI [9.63, 14.43]) of programs that build and then behave wrong. The gap exists in every model–method combination, including combinations with a compile rate above 99%.
It also gets worse with size: grouping by reference length, the gap is 3.67 points for 1–20 line programs and 24.07 points for programs over 80 lines. Longer, more stateful programs are exactly where compilation stops telling you anything.
Why it hides: transient mismatches and sampling phase
The failures don't usually sit at the end of the trace. 144 of 157 audited behavioural failures re-converge inside the scenario, and in 115 of 157 no mismatch run lasts more than 5 consecutive scans.
So the natural habit — "check every Nth scan" — is a sampling problem, not a coverage problem:
| Observation policy | Behavioural failures missed (of 157) |
|---|---|
| Every scan | 0 |
| Every 2 scans | 11 (7.01%) |
| Every 5 scans | 34 (21.66%) |
| Every 10 scans | 47 (29.94%) |
| Last scan only | 98 (62.42%) |
Even with scenario endpoints always checked. And the phase matters: shifting which scans you look at — same programs, same inputs — moves the miss rate for stride 5 between 12.10% and 28.03%. No fixed phase finds everything.
The paper's second example is a timer, which is the version PLC engineers will recognise instantly:
(* candidate: uses the previous scan's input *)
TOF0(IN := pir_active, PT := T#20s);
(* ... manual override update ... *)
pir_active := stairs_pir_sensor AND NOT lights_buttons_state;
stairs_light := lights_buttons_state OR TOF0.Q;
The off-delay timer is called before pir_active is assigned, so it consumes the value from the previous scan. The lamp is wrong at scan 7 and correct again at scans 8–9. Look at the later scans and you will never know.
Where the failures cluster (use this as a checklist)
Of the 157 audited behavioural failures:
| Category | Share |
|---|---|
| Public output update | 27.4% |
| Arithmetic / boundary logic | 22.3% |
| Timing / call order | 15.9% |
| Reset / priority | 9.6% |
| State retention / overwrite | 8.9% |
| Edge detection | 8.3% |
| Initialisation | 5.7% |
The first three categories are 65.6% of behavioural failures. Note what dominates: not fancy algorithms, but when a value is written, which boundary condition was missed, and whether a stateful block was called before its inputs were current. Compile errors, by contrast, are boring: 53.42% of them are malformed statements or declarations — the compiler already tells you about those.
Generation can improve, but it doesn't close the gap
The authors then built CycleGen: generate k candidates, repair compile errors with bounded compiler feedback, write runtime self-tests in a separate model context, and pick the candidate that passes the most self-tests.
Execution pass rate goes 74.63% → 83.31% (+8.68 points). The ablation is the interesting part, because it prices each piece:
| Configuration | Compiles | Executes | Avg tokens |
|---|---|---|---|
| Direct, 1 candidate | 84.93% | 74.63% | 1,929 |
| 5 candidates, take first valid | 92.23% | 79.94% | 9,740 |
| + compiler-guided repair | 94.85% | 81.69% | 11,922 |
| + self-test selection | 94.89% | 83.31% | 18,197 |
Two things worth internalising:
- Diminishing returns are brutal. k=5 → k=8 buys 0.87 points going in… and then loses 4 passes while spending 38.8% more tokens. The observed k=5 dominates its own extensions.
- Model-written tests are a signal, not an oracle. Only 54.35% of self-test suites accepted all bound reference cases; mutation detection was 73.33%; only 43 of 192 suite slots caught any mutant. Using them to rank candidates is useful. Using them to declare correctness is not.
And the gap persists at the top: CycleGen still leaves 11.59 points between compiling and behaving.
What this means if you're shipping generated PLC code
Three layers, and the paper's 11.92-point gap is the cost of skipping the middle one:
- Structural validation — parse, interface check, compile. Fast, cheap, and provably insufficient on its own.
- Per-scan behavioural regression — same inputs, same initialisation, same logical clock, compare every declared output on every scan. This is the layer that catches the shift register and the timer.
- Full-machine and on-hardware verification — PLCSIM Advanced or the real controller, when you care about communication, motion, I/O channels and scan jitter.
We build for layers 2 and 3. TiaLink drives a local TIA Portal over Openness (V17–V21): it indexes the project into a knowledge graph — call relations, cross-references, DB member reads and writes, dangling references — so a change's blast radius is visible before you write, and LAD blocks go through a LadDoc schema check before import and compile. Our cloud simulator handles the per-scan execution side with deterministic scan semantics, timer ticks injected via tickMs.
Boundaries (what we did not do)
- We did not run CycleBench. We did not reproduce its scores. This is our reading of the paper, with the tables re-checked against the PDF.
- Deterministic scan semantics is not physical real time. Injected scan intervals make regression repeatable; they do not reproduce scan jitter, communication timing or hardware response.
- Our simulation path covers a subset of IEC 61131-3 (IF/CASE/FOR/WHILE, arrays and structs, timers, edges), not the whole language, and not communication, technology objects, motion control, safety programs or hardware channels.
- Passing the benchmark means "matches a reference on the provided finite scenarios" — not functional correctness, termination, or physical safety. The authors say this themselves, and it's worth repeating because it is the most common way this kind of result gets over-read.
Paper: Jinyun Chen, Juntao Hu, Haochen Li, Wentao Song, Ningbo Gu, Jianwei Niu, Qing Gao, Rui Wang. Compilation Is Not Correctness: Scan-by-Scan Evaluation of LLM-Generated PLC Programs. arXiv:2610.28675, October 2026.
If you're evaluating LLM-generated PLC code today, the cheapest thing you can steal from this paper is the acceptance rule: a task passes only if every declared output matches on every scan. Everything else — properties, sampled scans, final values — is a filter that lets a known class of bug through.
Top comments (0)