让代码生成过程可解释可审计,每行代码都有来源和修改记录。
TraceCoder: Explainable and Auditable Code Generation with Position-Key Snippet Versioning

- 用版本化片段历史记录每次修复的失败原因和模型解释。
- 30个任务中平均代码变更率30%,10个任务达到6次迭代上限。
- 通过位置键索引实现细粒度追踪,适合高可靠性场景使用。
当前基于大模型的编程代理生成代码如黑箱:每行代码的逻辑依据隐藏,修复过程中的演化痕迹消失,事后审计无法进行。本文提出一种新型代码生成机制,通过三项互补设计解决上述问题:(i) 关系型片段历史结构,记录每次修复事件中的测试基准、轮次编号、失败文本及大模型解释,支持完整溯源查询;(ii) 浏览器可视化工具,将历史以热力图与悬停标注形式呈现源码;(iii) 带树节点分隔符的竞争性分数位置键索引方案,为每个代码片段分配稳定且字典序排列的标识符,实现细粒度追踪而不破坏原有结构。在涵盖字符串处理、数学计算与数据结构操作的30个算法任务上评估,两种提供方配置下,10个任务耗尽6轮迭代预算(针对细微边界情况)。平均代码变更率(Chg%)达30%,十组代码片段中有三组可追溯至具体修复事件,相较仅用Gemini 2.0 Flash在20个任务子集上提升至21%。三个案例研究证明系统能说明哪些特定测试失败影响了最终程序的每一行。该机制使自动化代码生成的内部“叙事”变得可审计、可重放,对生产环境中的可信与责任至关重要。
原文摘要 · Abstract (English)
Contemporary LLM-based coding agents produce code as black-box outputs: the rationale behind each line is hidden, the evolution of the code through benchmark-driven repair is ephemeral, and post-hoc auditing is impossible. We present a code generation concept that addresses these shortcomings through three complementary mechanisms: (i) a relational snippet-history schema that records, per repair event, the benchmark reference, round number, failure text, and LLM explanation, enabling full provenance queries; (ii) a browser-based visualisation tool that renders this history as heat-mapped, hover-annotated source code; and (iii) a competitive fractional position-key indexing scheme with tree-node delimiters that assigns stable, lexicographically-ordered identifiers to each code snippet, enabling fine-grained tracking without disrupting surrounding lines. We evaluate TraceCoder on 30 algorithmic programming tasks spanning string processing, mathematical computation, and data-structure manipulation, across two provider configurations. Of these, 10 exhaust the 6-iteration budget on tasks with subtle edge-case behaviour. Mean Chg% reaches 30%, three in ten code snippets carry a traceable repair-event row, compared to 21% when using Gemini 2.0 Flash as sole provider on a 20-task subset. Three detailed case studies demonstrate how the system explains which specific benchmark failures shaped each line of the final program. The proposed mechanism makes the internal "narrative" of automated code generation auditable and replayable, a property essential for trust and accountability in production deployments.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。