cs.SEOct 9, 2026

Diagnosing Generalization Boundaries in AI-Based Vulnerability Detection via Calibrated Embedding Distances

Authors: Konstantin Ievtushenko, Ralf Lämmel, Jan Jürjens

Organizations: University of Koblenz, Germany · Fraunhofer ISST, Germany

Abstract

High benchmark scores in learning-based vulnerability detection mask severe degradation under distribution shifts. This paper demonstrates that calibrated embedding geometry exposes these hidden generalization boundaries on syntactically similar vulnerable and patched code pairs. An evaluation of CodeBERT and Qwen2.5-Coder across pattern, project, and temporal shifts on a strictly paired dataset reveals three main findings. First, whitened intermediate-layer embeddings with local nearest-neighbour scoring separate unfamiliar samples with a mean out-of-distribution AUROC of 0.739 (RQ1). Second, distance scores reveal a shift-specific reliability gradient where accuracy drops by over 35 percentage points and cross-project shifts cause the sharpest degradation, even though temporal shifts drift geometrically farthest (RQ2). Third, false positives on patched code systematically correlate with geometric proximity to vulnerable training neighbourhoods, increasing from 9.4% in the lowest-risk decile to 58.8% in the highest (RQ3). These calibrated distances establish a diagnostic signal that maps representation geometry directly to model degradation without requiring auxiliary models.

Figures & tables

Explore similar work

CardsList
  1. When Models Know but Can't Linearly Say: Relational Encoding Limits Linear Vulnerability Classification in Code LLMs

    Oct 19, 2026Rui Melo, Andre Catarino, Claudia Mamede +2LLMs for CybersecuritySoftware Vulnerability Detection

  2. VICBench: A Multi-Language Benchmark for Code Vulnerability Detection

    Aug 12, 2026Jin Lu, Xuening Han, Yang Zhong +4Software Vulnerability DetectionSoftware Engineering Benchmarks