Knowledge-Enhanced Agentic Vulnerability Repair

Sicong Cao, Hao Ma, Le Yu, Kangyi Ding, Xiaolei Liu, Terry Yue Zhuo, Bo Wang, Xingwei Lin, Xiaobing Sun, Linzhang Wang, David LoarXiv 2026

TL;DR

KEAREPAIR is a novel automated vulnerability repair (AVR) framework that combines tool-augmented agentic reasoning with dual-view historical knowledge retrieval to fix software bugs. By grounding large language models (LLMs) in verified program facts and structured fix strategies, it achieves an impressive 83.64% repair rate on real-world C/C++ vulnerabilities, significantly outperforming existing baselines while maintaining exceptional cost efficiency.

What Problem Does This Paper Address?

As frontier AI models accelerate the discovery of software vulnerabilities, human developers are facing an overwhelming backlog of security flaws to remediate. Automated Vulnerability Repair (AVR) aims to solve this by automatically generating code patches. However, current LLM-based patching tools suffer from two fundamental flaws:

  1. Unreliable Root Cause Analysis: They often rely on imperfect fault localization tools or unconstrained LLM reasoning, leading to hallucinations or patches applied to the wrong locations.
  2. Suboptimal Knowledge Utilization: Existing Retrieval-Augmented Generation (RAG) methods match historical vulnerability-patch pairs based purely on surface-level code similarity, ignoring the deeper, logical causal similarities required to generate a correct fix.

Methods

KEAREPAIR introduces a three-phase agentic workflow designed to anchor patch generation in concrete program facts and high-level vulnerability abstractions:

  1. Vulnerability Knowledge Base Construction: The framework distills historical vulnerability-patch pairs into structured knowledge items (root causes, vulnerable behaviors, and fixing strategies). Crucially, this knowledge is split into two complementary views: data-flow and control-flow.
  2. Fact-Grounded Agentic Vulnerability Diagnosis: Instead of letting the LLM guess the root cause, a ReAct-style diagnostic agent uses specialized static analysis tools (trace_data_flow, is_path_reachable, and inspect_api_usage) to extract verified semantic facts from the codebase.
  3. Knowledge-Level Retrieval-Augmented Patch Generation: Using the verified diagnostic report, KEAREPAIR generates view-specific semantic queries to retrieve the most relevant historical exemplars. A hybrid re-ranker balances code similarity (via CodeLlama) and behavioral similarity (via BM25). Finally, a repair agent synthesizes the patch and refines it through a closed-loop validation process involving compilation, Proof-of-Concept (PoC) replay, and test-suite execution.
Fig. 2: Overview of KEAREPAIR.

Datasets

The authors evaluated KEAREPAIR across multiple benchmarks:

  • VUL4C: A benchmark containing 68 real-world C/C++ vulnerabilities. The authors utilized a filtered evaluation set of 55 reproducible CVEs spanning 10 software products and 6 vulnerability types (e.g., buffer overflows, use-after-free).
  • PATCHEVAL: A multilingual benchmark used to test cross-language generalizability, from which a subset of 173 CVEs across Go, JavaScript, and Python was selected.
  • PRIMEVUL: A high-quality dataset consisting of 5,480 vulnerability-patch pairs across 130 CWE categories, used to construct the offline retrieval knowledge base.

Key Insights and Ideas

  • Facts Over Fiction: Free-form LLM reasoning about complex code structures inherently invites hallucination. Equipping the agent with deterministic static analysis tools ensures that the model's diagnostic reasoning is grounded in verified code execution paths.
  • Dual-View Semantics: Matching historical patches based on surface-level text similarity introduces contextual noise. Decomposing vulnerability logic into separate control-flow and data-flow views allows the model to capture abstract, reusable repair patterns.
  • The Power of the Loop: Ablation studies revealed that the feedback-driven iteration mechanism (compiling and testing candidate patches) was the single most critical component, yielding a 76.92% improvement in the repair rate compared to single-turn patch generation.

Key Results

KEAREPAIR was tested using several frontier LLM backbones (including GPT-5.1, Claude-Sonnet-4-6, and Gemini-3.1-Pro) and compared against eight state-of-the-art AVR baselines.

  • High Success Rate: When paired with Gemini-3.1-Pro or GPT-5.1, KEAREPAIR successfully repaired 46 out of 55 vulnerabilities (83.64%), outperforming the best-performing baseline, PatchAgent (39/55).
  • Unique Fixes: KEAREPAIR successfully resolved nine unique vulnerabilities that PatchAgent missed, and six unique vulnerabilities that none of the baseline approaches could address.
  • Cost-Benefit Efficiency: Gemini-3.1-Pro emerged as the optimal backbone, achieving the top repair rate with an average time overhead of under 50 seconds and a remarkably low cost of $0.30 per vulnerability.
TABLE II: Cost analysis of KEAREPAIR under different LLMs.
  • Cross-Language Generalization: On the PATCHEVAL dataset, KEAREPAIR paired with Qwen3.5-Plus achieved a 85.55% success rate (148/173), demonstrating that its core design principles translate effectively to Python, JavaScript, and Go.

Limitations and Future Work

Despite its strong performance, the authors note two primary limitations:

  • Static Analysis Dependencies: Real-world projects with deeply nested macros, conditional compilation, or complex compiler extensions can cause static analysis tools to return imprecise results, forcing the agent to fall back on unconstrained reasoning.
  • Single-Location Fix Constraints: Because the underlying knowledge base operates at the function level, KEAREPAIR struggles with complex, inter-procedural vulnerabilities that require coordinated edits across multiple files.

Future work will focus on scaling the framework to capture global architectural contexts and building contamination-resistant evaluation benchmarks.

Summary updated

BibTeX
@misc{cao2026knowledge,
  author = {Sicong Cao and Hao Ma and Le Yu and Kangyi Ding and Xiaolei Liu and Terry Yue Zhuo and Bo Wang and Xingwei Lin and Xiaobing Sun and Linzhang Wang and David Lo},
  title = {{Knowledge-Enhanced Agentic Vulnerability Repair}},
  year = {2026},
  eprint = {2607.00820},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.00820},
}
Figure