Editor’s introduction
The study evaluated three LLM variants—GPT-5.5, GPT-5.4-mini, and GPT-4.1-mini—within the FlowRepair framework for repairing faulty Stateflow models. It compared LLM-generated mutations against the original hand-crafted mutation operators, using 19 real-world models from four cyber-physical systems. Results showed that LLM-based mutations produced valid patches for only four models and plausible patches for four, compared to 18 and 16 valid patches with the original method. The LLMs struggled with precise symbolic edits and failed to generate effective solutions for faults requiring accurate value synthesis or structured expression insertion. The findings indicate that direct integration of LLMs as mutation operators does not enhance repair performance in this context. The evidence suggests that LLMs generate a noisy search space and lack behavioral feedback, limiting their utility in search-based automated repair under the tested conditions. These results reflect limitations in how generative models are currently applied as mutation operators, rather than indicating a general failure of LLMs in software repair.
Introduction
Cyber-Physical Systems (CPSs) integrate computational elements with physical processes. Due to their reliance on complex and expensive hardware, their software is typically validated through simulation-based testing during early development stages. MATLAB/Simulink has become the de facto platform for CPS modeling and simulation, supporting features such as automated test generation and standards-compliant code generation. CPS control architectures commonly separate high-level decision-making from low-level control, with high-level logic often implemented using Stateflow statecharts within Simulink. Although substantial research has addressed automated test generation for Simulink models, the repair of detected faults remains largely manual, motivating the need for Automated Program Repair (APR) techniques for Simulink models.
A recent study proposed FlowRepair, a search-based APR technique for Stateflow models. In addition to novel repair objectives targeting CPSs, FlowRepair integrates global and local search and adopts novel repair mutations for Stateflow models. Like many other search-based APR repair tools, FlowRepair has one core limitation: The repair capability is limited by the implemented mutation operators. On the one hand, if the number of mutation operators is limited, the tool may not have the ability to repair many types of bugs. On the other hand, if the number of mutation operators is high, the search space may become exceedingly large, making the APR technique not scalable, especially in the context of systems with computationally expensive executions.
To deal with this problem, in this paper we propose using Large Language Models (LLMs) as mutation operators. We replace key FlowRepair mutation operators with an LLM-based mutator that are able to generate repair candidates directly from the faulty Stateflow model. Instead of relying on a fixed set of predefined mutation templates, the LLM dynamically proposes modifications. This allows the repair process to explore a broader and more flexible search space while avoiding the need to manually design a large number of mutation operators. The generated candidates are then evaluated within the existing search-based repair loop, where FlowRepair’s fitness functions assess whether the modified model is closer to resolving the detected bug.
We evaluate our approach using the same experimental setup as the original FlowRepair paper to ensure a controlled comparison under the same wall-clock budget between the traditional mutation-based repair strategy and the proposed LLM-based mutation generation. Surprisingly, the results are substantially worse, indicating that the LLM-based approach does not outperform the original search-based APR technique. In fact, replacing handcrafted mutation operators with LLM-generated mutations substantially reduced repair effectiveness in the observed results in most cases under this experimental setup. While the LLM is able to generate plausible repairs for a small subset of faults, the overall repairing ability and consistency remain substantially lower than those achieved by FlowRepair. These findings highlight important limitations of using LLMs as mutation operators in simulation-based CPS repair contexts and suggest that naively replacing rule-based operators with generative models may degrade repair performance rather than improve it.
Background on How FlowRepair Works
FlowRepair is a search-based APR technique for repairing faults in Simulink-Stateflow models of CPSs. Unlike traditional APR techniques, which rely on large, fast-executing test suites, CPS validation requires expensive simulations of both the controller and the physical environment. This imposes strict constraints on test execution and available failure information. In CPS testing, a single simulation may require a complete system-level execution, where the software controller and physical plant interact over time. Therefore, repair methods that depend only on counting passing and failing tests provide limited guidance, especially when only one failure-inducing test is available, as is common in falsification-based testing of CPSs.
To address this, FlowRepair first performs fault localization using Spectrum-Based Fault Localization (SBFL). The Stateflow model is instrumented so that the execution of states and transitions can be recorded for each test case. The available passing and failing tests are then executed, and the collected execution traces are used to compute a suspiciousness score for each Stateflow component. FlowRepair uses the Tarantula metric for this purpose. Components that are executed more frequently by failing tests and less frequently by passing tests receive higher suspiciousness scores. These scores are then used to rank the states and transitions according to their likelihood of being faulty. This ranking does not directly identify the fault, but it guides the repair algorithm towards the most suspicious parts of the model and reduces unnecessary mutations on less relevant components.
After fault localization, FlowRepair starts the patch generation process. The repair algorithm receives the faulty Simulink model and the suspiciousness ranking as input. During the repair process, FlowRepair maintains two archives. The first archive stores plausible patches, which are candidate repairs that pass the available test suite. The second archive stores partial patches, which are modified models that do not fully pass the failing test but improve the model behaviour according to the repair objectives. A partial patch is therefore treated as a useful intermediate repair because it moves the search closer to a complete fix without necessarily satisfying all requirements yet.
Patch generation is guided by a hybrid search strategy that combines global and local search. The global search is responsible for exploring different candidate mutations across the suspicious states and transitions. To select the component to mutate, FlowRepair uses the suspiciousness ranking through a roulette-wheel selection strategy. This means that components with higher suspiciousness scores are more likely to be selected, while components with lower scores can still be selected with smaller probability. This allows the search to focus on likely faulty areas without completely ignoring the rest of the model. Once a component is selected, FlowRepair applies one compatible mutation operator and executes the resulting model using simulation-based testing.
The test execution returns a verdict for the mutated model. If the mutated model passes the available test suite, FlowRepair stores it in the plausible patch archive. If the model still fails, FlowRepair checks whether the verdict has improved compared with the previous model. A verdict is considered improved when at least one repair objective is improved and none of the other objectives becomes worse. In that case, the mutated model is added to the partial patch archive, and the local search process is triggered. This archive-based mechanism is useful because it preserves promising intermediate solutions instead of discarding them immediately. Since some partial patches may later lead to valid repairs, FlowRepair keeps them available for further mutation.
Experimental Configuration
Overall setup: The experimental foundation of this study follows the setup established in the prior work by Arrieta et al., which we adopt to ensure a controlled comparison under the same wall-clock budget between randomized and LLM-based mutation strategies. We use the same dataset and bug benchmarks, along with an identical preprocessing pipeline for fault localization, suspiciousness score calculation, and evaluation metrics defined in their study. Furthermore, all experiments are executed within the same infrastructure and computational environment described in the FlowRepair paper. By reusing this setup rather than redefining it, we maintain methodological consistency and focus our contribution on analyzing how LLM‑driven repair behaves under the same controlled conditions.
Algorithm Configuration: The repair process was executed with a time budget of 1 hour and a maximum of 30 local repair attempts on partially improved patches, these values remain constant across all runs. Under this configuration, each run produced between 62 and 675 candidate patches with GPT-5.5, between 56 and 615 with GPT-5.4-mini, and between 75 and 713 with GPT-4.1-mini. The fault localization was guided using the Tarantula suspiciousness metric, one of the most widely used SBFL techniques.
Evaluation Metrics: As in, for each execution, two evaluation metrics were collected: the number of generated plausible patches, defined as patches that pass the simulation-based test suite, and the number of generated valid patches, i.e., plausible patches manually inspected by a software engineer and judged to implement the same corrective behavior as the developer patch. The Mean, minimum, and maximum summarize patch occurrences across five independent executions, where each generated patch is counted as one occurrence, including repeated identical patches. Therefore, these metrics quantify patch generation frequency rather than patch diversity.
Employed LLM: We used GPT-5.5 as the initial model for the LLM-based repair because it offers strong reasoning ability for handling semantic changes in Stateflow labels. To assess whether the observed results are robust across different model choices, we additionally evaluated GPT-5.4-mini and GPT-4.1-mini. These smaller variants offer a better balance between performance and computational cost, allowing us to execute many repair attempts within the fixed time budget and repeat experiments across multiple models. The additional experiments help determine whether the observed repair behavior is specific to GPT-5.5 or remains consistent across different LLM variants. For patch generation, we used a fixed temperature of 0.8 for all LLM configurations to encourage diverse patch generation while maintaining a controlled comparison across models, consistent with other LLM-based APR studies. Since the objective of this study is to evaluate LLM-generated mutations as a direct substitute for FlowRepair’s domain-specific operators, keeping the decoding configuration fixed avoids confounding the comparison with additional parameter tuning.
Dataset of real bugs: The evaluation of the LLM-based repair approach was conducted by replicating the original FlowRepair paper, using the same dataset originally introduced in FlowRepair, which consists of 19 faulty Stateflow models from four different case-studies. Table II summarizes the structural characteristics of the Stateflow case-study models.
RQ1- Repairing ability of the LLM-based approach
The results of our evaluation are summarized in Table III and Table IV. Table III reports the plausible patch results, while Table IV presents the corresponding valid patch results across five independent runs. Across the five executions performed for each faulty model, the LLM-based repair approach showed limited repair ability across all evaluated LLM variants. GPT-5.5 generated plausible and valid patches for 4 out of the 19 models. GPT-5.4-mini generated plausible patches for 6 models and valid patches for 4 models, while GPT-4.1-mini generated plausible patches for 5 models and valid patches for 4 models. These results indicate that changing the LLM model affects the number of generated patches and the specific faults repaired, but the overall repairing ability remains limited under the evaluated conditions.
The results also show that successful repair cases vary across model choices. For instance, GPT-5.5 repaired both Pacemaker models, which were not repaired by GPT-5.4-mini or GPT-4.1-mini. Conversely, GPT-5.4-mini repaired fridge_1 with a mean of 35.2 plausible and valid patches, whereas GPT-5.5 did not repair this model and GPT-4.1-mini produced only a small number of patches. This variation suggests that some repair outcomes are model-dependent. However, the broader trend remains consistent: across the evaluated LLM variants, successful repairs are concentrated in a small subset of faults.
In contrast, the approach performs poorly for faults that require precise value synthesis, missing expression insertion, or structural reasoning. For example, door_2 requires changing a specific assigned value from 1 to -1, while elevator_1 and elevator_2 require inserting missing expressions. None of the evaluated LLM variants produced valid patches for these models. Similarly, the approach struggles with structural faults such as door_1, where the correct repair requires modifying the source of a transition. GPT-4.1-mini generated plausible patches for this model, but none were valid, suggesting that the generated changes passed the available tests without capturing the intended structural correction. A similar pattern appears in elevator_4 and elevator_5, where GPT-5.4-mini generated plausible patches but no valid patches, indicating overfitting or semantically incorrect repairs.
Overall, these results indicate that the effectiveness of LLM-based mutation depends strongly on the nature of the fault and the selected LLM variant. The approach can generate correct repairs for some localized semantic changes, but it remains unreliable for faults requiring exact value synthesis, missing expressions, or structural modifications. The additional experiments with GPT-5.4-mini and GPT-4.1-mini strengthen this observation by showing that, although the exact successful cases differ across models, the limited repair coverage remains consistent across the evaluated LLM choices.
RQ1: Using LLMs as repair mutators produced plausible patches for 4 out of 19 models with GPT-5.5, 6 out of 19 with GPT-5.4-mini, and 5 out of 19 with GPT-4.1-mini. Valid patches were produced for 4 out of 19 models for each evaluated LLM variant. These results indicate limited repairing ability under the evaluated conditions, with successful repairs mainly concentrated in localized semantic faults.
Discussion
The results of our empirical evaluation show that replacing several hand-crafted mutation operators in FlowRepair with LLM-generated mutations did not improve repair performance for the evaluated Stateflow models. Across the 19 faulty models, FlowRepair achieved broader repair coverage, while the LLM-based variants repaired only a small subset, with successful cases concentrated in a few localized semantic faults.
A first key insight concerns the shape of the search space. FlowRepair relies on deliberately constrained mutation operators that produce small, syntactically valid, and semantically local modifications, keeping the search space focused. In contrast, LLM-based mutation introduces more flexible but less constrained edits. Although this may increase the variety of possible repairs, it may reduce the proportion of useful candidates for simulation-based validation. Each run generated many candidates, yet only a small fraction led to plausible or valid repairs. In CPS repair, where each candidate must be validated through simulation, such less constrained exploration may quickly consume the available repair budget.
Third, several failures arise from plausible but semantically invalid patches. This was observed in door_1 for GPT-4.1-mini, and in elevator_4 and elevator_5 for GPT-5.4-mini, where plausible patches were generated but none were valid. These cases show that passing the available simulation tests does not always imply semantic correctness. In door_1, the fault involves an incorrect transition source, which is a structural property of the Stateflow model. In elevator_4 and elevator_5, the fault involves an added exit action. These faults require changes that are tied to Stateflow execution semantics and model structure, rather than only local textual rewriting.
Structural characteristics of Stateflow models further compound these difficulties, as repairs may require graph-level changes, such as modifying transition sources or targets or adding/removing state actions while preserving execution order. The current LLM-based integration operates mainly on textual representations of states and transitions, providing limited access to topology and execution semantics. Although a subset of FlowRepair’s structural operators was retained, the hybrid configuration did not match FlowRepair’s reliability on structure-dependent faults, highlighting the importance of explicitly representing Stateflow structure in generative CPS repair.
The absence of behavioural feedback is another important design factor. FlowRepair’s search is guided by repair objectives such as failure duration, severity, and activation time, which provide feedback after simulation. In the evaluated LLM-based variants, the LLM generates mutations from static information such as labels, actions, and variable lists, without receiving iterative feedback about why a patch failed or whether it partially improved the system behaviour. As a result, the generation process cannot directly refine its suggestions based on dynamic CPS behaviour. This could contribute to repeated generation of irrelevant, near-miss, or overfitting patches.


