← Back to Index
September 24, 2026•Web Development

The Most Controversial Rewrite in History: Inside Bun's 960k-Line AI Port from Zig to Rust

The Cardinal Sin of Software Engineering

In 2000, Joel Spolsky published what would become the most famous essay in modern software engineering: Things You Should Never Do, Part I. His thesis was absolute and unforgiving: the single worst strategic mistake any software company can make is deciding to rewrite an application from scratch. Netscape did it with their browser and handed the web to Microsoft Internet Explorer; countless startups did it and burned their entire runway before shipping a functional binary.

For twenty-six years, Spolsky's rule stood as sacred dogma.

Then, in 2026, Jarred Sumner and the Bun team took a sledgehammer to it. In less than two weeks, Bun—the fastest-growing alternative JavaScript runtime—executed what developers are calling the most controversial rewrite in computing history: porting 960,000 lines of low-level systems code from Zig to Rust, automated almost entirely by Claude AI coding agents.

The announcement sent shockwaves through Hacker News, Reddit, and the systems programming community. For four years, Bun's primary brand identity was synonymous with Zig; it was the undisputed flagship project proving that Zig could power production infrastructure. To abandon Zig for Rust overnight—and to do so using autonomous AI agents—has ignited an intense technical civil war.


1. The Catalyst: When Fast Runtimes Leak Memory

Why would Bun risk its entire project lifecycle on a ground-up language rewrite?

The answer came down to an existential production bottleneck: chronic, un-debuggable memory leaks.

As Bun gained enterprise adoption, its largest operational customer became Anthropic's terminal agent, Claude Code. In high-throughput, long-running agentic workloads—where thousands of sub-processes, shell scripts, and TypeScript files are evaluated continuously—Bun began suffering severe memory bloat. Developers reported memory consumption skyrocketing from 200 megabytes to 14 gigabytes, and in extreme sessions, past 23 gigabytes, causing operating systems to terminate the runtime via OOM (Out Of Memory) killers.

In Zig, memory management is entirely manual. Developers explicitly pass allocators to every data structure. While this provides unrivaled raw execution speed and mechanical sympathy with modern CPU caches, tracking subtle pointer leaks across an asynchronous, event-driven runtime with hundreds of Node.js API polyfills proved to be a grueling debugging nightmare for a small engineering team.

Rust's strict compile-time ownership model, Borrow Checker, and RAII (Resource Acquisition Is Initialization) semantics promised an immediate architectural solution: deterministic memory deallocation without garbage collection pauses.


2. The 11-Day AI Port: 960,000 Lines Across Language Paradigms

What shocked the industry was not the decision to migrate to Rust, but the speed and methodology of the execution.

A manual rewrite of a nearly million-line systems codebase—handling HTTP/3 parsing, JavaScriptCore FFI bindings, WebSockets, bundling, and SQLite integration—would traditionally require a team of thirty senior systems engineers two to three years of grueling labor.

Instead, Jarred Sumner orchestrated an ensemble of Claude AI agents executing in parallel:

  • The AI parsed existing Zig Abstract Syntax Trees (ASTs) and mapped them directly into equivalent Rust crates.
  • Agents ran automated test suites in continuous loops, iteratively adjusting types, lifetime annotations, and borrow boundaries until the tests turned green.
  • Within eleven days, the Rust branch achieved an astonishing 99.8% pass rate on Bun's existing Linux x64 glibc test suite.
// Conceptual snippet: Wrapping JavaScriptCore C++ bindings in Rust
// What used to be manual Zig pointer arithmetic converted to Rust
pub struct JSRuntimeContext {
    vm: *mut JSC_VM,
    global_object: *mut JSC_JSGlobalObject,
}

impl Drop for JSRuntimeContext {
    fn drop(&mut self) {
        unsafe {
            // Guaranteed deterministic destruction on scope exit
            JSC_JSGlobalObject_release(self.global_object);
            JSC_VM_release(self.vm);
        } 
    }
}

To AI optimists, this was the crowning achievement of the generative software revolution: a tiny team achieving a 50-person-year migration in days.


3. The 13,000 Unsafe Blocks: Engineering Triumph or Vibecoded Disaster?

However, once developers inspected the emitted Rust codebase, celebration turned into fierce skepticism.

Rust's legendary memory safety guarantees only apply to "safe" Rust. When code interacts with raw pointers, foreign C/C++ libraries, or OS-level system calls, it must be wrapped in unsafe { ... } blocks, effectively telling the compiler: "trust me, I know what I'm doing."

Audits of Bun's new Rust repository revealed over 13,000 unsafe blocks.

Critics immediately labeled the port a "vibecoded disaster." In idiomatic Rust, unsafe is used sparingly as a surgical escape hatch. Porting Zig's raw pointer arithmetic directly into unsafe Rust blocks allowed the AI to bypass the Borrow Checker and pass unit tests, but it fundamentally compromised the safety thesis of migrating to Rust in the first place:

  • If pointers are dereferenced inside unverified unsafe blocks, use-after-free bugs and data races can still occur.
  • Fuzzing and static analysis tools struggle to verify synthesized pointer lifetimes.
  • Maintainability becomes treacherous: human engineers cannot easily reason about edge cases in machine-translated systems code.

4. The Zig Community Pushback: Andrew Kelley's Critique

The rewrite also triggered profound personal and philosophical friction. Zig creator Andrew Kelley publicly addressed the fallout, expressing disappointment not just in losing Zig's most visible real-world showcase, but in the engineering methodology itself.

Kelley pointed out that Bun was not rigorously fuzzing its Zig codebase to locate leaks before abandoning it, and argued that trading Zig's clean, explicit simplicity for thousands of unsafe Rust blocks was an illusion of progress. The episode exposed a widening cultural divide between language purists who view software engineering as a disciplined, deliberate craft, and high-velocity startup founders willing to wield brute-force AI synthesis to solve immediate business problems.


5. Did AI Just Disprove Spolsky's Rule?

Does Bun's rewrite invalidate Joel Spolsky's famous warning against ground-up rewrites?

The answer is both yes and no:

  • What Changed: The fatal trap of the traditional rewrite was time. Companies died because they couldn't ship features for two years while competitors ate their market share. AI agents compress that multi-year feedback loop into days, removing the catastrophic market-timing penalty.
  • What Remains Dangerous: Spolsky warned that rewrites discard thousands of hard-won bug fixes hidden in ugly, legacy code. An AI porting code against an existing test suite only preserves the behaviors that were explicitly tested. Unwritten assumptions, subtle OS timing quirks, and edge-case memory safety are inevitably stripped away.

Conclusion: A Glimpse into the Future of Systems Engineering

Whether you view Bun's Rust rewrite as a reckless hack or a visionary breakthrough, one reality is undeniable: the cost of large-scale software refactoring has collapsed forever.

We have entered an era where programming languages are no longer permanent commitments. When autonomous coding agents can translate complex ASTs, port hundreds of thousands of lines of code across paradigms, and repair test suites in real-time, the barriers between systems ecosystems dissolve.

Bun took the ultimate gamble. Over the coming months, production reliability, enterprise stability, and CVE vulnerability disclosures will deliver the final verdict on whether AI-generated systems infrastructure can truly stand the test of time.

Build something exceptional.

Custom web design and development, no templates.

Start a Project
Bun's Zig to Rust AI Rewrite: The 2026 Controversy — ZIAFTRA