arXiv:2602.06875cs.SEcs.AI2026-02被引 8

用运行轨迹辅助修复大模型生成代码的隐藏错误

TraceCoder: A Trace-Driven Multi-Agent Framework for Automated Debugging of LLM-Generated Code

  • 通过代码注入探针捕捉细粒度执行轨迹
  • 相较基线提升34.43%修复准确率,迭代修复单独贡献65.61%增益
  • 适合需要高可靠性代码生成的开发场景

大型语言模型在复杂任务中常生成存在细微但关键缺陷的代码。现有自动化修复方法多依赖表面的通过/失败信号,难以洞察程序行为,导致错误定位不精准。此外,缺乏对过往失败经验的学习机制,使修复过程陷入重复低效循环。为此,我们提出TraceCoder,一种模拟人类专家‘观察-分析-修复’流程的协作式多智能体框架。该框架首先通过诊断探针对代码进行插桩,捕获细粒度的运行时轨迹,以深入理解程序内部执行过程;随后对这些轨迹进行因果分析,精确识别故障根源。这一过程进一步通过一种新型历史教训学习机制(HLLM)增强,该机制从以往失败的修复尝试中提炼经验,指导后续修正策略并避免相同错误重现。为确保稳定收敛,系统引入回滚机制,要求每次修复迭代都严格优于前一次。在多个基准测试上的综合实验表明,TraceCoder相比先进基线实现高达34.43%的相对准确率提升。消融实验证实各组件有效性,仅迭代修复流程本身即带来65.61%的相对性能增益。此外,TraceCoder在准确率与成本效率方面均显著优于主流迭代方法。

原文摘要 · Abstract (English)

Large Language Models (LLMs) often generate code with subtle but critical bugs, especially for complex tasks. Existing automated repair methods typically rely on superficial pass/fail signals, offering limited visibility into program behavior and hindering precise error localization. In addition, without a way to learn from prior failures, repair processes often fall into repetitive and inefficient cycles. To overcome these challenges, we present TraceCoder, a collaborative multi-agent framework that emulates the observe-analyze-repair process of human experts. The framework first instruments the code with diagnostic probes to capture fine-grained runtime traces, enabling deep insight into its internal execution. It then conducts causal analysis on these traces to accurately identify the root cause of the failure. This process is further enhanced by a novel Historical Lesson Learning Mechanism (HLLM), which distills insights from prior failed repair attempts to inform subsequent correction strategies and prevent recurrence of similar mistakes. To ensure stable convergence, a Rollback Mechanism enforces that each repair iteration constitutes a strict improvement toward the correct solution. Comprehensive experiments across multiple benchmarks show that TraceCoder achieves up to a 34.43\% relative improvement in Pass@1 accuracy over existing advanced baselines. Ablation studies verify the significance of each system component, with the iterative repair process alone contributing a 65.61\% relative gain in accuracy. Furthermore, TraceCoder significantly outperforms leading iterative methods in terms of both accuracy and cost-efficiency.

自动化修复代码生成多智能体调试

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。