ATRIUMsearch → argument graph
Article · 2026-07-08 · 6 moments

Rewriting Bun in Rust

Rewriting Bun in Rust Jarred Sumner has been promising this blog post (since May 9th) about his Zig to Rust rewrite of Bun for significantly longer than it took him to finish the rewrite. Honestly, it was worth the wait. This is a detailed description of an extremely sophisticated piece of agentic engineering, featuring dynamic workflows, trial runs, adversarial review and all sorts of other interesting tricks. Jarred spends the first half of the post praising Zig for getting Bun this far. Th ✦ AI generated

01
Claim

Bun's crashes largely came from mixing garbage-collected memory with manually-managed memory, a combination so uncommon that no language is really designed to handle it safely, which is why he grew tired of Bun's bugfix list and worried about crashes.

Jarred Sumner explains that Bun's persistent crash bugs stemmed from an unusual mix of GC and manual memory management that no language, including Zig, is really built to handle.

transcript

Jarred Sumner: Our bugfix list felt bad and I was tired of going to sleep worrying about crashes in Bun. I don't blame Zig for that - other users of Zig don't have the bugs we had, and mixing GC with manually-managed memory is an uncommon enough thing for software to need that no language really designs for it.

extends · 1

02
Context

Bun's TypeScript-based test suite could double as a conformance suite, which is what allowed an agent harness to automate most of the initial Zig-to-Rust port using an early version of the Mythos/Fable model.

A key enabling condition for the rewrite was that Bun already had a language-independent TypeScript test suite, which agents could use to verify correctness while porting code from Zig to Rust.

transcript

Simon Willison: A crucial enabling factor for the rewrite was that the Bun test suite was written in TypeScript, which meant it could act as a conformance suite. This allowed an agent harness to automate much of the initial port from Bun to Rust, initially as an experiment to try out an earlier version of the model we now have access to as Mythos/Fable.

rebuts · 1

03
Claim

Coding agents powered by today's frontier models have overturned the old rule that you should never stop the world and rewrite a large piece of software from the ground up.

The author argues that Joel Spolsky's classic warning against full rewrites no longer fully applies now that frontier-model coding agents exist.

transcript

Simon Willison: Everyone knows you should never stop the world and rewrite a large piece of software from the ground up. Joel Spolsky highlighted that in Things You Should Never Do, Part I back in April 2000! Coding agents powered by today's frontier models change that equation.

explains mechanism · 1gives example · 1

04
Mechanism

Safe Rust turns the use-after-free, double-free, and forgot-to-free bugs that plagued Bun's error paths into compiler errors, thanks to RAII-like automatic cleanup via Drop.

Jarred Sumner explains the technical reason for choosing Rust: its ownership model catches the exact class of memory bugs that had been hurting Bun, at compile time.

transcript

Jarred Sumner: A large percentage of bugs from that list are use-after-free, double-free, and "forgot to free" in an error path. In safe Rust, these are compiler errors and RAII-like automatic cleanup with Drop.

05
Data

The pre-merge rewrite consumed 5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached input token reads, roughly $165,000 at API pricing, though Anthropic itself didn't have to pay for the tokens.

The full rewrite's token usage before merging translated to an estimated $165,000 at standard API pricing, a cost Anthropic didn't actually have to pay.

transcript

Simon Willison: Pre-merge, this took 5.9 billion uncached input tokens, 690 million output tokens, and 72 billion cached input token reads — around $165,000 at API pricing.

06
Mechanism

The way to responsibly merge a PR with over a million LLM-authored lines is a language-independent test suite with a million assertions plus adversarial code review, and to fix the process that generates the code rather than hand-fixing the code itself when something goes wrong.

The confidence-building strategy for merging a massive AI-generated rewrite combined a huge language-independent test suite, adversarial review, and fixing the generation process itself rather than patching individual bugs.

transcript

Jarred Sumner: A language-independent test suite with a million assertions, adversarial code review and when something does go wrong, fixing the process that generates the code instead of hand-fixing the code.

Highlight slides
Related episodes