AI 用规范驱动重构了大型代码库的核心架构,无测试和人工审查下成功实现。
Specification-first convergence with an AI coding agent: a case study of dismantling a core architectural invariant across 189 files in a 717k-line codebase with no test oracle and no human code review
- AI 先写出精确规范,再通过多轮审计逐步修正代码。
- 修复201个缺陷后,连续两次验证无问题,完成189文件的重构。
- 适合关注AI编程可信性与大规模重构的开发者与研究者。
本文报告了一项由AI编程代理在规范优先协议下执行的大规模架构重构案例,全程无人工代码审查,也无预设测试验证目标行为。任务是在一个包含717,725行代码、3,648个文件的生产级TypeScript应用中,拆除一个核心生命周期不变量:即UI面板在AI请求期间保持打开状态。目标行为是流式生成过程可在面板关闭后继续运行,并在重新打开时无缝接续同一活跃流,不丢失也不重复。协议包括:由代理生成形式化规范,进行14轮规范与源码比对审计,原子化实现,编译/测试反馈循环,再进行17轮代码与冻结规范的验证。共经历31轮审计,修正201个缺陷后才首次由人类运行程序。收敛标准为连续两次验证无发现。此次变更影响189个文件(新增31个),合并提交共涉及288个文件,新增34,770行,删除16,422行。在前几次会话及后续约三十次迭代中,软件表现符合规范,未发现异常。整个过程耗时三天,成本2,430美元。完整规范与原始会话日志(超过1,500页法语)已公开,可供审查或提交语言模型进行一致性检验。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。