以AI编码代理实现规范优先的收敛:一项跨189个文件、71.7万行代码库中拆除核心架构不变量的案例研究
研究论文 · 2026/08/14
本文报告了一个由AI编码代理在规范优先协议下进行的大规模架构重构的单一案例研究,该过程没有人工审查生成的代码,也没有预先存在的预言机来验证目标行为。任务是在一个大型相互依赖的代码库中拆除一个核心不变量,作者认为通过增量重构实际上不可行,这类变更通常需要重写。在所述协议下,代理成功完成了任务。该系统是一个717,725行的生产级TypeScript应用程序,包含3,648个文件。任务要求拆除一个核心生命周期不变量:保证UI面板在AI请求期间保持打开。目标行为是流式生成在面板关闭后仍然存活,并在重新打开时重新连接到同一实时流,不丢失或重复。协议包括:代理进行正式规范、14轮细化周期对照源代码审计规范、原子实现、编译/测试反馈循环,然后17轮验证周期对照冻结规范审计代码。在31次审计通过中,在任何人执行程序之前纠正了201个缺陷。收敛标准是经验性的:连续两次验证通过返回零发现。变更涉及189个文件(31个新文件);加上提取阶段,两个提交共288个文件,34,770行插入,16,422行删除。在第一次和大约三十次后续会话中,软件行为符合规范,未观察到错误。耗时:三天;成本:2,430美元。完整规范和原始会话日志(超过1,500页法语)作为证据发布,允许检查过程并提交给语言模型进行一致性检查。
本文提供了一个罕见的、完全仪器化的案例研究,展示了AI编码代理在规范优先协议下成功完成大规模架构重构,且无需人工审查代码。该研究提供了详细的协议、成本、时间和缺陷数据,并发布了完整证据,对AI辅助软件工程领域具有重要参考价值。
This paper reports a single, fully instrumented case study of a large-scale architectural refactoring by an AI coding agent under a specification-first protocol, with no human review of the generated code and no pre-existing oracle to validate the target behaviour. The task, dismantling a central invariant across a large interdependent codebase, was assessed by the author as effectively infeasible through incremental refactoring, the kind of change that conventionally calls for a rewrite instead. Under the protocol described here, the agent completed it successfully. The system is a 717,725-line production TypeScript application across 3,648 files. The task required dismantling a core lifetime invariant: the guarantee that a UI panel remains open for the duration of an AI request. The target behaviour was that a streaming generation survives the closing of its panel and can be reattached, on reopening, to the same live stream with no loss or duplication. The protocol: formal specification by the agent, 14 refinement cycles auditing that specification against the source code, atomic implementation, a compile/test feedback loop, then 17 verification cycles auditing the code against the frozen specification. Across 31 audit passes, 201 defects were corrected before any human executed the program. The convergence criterion was empirical: two consecutive verification passes returning zero findings. The change touched 189 files (31 new); with the extraction phase, the two commits total 288 files, 34,770 insertions, 16,422 deletions. Across the first and roughly thirty later sessions, the software behaved as specified, no bug observed. Elapsed: three days; cost: USD 2,430. The full specification and raw session logs, 1,500+ pages in French, are published as evidence, allowing inspection of the process and submission to a language model for consistency checking.