Skip to content

MemRepair: Hierarchical Memory for Agentic Repository-Level Vulnerability Repair

🕒 Published (v1): 2026-05-17 13:29 UTC · Source: Arxiv · link

Why this paper was selected

MemRepair: hierarchical memory enabling repository-scale vulnerability repair agents

Ask a follow-up

Open an assistant pre-loaded with this paper's context.

💬 Ask ChatGPT✦ Ask Claude

TL;DR

MemRepair is a memory-augmented agentic framework for automated vulnerability repair (AVR) that structures LLM-driven patch generation around a three-tier hierarchical memory (History-Fix, Security-Pattern, Refinement-Trajectory) rather than single-pass context-window generation. A Locator–Patcher–Verifier loop with closed runtime feedback drives iterative patch refinement. On SEC-Bench, PatchEval, and Multi-SWE-bench (C++), it reaches 58.0%, 58.2%, and 30.58% resolution rates, outperforming prior specialist and general-purpose agents by wide margins.

Problem

Existing LLM-based AVR agents treat repair as a single generation step over the currently visible context: they lack (1) persistent project-specific repair experience, (2) generalizable cross-project security patterns, and (3) "failure-to-success" debugging trajectories. Without these, agents oscillate between semantically invalid patches rather than converging—a failure mode termed Cognitive Deficiency—and apply local syntax corrections that miss cross-file data-flow dependencies.

Method

MemRepair orchestrates a Locator–Patcher–Verifier multi-agent loop backed by three persistent memory stores:

  • L1 History-Fix Memory (\(M_{L1}\)): 14,063 verified CVEFixes entries indexed by project, CWE type, language, and CVE ID. Retrieved via a two-tier priority: P1 = same-project + same-CWE + same-language (intra-project, temporally gated by \(\text{Timestamp}(e) < \text{Timestamp}(q)\)); P2 = cross-project + same-CWE + same-language when P1 yields fewer than \(k{=}2\) candidates. Similarity ranked by cosine distance over text-embedding-3-small embeddings.
  • L2 Security-Pattern Memory (\(M_{L2}\)): Extends L1 entries with \(R_{\text{rationale}}\)—a natural-language description of why the patch worked. Populated in real time from successful repairs.
  • L3 Refinement-Trajectory Memory (\(M_{L3}\)): Captures within-session "failure→success" transitions as tuples \(\langle P_{\text{fail}}, \Delta_{\text{diff}}, I_{\text{insight}} \rangle\). Retrieved and injected only after a verification failure, providing explicit corrective deltas.

The Locator uses Iter_grep, an AST-aware tool that parses the repository to find symbol definitions and use sites, then ranks the top-5 by proximity (logical call-stack distance) to the runtime crash point in sanitizer/stack-trace evidence \(R_{\text{dyn}}\), producing a structured localization object \(L_{\text{loc}} = \langle f, \ell \rangle\).

The Verifier executes oracle \(\langle \mathcal{T}, \tau_{\text{vuln}} \rangle\) (regression tests + PoC) and triggers: Success (terminate, update L2/L3), Relocate (rerun Phase 1 with new runtime evidence), or Regenerate (rerun Phase 2 at same \(L_{\text{loc}}\)). After each failed attempt, log_compress compresses raw tool logs into a fixed template (visited files/lines, applied diffs, verification failure logs) for context management. The loop caps at 3 failed attempts.

Key Contributions

  • First repository-level AVR framework with a three-tier hierarchical memory (History-Fix, Security-Pattern, Refinement-Trajectory) enabling experience-grounded patch generation.
  • Iter_grep: an AST-based structure-aware localization tool that ranks candidate repair sites by runtime stack-trace proximity, replacing unranked keyword grep.
  • A closed Locator–Patcher–Verifier feedback loop with tri-state transitions (Success / Relocate / Regenerate) and log compression for context efficiency.
  • Demonstrated state-of-the-art performance across four languages (C, C++, Python, Go, JavaScript) on three benchmarks at competitive cost (\(0.26–\)0.32/task for DeepSeek-v3.2 backbone).

Results

  • SEC-Bench (C/C++ memory safety): MemRepair 58.0% vs. OpenHands* (DeepSeek-v3.2) 38.5%, OpenHands (Claude-3.7) 34.0%, SWE-agent (Claude-3.7) 31.5%, Aider 23.5%. Cost: $0.26/task.
  • Multi-SWE-bench C++ subset: MemRepair (DeepSeek-v3.2) 30.58% vs. InfCode-C++ (GPT-5) 25.60%, InfCode-C++ (DeepSeek-v3) 13.20%, OpenHands 14.70%, SWE-agent 11.60%, Agentless 3.90%.
  • PatchEval (Python, Go, JavaScript): MemRepair 58.2% (exact per-language breakdown not reported in the provided text).
  • Location accuracy on SEC-Bench: MemRepair 60.0% vs. OpenHands* 63.0%, OpenHands 65.0%, SWE-agent 67.5%, Aider 46.0%—MemRepair trades localization accuracy for higher end-to-end repair rate via the Relocate mechanism.
  • MemRepair achieves higher resolution than the specialised C++ static-analysis agent InfCode-C++ (GPT-5) despite using a cheaper backbone, at lower per-task cost.

Limitations

  • File-level location accuracy (60%) lags behind some baselines (SWE-agent 67.5%), indicating that Iter_grep + runtime evidence does not always pinpoint the correct file.
  • L2 and L3 memory scales are small by construction (116 and 86 entries on SEC-Bench); scalability to long-running, large-scale deployments relies on heuristic deduplication (cosine ≥ 0.95 merge) and recency-weighted pruning, not experimentally validated at scale.
  • Refinement loop is capped at 3 iterations by empirical pilot study; optimal cap may vary across vulnerability types or repositories.
  • Comparison with VulDebugger and other dynamic agents excluded due to closed-source datasets/reproducibility constraints, limiting the breadth of the baseline comparison.
  • Temporal leakage risk is mitigated only for intra-project retrieval; cross-project P2 retrieval has no timestamp filter, potentially admitting future-dated fixes.

Relevance to Harnesses / Meta-Harnesses

MemRepair is a concrete example of a feedback-driven multi-agent harness where persistent, structured memory replaces ad-hoc in-context accumulation—directly relevant to meta-harness design patterns where orchestrators must manage long-running, multi-step agent loops without exceeding context limits. The three-tier memory hierarchy models how a harness can decouple what to remember (project conventions, generalizable patterns, debugging trajectories) from when to inject it (pre-patch vs. post-failure), a design principle applicable to any iterative agentic pipeline. The log_compress mechanism is a practical solution to context-window management within a harness loop, complementing techniques like RAG and summarization used in broader meta-harness literature. The tri-state Verifier (Success / Relocate / Regenerate) formalizes branching control flow that meta-harnesses need when subagent outputs must be validated and rerouted dynamically.