Rewriting Bun in Rust
AI coding agents have changed the fundamental assumptions of software engineering: Bun's developer used AI agents to rewrite the project from Zig to Rust in just 11 days, proving that large-scale rewrites are no longer taboo.
- The core motivation for Bun's migration from Zig to Rust was memory safety, and AI agents made this historically one-way decision reversible
- A language-agnostic test suite acted as a 'conformance suite', enabling AI agents to automatically port code
- Agent engineering practices involve dynamic workflows, trial runs, and adversarial review, not just one-off code generation
- This marks the loosening of the 'never rewrite' dogma in software engineering; language choice is becoming more fluid
If you follow how AI is actually being used in software development, a recent blog post by Bun's founder might rock some of your long-held beliefs. Jarred Sumner documented in detail how they used AI coding agents to migrate Bun's core from Zig to Rust in just 11 days. This is not just another tech stack victory — it reveals a deeper paradigm shift: the "never rewrite" taboo is being broken by AI.
The Why: What Drove the Rewrite?
Bun is a JavaScript runtime written in Zig, known for its speed. But Zig's manual memory management left Bun plagued by memory bugs like use-after-free and double-free errors. Sumner confessed he was tired of worrying about crashes every night. While Zig is excellent in itself, mixing garbage collection (GC) with manual memory management is rare — so rare that no language really designs for it. Until very recently, language choice for a project like Bun was a one-way door: once chosen, almost impossible to go back.
The How: How Did AI Make the "Impossible" Possible?
Conventional wisdom says you should never stop the world to rewrite a large software project from scratch. Joel Spolsky wrote the canonical article about this back in 2000. But Sumner argues that coding agents powered by frontier models have changed the equation.
Specifically, Bun's team had a test suite written in TypeScript, which is language-agnostic. This test suite became a perfect "conformance suite": it defines how Bun should behave, regardless of whether the underlying language is Zig or Rust. Sumner built an agent harness that let the AI automatically port Zig code to Rust and then run the tests to see if they passed. At first he didn't expect it to work, but within days, a high percentage of tests were passing, and the new Rust code mapped closely to the original Zig. His opinion shifted from "worth trying" to "I'm going to merge this."
But this wasn't just naive code generation. Sumner describes sophisticated agent engineering: dynamic workflows (the AI decides what to do), trial runs (iteratively adjusting prompts and loops), and "adversarial review" — he would manually read outputs, spot bugs, and then prompt Claude to edit the loop logic to fix issues. In the end he faced a +1 million line PR, and the confidence to merge came entirely from that verifiable test suite.
The Bigger Trend: Programming Languages Are No Longer One-Way Streets
Perhaps the most profound impact is that it reveals a trend: with AI agents, language choice is shifting from a one-way door to a revolving door. Sumner emphasized in his post, "Until very recently, programming language choice was a one-way decision for a project like Bun." But now, if you have a solid test suite, AI can help you perform a massive language migration. That means teams can more flexibly pick a language for the current needs, and even switch later if they want.
Underneath this is the maturing of AI agent engineering. We're used to AI writing small functions or scripts, but Bun's case shows AI can participate in architectural-level refactors — as long as you provide clear goals and a means of verification.
Practical Takeaways: What Can You Learn?
For the average developer, Bun's story isn't a call to immediately rewrite your own project, but rather a new mindset:
- Your test suite is the spec you give to the AI. High-quality, language-agnostic tests are the foundation for AI-assisted safe refactoring.
- Agent engineering is magic that requires iterative effort. Sumner spent plenty of time monitoring, adjusting, and reviewing — much like training a junior developer.
- Start with small experiments. Bun's team initially tried an earlier model; you can test on non-critical modules first.
Counterintuitive Insight: AI Isn't Replacing Programmers — It's Changing Decision Logic
Many think AI will let you generate an entire app from a single sentence. But Bun's case shows the truly revolutionary shift is this: AI lets us make technical decisions we never dared before. Rewriting is no longer suicide, because AI has dramatically lowered the cost and risk. This might encourage more teams to innovate rather than being forever shackled to legacy code.
Of course, this requires strong engineering discipline and a testing culture. AI is just a lever — it always amplifies your own capability, not compensates for chaos.
Analysis by BitByAI · Read original