Lode

Stand on the shoulders of giants.

Open the curator →
Source
arXiv
Published
Runtime
0:00
Snippets
5

A conversation between

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

Waveform of the source interview with highlighted segments per snippet.
0:00 0:00

§02

Snippets

  1. An AI agent completed a large-scale architectural refactoring across 189 files in a 717k-line TypeScript codebase using specification-first protocol with no human code review and no pre-existing test oracle.

    Demonstrates that formal specification and iterative verification can replace traditional human review and comprehensive test suites for high-stakes refactoring.

  2. The agent dismantled a lifetime invariant—the guarantee that a UI panel remains open for the duration of an AI request—allowing streams to survive panel closure and reattach on reopening.

    Shows that AI agents can reason through and execute changes to fundamental architectural constraints that conventional incremental refactoring would struggle with.

  3. The agent completed 31 audit passes that identified and corrected 201 defects before any human executed the program, reaching zero findings across two consecutive verification cycles.

    Specification-driven iteration can catch defects earlier and more systematically than traditional post-hoc testing.

  4. The entire refactoring—14 specification cycles, 17 verification cycles, and implementation across 288 files—cost USD 2,430 and completed in three days with no observed bugs in subsequent use.

    Formal specification-first protocols can make large architectural changes economically and temporally feasible at scale.

  5. The frozen specification was audited against the implemented code across 17 verification cycles, with session logs and full specification published to allow external consistency checking by other language models.

    Transparency and auditability of both specification and implementation enable third-party verification without requiring human code review.

§03

Synthesis

Specification-First Refactoring at Scale: AI Agent Completes "Infeasible" Architectural Change

An AI coding agent successfully dismantled a core architectural invariant across a 717k-line TypeScript codebase—a task the author deemed infeasible for incremental refactoring—by following a strict specification-first protocol with no human code review and no pre-existing test oracle to validate correctness.

The Problem and the Change

The system is a production application spanning 3,648 files. The central invariant being removed: that a UI panel must remain open for the entire duration of an AI request. The target behavior was more flexible: streaming generations should survive panel closure, persist as live streams, and reattach to the same stream when the panel reopens—with zero data loss or duplication.

This is a deep architectural constraint, touching 189 files directly (31 newly created). The full diff across two commits spans 288 files, 34,770 additions, 16,422 deletions. Conventionally, such a change would require a codebase rewrite rather than incremental refactoring.

The Protocol

The agent followed a two-phase audit-heavy workflow:

Specification phase (14 refinement cycles): The agent formalized the target behavior in writing, then audited its specification against the existing source code to ensure it captured the actual constraints and behavior that needed to change.

Implementation phase (17 verification cycles): After atomic implementation, the agent ran a compile/test feedback loop, then re-audited the resulting code against the frozen specification. Across all 31 audit passes, the agent identified and corrected 201 defects before any human ran the program.

The convergence criterion was empirical: two consecutive verification passes with zero findings.

Why This Matters

The case study challenges a widespread assumption about large refactorings: that they require human judgment and incremental testing. Here, formal specification + relentless automated auditing + tight feedback loops replaced human code review. The author executed no tests themselves during development; the first human execution of the refactored code occurred three days later, after the agent had reached convergence.

The results: Across the initial session and roughly thirty subsequent sessions, the software behaved as specified with no observed bugs. Total elapsed time: three days. Total cost: USD 2,430.

The evidence is public: the authors published over 1,500 pages of session logs and the full specification (in French) to allow inspection of the process and consistency checking by language models.

Key Insight

This work suggests that specification-first development with AI agents may unlock a new mode for high-stakes refactoring—one where formal rigor and exhaustive auditing substitute for the human code review and incremental validation that architects have relied on for decades. The absence of an oracle (no pre-existing golden tests) did not prevent convergence; the specification itself became the oracle.

Mine your own.

Lode is a workbench, not a feed. Paste a YouTube URL. The model proposes a transcript, a set of quote-grounded snippets, a synthesis essay, and the fan-out. You decide what stays.

Open the curator