Benchmarking Correctness and Security in Multi-Turn Code Generation

Ruchit Rawal, Jeffrey Yang Fan Chiang, Chihao Shen, Jeffery Siyuan Tian, Aastha Mahajan, Tom Goldstein, Yizheng Chen · DOI

AI coding assistants have revolutionized software development, yet most evaluations remain limited to "single-turn" tasks. In practice, development is an iterative conversation involving feature requests, refinements, and refactoring. A new study from the University of Maryland introduces MT-Sec, the first benchmark designed to evaluate whether Large Language Models (LLMs) maintain functional correctness and security across complex, multi-turn interactions.

The Multi-Turn Challenge: Semantic Entanglement

While existing benchmarks like SECCODEPLT or BAXBENCH assess one-shot generation, they fail to capture "semantic entanglement"—the challenge of tracking evolving requirements while adhering to security constraints over time. MT-Sec reveals a significant performance cliff: LLMs experience a 20-27% drop in "Correct & Secure" (C&S) performance when transitioning from single-turn to multi-turn tasks.

Methodology and Interaction Types

The researchers developed a synthetic pipeline to transform single-turn security tasks into three-turn dialogues. These interactions are categorized into three distinct types:

  1. Expansion: Incrementally adding features to basic logic.
  2. Editing: Simulating iterative revisions and changes in requirements.
  3. Refactoring: Restructuring code for clarity without altering behavior.
Visualizing Multi-Turn Interaction Types: Expansion, Editing, and Refactoring compared to Single-Turn baselines.

To maintain rigor, a "Consistency Guardrail" ensures that final requirements align with original unit tests, followed by human verification to ensure natural developer workflows.

Dataset Composition

MT-Sec comprises 2,376 multi-turn tasks derived from SECCODEPLT and BAXBENCH. It covers 6 programming languages (Python, JS, Go, PHP, Ruby, Rust) and 27 Common Weakness Enumerations (CWEs), providing a comprehensive view of potential security vulnerabilities in iterative coding.

Key Insights: Temporal Reasoning and "Paranoia"

The study suggests that the performance drop is not due to context length but a failure in temporal reasoning—the ability to track how incremental changes impact security. Interestingly, "MT-Random" tests (long contexts of unrelated code) did not show the same degradation.

Furthermore, reasoning models (e.g., OpenAI o1/o3, DeepSeek-R1) often exhibited "over-refusal," where accumulated context triggered safety filters that blocked benign tasks. The study also found that repeating security policies in every turn could backfire, leading to logic errors as models over-corrected.

Comparative Performance

Across 32 evaluated models, the degradation was universal. While top-tier models like Claude Opus 4T and GPT-5T led in absolute scores, they still suffered from the multi-turn performance gap.

Performance degradation across various LLMs showing the breakdown of Correct & Secure (C&S) vs. Correct & Insecure (C&I) outputs.

Specific vulnerabilities, such as CWE-95 (Improper Neutralization of Directives) and CWE-77 (Command Injection), saw notable spikes during iterative editing phases. Additionally, generating code "diffs" proved less secure than rewriting full programs.

Conclusion and Future Directions

MT-Sec highlights a critical vulnerability in current AI coding assistants. As workflows become increasingly agentic, security evaluations must evolve to match the conversational nature of these tools. Future research will focus on intermediate evaluation (testing security at every turn), dynamic test generation, and extending conversations beyond three turns to identify performance floors.

Summary updated

BibTeX
@inproceedings{rawal2025benchmarking,
  author = {Ruchit Rawal and Jeffrey Yang Fan Chiang and Chihao Shen and Jeffery Siyuan Tian and Aastha Mahajan and Tom Goldstein and Yizheng Chen},
  title = {{Benchmarking Correctness and Security in Multi-Turn Code Generation}},
  booktitle = {MTI-LLM @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=GIvfdmlvMA},
}
Figure