让代码生成器学会项目历史,产出更符合实际的合并请求。
Learning to Commit: Generating Organic Pull Requests via Online Repository Memory
- 通过分析历史提交记录,提取项目特有的编码风格与架构规律。
- 在未见任务上,代码风格一致性和内部接口复用率显著提升。
- 适合需要高契合度代码生成的开源维护者或团队使用。
基于大语言模型的编程代理在控制性基准测试中表现优异,但生成的合并请求常被真实维护者拒绝。根本原因并非功能错误,而是缺乏有机性:生成代码忽略项目特定规范,重复已有内部 API 功能,并违背多年积累的隐式架构约束。仅提供最新代码库快照不足以解决问题,因为快照仅反映最终状态,而非达成该状态的演变模式。我们提出 Learning to Commit 框架,通过在线仓库记忆(Online Repository Memory)填补这一空白。给定严格时间划分的仓库,代理对早期提交进行监督对比反思:盲目尝试解决每个历史问题,将预测结果与真实补丁对比,将差异提炼为持续增长的可复用技能集合,涵盖编码风格、内部 API 使用和架构不变量。当收到新合并请求描述时,代理基于累积技能进行生成,使修改内容扎根于项目自身演化路径,而非通用预训练先验。评估针对真正未来的已合并请求展开,涵盖功能正确性、代码风格一致性、内部 API 复用率及修改区域合理性等多个维度。在具有丰富提交历史的专家维护仓库上实验表明,该方法有效提升了未来任务上的有机性得分。
原文摘要 · Abstract (English)
Large language model (LLM)-based coding agents achieve impressive results on controlled benchmarks yet routinely produce pull requests that real maintainers reject. The root cause is not functional incorrectness but a lack of organicity: generated code ignores project-specific conventions, duplicates functionality already provided by internal APIs, and violates implicit architectural constraints accumulated over years of development. Simply exposing an agent to the latest repository snapshot is not enough: the snapshot reveals the final state of the codebase, but not the repository-specific change patterns by which that state was reached. We introduce Learning to Commit, a framework that closes this gap through Online Repository Memory. Given a repository with a strict chronological split, the agent performs supervised contrastive reflection on earlier commits: it blindly attempts to resolve each historical issue, compares its prediction against the oracle diff, and distils the gap into a continuously growing set of skills-reusable patterns capturing coding style, internal API usage, and architectural invariants. When a new PR description arrives, the agent conditions its generation on these accumulated skills, producing changes grounded in the project's own evolution rather than generic pretraining priors. Evaluation is conducted on genuinely future, merged pull requests that could not have been seen during the skill-building phase, and spans multiple dimensions including functional correctness, code-style consistency, internal API reuse rate, and modified-region plausibility. Experiments on an expert-maintained repository with rich commit history show that Online Repository Memory effectively improves organicity scores on held-out future tasks.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。