SeCuRepair: Semantic Repair Framework
- SeCuRepair is a framework for repairing code vulnerabilities using a reason-then-edit paradigm that enforces a deeper understanding of repair logic.
- It integrates semantic, syntactic, and lexical rewards through reinforcement learning to ensure patches meet both structural and functional criteria.
- The curriculum-driven process enables the model to master simple fixes before tackling complex multi-hunk repairs for improved generalization.
Searching arXiv for SeCuRepair and closely related vulnerability-repair work. SeCuRepair is a semantics-aligned, curriculum-driven, and reasoning-enhanced framework for vulnerability repair that was introduced to address three diagnosed weaknesses of learning-based Automated Vulnerability Repair (AVR): limited cross-repository generalization, poor handling of long-range dependencies in complex multi-hunk repairs, and over-reliance on superficial lexical patterns (Yang et al., 1 Oct 2025). Its core design adopts a reason-then-edit paradigm in which the model must first state why and how a vulnerability should be fixed and only then generate the patch. The framework is evaluated on strict, repository-level splits of BigVul and PrimeVul\textsubscript{AVR}, where it is reported to surpass the best-performing baselines by 34.52\% on BigVul and 31.52\% on PrimeVul\textsubscript{AVR} in terms of CodeBLEU (Yang et al., 1 Oct 2025).
1. Definition and problem setting
SeCuRepair is situated within learning-based AVR for C/C++ code. The motivating diagnosis identifies three fundamental weaknesses in state-of-the-art AVR approaches. First, under a repository-level split with no overlapping GitHub projects between train and test, existing models’ CodeBLEU drops by up to 29.7\% and Exact-Match by up to 91.6\%. Second, in BigVul and PrimeVul\textsubscript{AVR}, roughly 40–47\% of fixes require edits in two or more non-contiguous hunks, and strong baselines degrade in CodeBLEU as the number of hunks increases, including a reported for VulMaster. Third, minor syntactic variations such as renaming a local variable can cause 40–70\% of patches to become incorrect (Yang et al., 1 Oct 2025).
The framework is therefore defined not merely as a patch generator, but as a repair system intended to enforce a more explicit representation of repair logic. The paper states that SeCuRepair “adopts a reason-then-edit paradigm, requiring the model to articulate why and how a vulnerability should be fixed before generating the patch” (Yang et al., 1 Oct 2025). This suggests that the framework treats vulnerability repair as a structured generation problem rather than a pure next-token imitation problem.
A useful boundary condition is provided by the adjacent system \texttt{SecRepair}, which is also LLM-based and also uses reinforcement learning with a semantic reward, but is organized as an end-to-end system for identifying, localizing, and repairing vulnerabilities while generating descriptions and code comments (Islam et al., 2024). SeCuRepair is more narrowly framed around vulnerability repair quality under repository-level generalization, semantic robustness, and multi-hunk coordination (Yang et al., 1 Oct 2025).
2. Reason-then-edit formulation
At the center of SeCuRepair is a two-step output schema:
7
The framework’s first stage is Reasoning-Transferred SFT. In this stage, high-quality pairs are distilled from a teacher LLM, specifically GPT-5 mini, via rejection sampling, and the student model is fine-tuned to reproduce that format (Yang et al., 1 Oct 2025). The supervised objective is given as
where is the total token length of the reasoning+patch response and is the model’s token-generation policy (Yang et al., 1 Oct 2025).
The rationale given in the paper is that “explicit reasoning enforces a genuine understanding of repair logic rather than superficial memorization of lexical patterns” (Yang et al., 1 Oct 2025). A plausible implication is that the reasoning block functions as an inductive scaffold: it requires the model to expose the causal relation between the vulnerability mechanism and the intended fix before decoding patch tokens.
This design differs from systems trained only by maximizing token-level likelihood against a single reference patch. The contrast is explicit in the paper’s motivation and is also directionally consistent with \texttt{SecRepair}, which similarly attempts to provide explanation alongside repaired code, although through vulnerability descriptions and code comments rather than a strict reason-then-edit schema (Islam et al., 2024).
3. Semantics-aware reinforcement learning
SeCuRepair’s second stage replaces sole reliance on single-reference token matching with on-policy reinforcement learning using Group Relative Policy Optimization (GRPO) (Yang et al., 1 Oct 2025). The reward jointly measures lexical, syntactic, and semantic alignment with the oracle patch.
The lexical component is BLEU:
where is -gram precision and is the brevity penalty (Yang et al., 1 Oct 2025).
The syntactic component is AST subtree matching:
with 0 the set of AST subtrees (Yang et al., 1 Oct 2025).
The semantic component is DFG edge matching:
1
where 2 is the set of data-flow edges (Yang et al., 1 Oct 2025).
These three scores form 3, and the reward is
4
GRPO then samples 5 rollouts per prompt, computes normalized advantages
6
and optimizes the clipped surrogate
7
where
8
The stated purpose is to reward patches for “their syntactic and semantic alignment with the oracle patch rather than mere token overlap” (Yang et al., 1 Oct 2025). This suggests a shift from surface-form imitation toward structure- and flow-preserving repair behavior. In related work, \texttt{SecRepair} also employs reinforcement learning with a semantic reward, but there the reward is BERTScore for code-comment generation rather than a combined BLEU–AST–DFG reward for patch generation (Islam et al., 2024).
4. Difficulty-aware curriculum and training pipeline
SeCuRepair stages training by repair difficulty using the number of vulnerable hunks 9 (Yang et al., 1 Oct 2025). The curriculum is controlled by a piecewise-constant pacing function 0, with cumulative expansion of the training set across three stages:
- Stage 1 (easy): 1
- Stage 2 (medium): 2
- Stage 3 (hard): all 3
The paper states that this schedule “prevents forgetting and allow[s] the model to master simple localized fixes before tackling complex, coordinated edits” (Yang et al., 1 Oct 2025). A plausible implication is that the curriculum is intended to stabilize policy improvement under GRPO when the action space includes long structured patches with interdependent edits.
The model and training pipeline are specified in detail. The base model is Qwen2.5-7B-Instruct, described as “a standard transformer encoder–decoder,” with a single decoder that first emits the reasoning trace and then the patched code under the tag schema (Yang et al., 1 Oct 2025). Stage 1 distills 4 reasoning+patch candidates from GPT-5 mini, applies two-step rejection sampling consisting of a format check and CodeBLEU 5, yields 484 high-quality examples, and fine-tunes full parameters for 3 epochs at 6 (Yang et al., 1 Oct 2025). Stage 2 initializes from the SFT checkpoint and runs GRPO with 7 rollouts, actor LR 8, batch size 1024, and up to 20 epochs, while integrating the curriculum schedule across epochs (Yang et al., 1 Oct 2025).
5. Experimental evaluation
The evaluation uses two datasets. BigVul contains 9 333 C/C++ functions with an 8:1:1 repo-split, and PrimeVul\textsubscript{AVR} contains 1 554 out-of-distribution C/C++ function pairs filtered to exclude any overlap with BigVul training repos (Yang et al., 1 Oct 2025). Baselines are FAVOR (CodeT5+SFT), VulMaster (CodeT5+SFT), GPT-4o (zero-shot), and Qwen2.5+SFT, and the automatic metric is CodeBLEU, with “no EM” (Yang et al., 1 Oct 2025).
The key reported CodeBLEU results are summarized below.
| Dataset | Result |
|---|---|
| BigVul | SeCuRepair 35.42 % vs VulMaster 26.33 % (+34.52 %) |
| PrimeVul\textsubscript{AVR} | SeCuRepair 30.79 % vs GPT-4o 23.41 % (+31.52 %) |
| Qwen2.5+SFT | 29.62 % / 25.92 % (BigVul / PrimeVul) |
The paper also reports a human evaluation on PrimeVul\textsubscript{AVR} with 9, where the proportion of “workable” patches, defined as Likert 0, is 58\% for SeCuRepair, 50\% for GPT-4o, and 20\% for VulMaster (Yang et al., 1 Oct 2025).
These numbers are paired with the earlier diagnosis of repository-level degradation, multi-hunk sensitivity, and lexical brittleness. This suggests that the evaluation is intended not only as a benchmark comparison but also as a validation of the framework’s three design commitments: reasoning, semantic reward, and curriculum (Yang et al., 1 Oct 2025).
6. Ablations and representative repair behavior
The ablation studies quantify the contribution of each major component on BigVul CodeBLEU relative to the SFT baseline. The paper reports the following gains: 1RL with BLEU-only reward, 2; 3semantic reward using AST + DFG, 4; and 5curriculum schedule, 6 (Yang et al., 1 Oct 2025). The ablation pattern is consistent with the claim that the final performance depends on the combined effect of semantic alignment and staged exposure to harder repairs.
A representative case study is CVE-2021-29513 in CPython, described as a NULL-pointer dereference in PyDict_Next (Yang et al., 1 Oct 2025). The patch must check descr->fields for NULL at two distinct locations and early-return or error if the check fails. The reported SeCuRepair output is:
8c if (!descr->fields) { PyErr_SetString(PyExc_SystemError, "uninitialized descriptor"); return NULL; } … // Repeat guard at second call site 9
The paper notes that the oracle uses descr->fields == nullptr and a different error message, but characterizes the generated patch as “semantically equivalent and syntactically valid” (Yang et al., 1 Oct 2025). This is important because the case study is used to illustrate the framework’s intended departure from surface-form imitation. A plausible implication is that SeCuRepair treats correctness signals as partially invariant to benign syntactic divergence when AST and DFG agreement remain high.
7. Position within the literature and scope of interpretation
Within the provided literature, SeCuRepair belongs to a broader trend of combining code repair with security-aware generation objectives. The closest adjacent system is \texttt{SecRepair}, which is powered by CodeGen2, uses supervised instruction tuning followed by PPO with a semantic reward, and unifies vulnerability identification, repair generation, vulnerability description, and code comment generation on the InstructVul dataset (Islam et al., 2024). The shared elements are reinforcement learning and semantic reward; the difference is that SeCuRepair is explicitly semantics-aligned, curriculum-driven, and reasoning-enhanced for vulnerability repair under strict repository-level evaluation (Yang et al., 1 Oct 2025).
A common misconception would be to treat SeCuRepair as merely another supervised patch generator with a different prompt template. The reported design and ablation evidence do not support that reading. The framework couples a mandated reasoning trace, a reward defined over BLEU, AST, and DFG agreement, and a difficulty-aware curriculum (Yang et al., 1 Oct 2025). This suggests that its novelty lies in the interaction among representation format, reward design, and training schedule rather than in a single component.
Another possible source of confusion is terminological. The broader corpus contains several unrelated uses of “repair” in secure storage, secret sharing, and blockchain settings, including “Generic Secure Repair for Distributed Storage” (Huang et al., 2017) and “Reparo: Publicly Verifiable Layer to Repair Blockchains” (Thyagarajan et al., 2020). Those works address repair in distributed systems or blockchain state, not automated vulnerability repair for source code. In the present sense, SeCuRepair denotes the 2025 vulnerability-repair framework centered on reason-then-edit generation, semantics-aware reinforcement learning, and curriculum learning (Yang et al., 1 Oct 2025).