← Lab /AI/ML

Function-focused context boosts functional success but improves security only modestly

Repository context construction has a limited positive impact on the security of LLM-generated code

AI/ML arXiv 4 Nov 2026 Measurement Prototype evidence

Published as “A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated Code”

Why it matters

Security-aware context construction can modestly improve the safety of LLM-generated code, but naïve functionality-oriented retrieval often leaves code vulnerable, suggesting that developers need explicit safeguard exposure rather than generic context.

Summary

The study finds that providing repository context that is oriented toward functionality improves functional correctness by up to 8.2 percentage points but improves security (secure pass rate) by at most 3.7 percentage points, and withholding a safeguard can drop the secure pass rate by up to 8.1 pp while inserting an insecure exemplar raises exploitable code by 6.3 pp; the evidence comes from a controlled experiment on 145 real-world CVE tasks with six LLMs and 13 context methods, showing modest and often non-significant security gains.

What they found 2

  1. Functionality-oriented context improves correctness more than security.

    “Finding 1 (RQ1): Functionality-oriented context improves correctness more than security.”

  2. Removing a safeguard from the context reduces secure outcomes by up to 8.1 pp.

    “Removing one safeguard role from the Reference context lowers SecPass@1 by 8.1 pp for the safe API, 6.7 pp for validators, 5.2 pp for the policy, and 3.9 pp for the caller contract (Figure 6a).”

Caveats 2

  • Four methods even have lower observed SecPass@1 than Local-only, and 40.3-50.2% of all generations are correct but exploitable.
  • Relative to Local-only, the eleven functionality-oriented methods change FuncPass@1 by -4.8 to +8.2 pp but SecPass@1 by only -1.1 to +3.7 pp, with no method differing significantly from Local-only after correction.

What’s new here 4

  • Introduces CASE-Bench, an executable benchmark of 145 repository-level tasks derived from real CVEs with both functional tests and PoC exploits validated in both vulnerable and patched versions.
  • Systematically varies repository context across 13 construction methods and six control conditions while keeping the task prompt fixed.
  • Analyzes coding-agent trajectories to measure how often agents actually observe security-relevant context.
  • Provides fine-grained edits (adding/removing safeguards or insecure exemplars) to isolate the causal impact of specific context elements on security outcomes.