arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2601.06497cs.SEcs.AI
收藏

在气泡中编码?评估LLMs在代码适应过程中解决上下文适应故障的能力

Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs During Code Adaptation

National University of Defense Technology(国防科技大学);Peng Cheng Laboratory(鹏城实验室)

Tanghaoran Zhang, Xinjun Mao, Shangwen Wang, Yuxin Zhao, Yao Lu, Zezhou Tang, Wenyu Xu, Longfei Sun, Changrong Xie, Kang Yang, Yue Yu

AI总结:

研究提出CtxBugGen框架,评估LLMs在解决代码适应中的上下文适应故障方面的性能,发现LLMs在处理此类问题时存在显著不足。

摘要:

代码适应是软件开发中一个基础但具有挑战性的任务,要求开发人员为新的上下文修改现有代码。一个关键挑战是解决上下文适应故障(CtxBugs),即当代码在原始上下文中正确但违反目标环境中的约束时发生。与孤立故障不同,CtxBugs不能通过局部修复来解决,而需要跨上下文推理来识别语义不匹配。忽视它们可能导致适应中的关键失败。尽管大型语言模型(LLMs)在自动化代码相关任务中显示出巨大的潜力,但它们在解决CtxBugs方面的能力仍然是一个重大且未探索的障碍,阻碍了它们在代码适应中的实际应用。为弥合这一差距,我们提出了CtxBugGen,一种新的框架,用于生成CtxBugs以评估LLMs。其核心思想是利用LLMs在缺乏上下文约束时倾向于生成合理但上下文无关的代码的倾向。该框架通过四步过程生成CtxBugs以确保其相关性和有效性:(1)适应任务选择,(2)任务特定的扰动,(3)基于LLM的变体生成和(4)CtxBugs识别。基于由CtxBugGen构建的基准,我们对四个最先进的LLMs进行了实证研究。我们的结果揭示了它们在CtxBug解决方面的令人不满的表现。表现最好的LLM,Kimi-K2,在Pass@1上达到55.93%,仅解决了52.47%的CtxBugs。CtxBugs的存在使LLMs的适应性能下降高达30%。失败分析表明,LLMs往往忽视CtxBugs并将其复制到其输出中。我们的研究突显了LLMs跨上下文推理中的关键弱点,并强调了需要新方法来增强它们的上下文意识,以实现可靠的代码适应。

英文摘要:

Code adaptation is a fundamental but challenging task in software development, requiring developers to modify existing code for new contexts. A key challenge is to resolve Context Adaptation Bugs (CtxBugs), which occurs when code correct in its original context violates constraints in the target environment. Unlike isolated bugs, CtxBugs cannot be resolved through local fixes and require cross-context reasoning to identify semantic mismatches. Overlooking them may lead to critical failures in adaptation. Although Large Language Models (LLMs) show great potential in automating code-related tasks, their ability to resolve CtxBugs remains a significant and unexplored obstacle to their practical use in code adaptation. To bridge this gap, we propose CtxBugGen, a novel framework for generating CtxBugs to evaluate LLMs. Its core idea is to leverage LLMs' tendency to generate plausible but context-free code when contextual constraints are absent. The framework generates CtxBugs through a four-step process to ensure their relevance and validity: (1) Adaptation Task Selection, (2) Task-specific Perturbation,(3) LLM-based Variant Generation and (4) CtxBugs Identification. Based on the benchmark constructed by CtxBugGen, we conduct an empirical study with four state-of-the-art LLMs. Our results reveal their unsatisfactory performance in CtxBug resolution. The best performing LLM, Kimi-K2, achieves 55.93% on Pass@1 and resolves just 52.47% of CtxBugs. The presence of CtxBugs degrades LLMs' adaptation performance by up to 30%. Failure analysis indicates that LLMs often overlook CtxBugs and replicate them in their outputs. Our study highlights a critical weakness in LLMs' cross-context reasoning and emphasize the need for new methods to enhance their context awareness for reliable code adaptation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑