Bun Rewrites 535K Lines of Zig into Rust in Four Months, Eliminates Numerous Memory Leaks
Bruno Couriol ยท rss ยท 2026-09-20 source โ Reader ๐ฅ๏ธ
Agentic EngineeringCapacity to Verify AI OutputCoding AgentsIncremental Rewrite GranularityMulti-Agent OrchestrationRust (Programming Language)
A single domain expert, directing dozens of parallel adversarial-review AI agents against a mechanical (behavior-preserving) porting process anchored to an extensive pre-existing test suite, rewrote a 535K-line production codebase into a memory-safer language in months instead of a year and shipped measurable bug and memory-leak reductions โ but critics dispute whether passing that same test suite ever was, or could be, sufficient proof that a million lines of largely unreviewed AI-generated code are actually safe.
practical ยท mixed โ Primarily a narrative case report (Sumner's account of the rewrite process and outcomes), but it embeds a genuine argumentative thread via Andrew Kelley's published rebuttal of the safety framing, plus a third-party (vitaminCPP) reframing of the stakes. It implicitly argues 'this approach is worth trusting,' while also reporting the counter-argument that it is not.
Structure
| Part | Role |
|---|---|
| Sumner's motivation and the historical risk of rewrites ('historically, rewrites are a terrible idea') | context |
| The process: PORTING.md and LIFETIMES.tsv planning artifacts, implementer/reviewer/fixer agent roles run in isolated context windows, sharded across 64 parallel Claude instances | evidence (methodology) |
| Quantitative outcomes: $165,000 in tokens, 1,300 lines/minute peak, 128 bugs fixed, native memory leaks eliminated, 2-5% HTTP throughput gain | evidence (results) |
| Post-merge hardening: 19 subtle semantic regressions found by fuzzing, 11 rounds of security review, 15 fuzzing-driven PRs | evidence (qualification of the results) |
| Andrew Kelley's (Zig creator) rebuttal that the safety framing is a 'sleight of hand' since bugs are eliminated by engineering resources, not language or method, and that the same test suite deemed inadequate for the old Zig code cannot simultaneously be trusted as sufficient for a million new lines | counter-argument |
| vitaminCPP's framing of the merge as an 'industry canary' for whether massive LLM-generated codebases stay maintainable long-term | broader implication |
Key terms
- adversarial agentic code review
A structural separation where an implementer agent never reviews its own work and two reviewer agents (in isolated context windows, seeing only file diffs) have no task but to find bugs and behavioral divergences before a fixer agent addresses them โ 'the implementer doesn't review, the reviewer doesn't implement.' - mechanical port
A rewrite that preserves the original code's structure and behavior line-for-line rather than redesigning it โ chosen specifically because it lets the existing test suite serve as an oracle, at the cost of some regressions rooted in surface-level Zig/Rust syntactic similarity. - unreviewed slop
Andrew Kelley's characterization of the merged Rust code: over a million lines accepted into production without genuine human line-by-line review, regardless of how many automated gates it passed.
Propositions
- explicitThe AI-assisted rewrite of Bun from Zig to Rust was completed and released (v1.4.0) about four months after it began, versus an estimated one year for a small human team.conf: highextendsHow building software is changing at Anthropic ยท p5 โ Gives the fuller end-to-end timeline (4 months to the v1.4.0 release) against the companion piece's 11-day initial-rewrite-sprint framing, showing most elapsed time went to post-hoc hardening rather than generation.
- explicitRust's compiler-enforced ownership/borrow-checking converts a recurring class of memory bugs (use-after-free, double-free, forgot-to-free on error paths) into compile errors, which the author considers a better feedback loop than a style guide.conf: high
- explicitStructural separation between an implementer agent and adversarial reviewer agents, each confined to isolated context windows, was treated as essential to catching bugs and behavioral divergences before merge.conf: high
- explicitPlanning artifacts (PORTING.md mapping Zig-to-Rust patterns, LIFETIMES.tsv documenting struct-field lifetimes) were key success factors โ the planning phase mattered as much as execution.conf: high
- explicitPassing the full pre-existing test suite (over one million assertions) was necessary but not sufficient: subsequent fuzzing, 11 rounds of security review, and further validation surfaced 19 additional subtle semantic regressions and produced 15 more fix PRs.conf: high
- explicitThe Rust rewrite (Bun v1.4.0) fixed 128 longstanding bugs from v1.3.14, eliminated native memory leaks (stable at 609MB vs. climbing past 6.7GB across 2,000 consecutive Bun.build() runs), and improved HTTP throughput by 2-5%.conf: highrefinesPresentation: Accelerating Performance by Incrementally Integrating Rust Into Existing Codebase ยท p1 โ p1 there claims full-system rewrites are generically error-prone and blow past deadlines; this case reports the opposite outcome for an AI-orchestrated, test-suite-anchored full rewrite โ though the 19 post-merge regressions this same document reports suggest the underlying risk was reduced, not eliminated.
- implicitA sufficiently rigorous process-level verification loop (planning artifacts, structural implementer/reviewer separation, post-merge fuzzing and security review) can substitute for exhaustive human line-by-line review of a million lines of generated code, provided the codebase has an extensive, language-independent test suite to serve as an oracle.conf: medium
- explicitcontestedBugs and correctness in a large codebase come from dedicating engineering resources to catching them, not from which programming language or automated verification method is chosen โ and it is inconsistent to argue the old test suite didn't catch all the Zig bugs while trusting that same suite is sufficient to validate a million new lines of Rust.conf: highcontradictsHow building software is changing at Anthropic ยท p10 โ The companion piece frames layered automated verification (AI review, security scanner, fuzzing) as a legitimate substitute for human line-by-line review at scale; Kelley's critique here directly disputes that this substitution is trustworthy, on the same underlying rewrite.
- explicitBun's merged rewrite functions as an industry canary for whether massive, LLM-generated codebases can remain maintainable over the software engineering lifecycle โ an open, unresolved question.conf: medium
- implicitMost of the four-month public timeline was spent on post-hoc verification and hardening (fuzzing, security review, regression fixes) rather than on the generative rewrite itself, which undercuts a naive 'AI made this N times faster' headline reading of the story.conf: medium
Arguments
The rewrite's process was rigorous enough that the resulting codebase is trustworthy to ship, despite being largely AI-generated.
Explicit premises:
- Rust's borrow checker converts a known bug class into compile errors.
- The test suite is decoupled from the implementation language, so it remains a valid oracle across the rewrite.
- Implementer/reviewer/fixer role separation, run in isolated context windows, was designed specifically to catch divergences before merge.
- Extensive post-merge hardening (11 rounds of security review, 24/7 fuzzing) found and fixed the regressions that did slip through.
Implicit premises:
- A sufficiently rigorous process-level verification loop can substitute for genuine human line-by-line review of a million lines of generated code.
- The combination of the original test suite, fuzzing, and security review constitutes a sufficient oracle for behavioral correctness.
Inferences:
- If this process generalizes, the bottleneck for future large-scale AI rewrites shifts from generation speed to the quality of the test/verification oracle available โ codebases with weaker test suites would be substantially riskier candidates for the same approach.
The safety claim for the rewrite is a sleight of hand and the resulting code should be regarded as unreviewed. strength: high
Explicit premises:
- Bug elimination in practice comes from dedicated engineering review effort, not from a choice of language or verification pipeline.
- The article's own admission that the Zig test suite didn't catch all of Zig's bugs undercuts relying on that same suite as sufficient for validating a million new lines of Rust.
Implicit premises:
- An automated multi-agent review loop is not equivalent in kind to genuine independent human engineering review.
- Code merged without that human review carries real risk regardless of how many automated gates it passed.
Inferences:
- If Kelley is right, the 128-bugs-fixed and memory-leak-elimination results should be read as evidence of test-suite/fuzzing thoroughness on this particular project, not as evidence that the rewrite methodology is generally safe โ a claim the article does not test on a second codebase.
Narratives
- Sumner's own account of the week-long spike: starting from 'I didn't expect it to work' skepticism, watching the test-suite pass rate climb over a few days, and moving to 'I'm going to merge this' confidence.
โ Implicitly supports the proposition that empirically watching pass rates rise is treated as a legitimate basis for trusting a large AI-generated change, in place of a priori certainty. - The in-process bundling memory test: 2,000 consecutive Bun.build() operations plateauing stably at 609MB in Rust versus climbing past 6.7GB previously.
โ Supports the memory-leak-elimination claim with a concrete, falsifiable before/after measurement rather than an anecdote.
Questions addressed
- โ
Can a small, AI-orchestrated effort safely rewrite a large legacy codebase into a memory-safer language faster than a human team could?
Sumner's account resolves this affirmatively for this case, citing the completed rewrite, bug fixes, and memory-leak elimination โ though the resolution is explicitly contested by Kelley. - โญ Is 'all tests pass' sufficient evidence that a rewrite of this scale is behaviorally correct?
The article's own account undercuts a 'yes': 19 subtle regressions were found only after merge, via fuzzing and security review, not via the original test suite โ yet the piece does not reconcile this with its framing that the process worked as intended. - โญ What is the true all-in cost of this approach compared to the human-only counterfactual, including internal-vs-external token pricing and the ongoing maintenance risk of a largely AI-authored codebase?
Gaps
- incompleteThe piece never addresses whether this specific implementer/reviewer/fixer workflow generalizes beyond an unusually well-suited case: a codebase with a mature, language-independent test suite, and its original author personally available to direct 64 parallel agents. No second example is offered.
Read next: Look for an independently reported large-scale AI rewrite of a codebase with a weaker test suite, or without the original author directing it, to see whether the risk profile holds. - illogicalThe 19 subtle semantic regressions caught only by post-merge fuzzing and security review โ not by the original test suite โ is empirical evidence that 'the test suite is good enough' was not fully true at merge time. The piece keeps its framing that the process worked as designed without reconciling why a suite deemed adequate to greenlight the merge then required 11 rounds of security review and 24/7 fuzzing to become trustworthy.
Read next: Compare against extract-boeckeler-maintainability-sensors-coding-agents and extract-code-maintainability-plummets-ai-coding-era for how this corpus elsewhere treats 'tests pass' as a weak signal of AI-generated code quality. - uninformedThe $165,000 token cost is reported 'at API pricing' without noting whether this reflects a subsidized internal rate (Bun/Anthropic are commonly owned), nor is any counterfactual maintenance-cost comparison offered for continuing to hand-fix the original Zig memory bugs over time.
Read next: See the companion gap already recorded on the same underlying event in extract-pragmatic-engineer-anthropic-building-software#g3.
Closes gaps elsewhere
- How building software is changing at Anthropic ยท g4 โ Reports the empirical outcome the companion piece left unexamined: post-merge fuzzing, 11 rounds of security review, and further validation caught 19 subtle semantic regressions the original TypeScript test suite had not caught, and fuzzing surfaced 15 more PRs' worth of issues โ direct evidence that 'all tests pass' was not sufficient proof of correctness and that additional out-of-band verification layers did real, non-redundant work.
Related documents
- Presentation: Accelerating Performance by Incrementally Integrating Rust Into Existing Codebase
- How building software is changing at Anthropic
- Have your agent record video demos of its work with shot-scraper video
- [FULL WORKSHOP] AI Coding For Real Engineers - Matt Pocock, AI Hero
- 11) AI-spesial med Vilde Opsal og Anders Sveen
- Steve Yegge's Vibe Coding Manifesto: Why Claude Code Isn't It & What Comes After the IDE
- Coding agents have crossed a chasm
- Agent Skills: Google-Backed AI Coding Agent Workflow
- Agentic AI and Code Reviews
- Accelerating Delivery: How AI Agents Can Own the Initial Code Draft