Bun の Rust への書き換えについて
Bun の開発者 Jarred Sumner が、LLM エージェントを活用した「アジェンティック・エンジニアリング」により、Zig から Rust への大規模コード書き換えを成功させた事例が報告された。
キーポイント
AI エージェントによる大規模リファクタリングの成功
従来の「書き換えは避けるべき」という常識を、LLM パワーを持つコーディングエージェントによって覆し、100 万行以上のコードベースを Zig から Rust へ移行した。
メモリ管理の課題解決と Rust への移行理由
Zig の GC と手動メモリの混合による使用後解放(use-after-free)などのバグが深刻化し、Rust のコンパイラ保証と RAII 機構でこれを解決するために書き換えが行われた。
TypeScript ベースのテストスイートが鍵役
Bun のテストスイートが TypeScript で書かれていたことが、AI エージェントによる自動ポートとコンフォーマンス検証を可能にする決定的な要因となった。
人間による監査とフィードバックループの重要性
完全自動化ではなく、開発者が AI の出力を人手でレビューし、Claude へのプロンプト修正を通じてループを改善するハイブリッドなプロセスが採用された。
影響分析・編集コメントを表示
影響分析
この事例は、ソフトウェア開発のパラダイムシフトを示唆しており、LLM エージェントが単なるコード生成ツールから、プロジェクト全体のアーキテクチャ変更や言語移行を主導する「アジェンティック・エンジニア」として機能し得ることを実証した。今後は、言語の選択が一度きりの決断ではなく、AI の力を借りて柔軟に変更可能になる時代へと突入しつつある。
編集コメント
「書き換えは禁じ手」という開発の鉄則が、AI エージェントという新兵器によって打破された画期的な事例です。ただし、この成功には TypeScript で書かれた堅牢なテストスイートが存在したことが不可欠であり、単に AI に任せるだけでは再現できない条件が含まれています。
Jarred Sumner 氏は、Zig から Rust への Bun の書き換えに関するこのブログ投稿について(5 月 9 日 以来)、実際に書き換えを完了するのにかかった時間よりもはるかに長い期間、約束し続けてきました。
正直に言って、待つ価値がありました。これは、動的ワークフロー、試行実行、敵対的レビューなど、あらゆる興味深いトリックを特徴とする、極めて洗練されたエージェント工学の詳細な記述です。
Jarred は投稿の前半で、Bun をここまで導いた Zig について称賛しています。そして、この記事の中核となるアイデアにたどり着きます(強調は私による):
**
バグ修正リストが重く感じられ、Bun のクラッシュを心配しながら眠ることに疲れ果てました。それを Zig のせいにするつもりはありません。Zig の他のユーザーには私たちと同じようなバグはなく、GC と手動管理メモリを混在させるのは、言語がそのために設計するほど一般的なソフトウェアではないからです。Zig がなければここまで来られなかったでしょうし、私は常に感謝しています。ごく最近まで、Bun のようなプロジェクトにおけるプログラミング言語の選択は、一度きりの決断でした。**
誰もが、大規模なソフトウェアをゼロから書き直すために世界を停止してはいけないことはよく知られています。Joel Spolsky は、2000 年 4 月に 「決してやってはいけないこと(第 1 部)」 でこれを指摘しました!
今日の最先端モデルによって駆動されるコーディングエージェントが、この方程式を変えています。
なぜ Rust を選ぶのか?それはすべて、メモリ管理におけるこれらの課題に帰着します:
そのリストにあるバグの大きな割合は、使用後の解放(use-after-free)、二重解放(double-free)、およびエラーパスでの「解放を忘れる」ものです。安全な Rust では、これらはコンパイラーのエラーとなり、Drop による RAII 的な自動クリーンアップが行われます。
この書き換えを可能にした決定的な要因は、Bun のテストスイートが TypeScript で書かれていたことです。つまり、これは適合性スイートとして機能し得たことを意味します。これにより、エージェント・ハーン(agent harness)を使って、Bun から Rust への初期の移植作業の多くを自動化することが可能になりました。当初は、現在 Mythos/Fable としてアクセスできるモデルの早期バージョンを試す実験として行われました。
最初は、これがうまくいくとは思っていませんでした。数日後にはテストスイートの高い割合がパスし始め、新しい Rust コードが元の Zig コードベースとどれだけ一致しているかを目の当たりにしました。私の意見は「試す価値がある」から「これをマージする」と変わりました。[...]
それら 11 日間のほとんど(およびその後も)私はワークフローを監視し、手動で出力を読み込んで問題やバグがないか確認し、Claude にループを編集させて修正を行いました。
+100 万行が追加された PR をどのようにレビューするのか?LLM が作成した大量のコードを責任を持ってマージするために必要な信頼感をどう築くのか?
100 万件のアサーションを持つ言語非依存のテストスイート、敵対的なコードレビュー、そして何かが間違えた際には、コードを手動で修正するのではなく、コードを生成するプロセス自体を修正することです。
Bun の新実装は、Claude Code でほぼ 1 ヶ月間稼働しています:
Claude Code v2.1.181(6 月 17 日リリース)以降では、Rust 版の Bun が使用されています。Linux 上での起動速度が 10% 向上しましたが、それ以外はほとんど誰も気づきませんでした。地味な改善こそが善です。
Anthropic で働く特典の一つは、トークンに対して支払いをしなくて済むことです。推定コストが 165,000 ドルにもなる場合、これは非常に便利です。
マージ前では、これにはキャッシュされていない入力トークンが 59 億個、出力トークンが 6.9 億個、そしてキャッシュされた入力トークンの読み取りが 720 億回必要でした。API 価格設定によると、これは約 165,000 ドルに相当します。
この一連の取り組みは、調整された並列エージェントの支援のもとで、極めて野心的なプロジェクトに取り組む際の興味深いケーススタディです。
Via Hacker News
Tags: ai, rust, zig, generative-ai, llms, ai-assisted-programming, anthropic, bun, conformance-suites, agentic-engineering, claude-mythos-fable
原文を表示
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. Then we get to a core idea in the piece, emphasis mine:
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. We wouldn't have gotten this far if not for Zig, and I'll always be grateful. Until very recently, programming language choice was a one-way decision for a project like Bun.
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.
Why pick Rust? It all came down to those challenges with memory management:
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.
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.
At first, I didn't expect it to work. A few days in, a high % of the test suite started passing and I saw how much the new Rust code matched up with the original Zig codebase. My opinion went from "this is worth trying" to "I'm going to merge this". [...]
For most of those 11 days (and after), I monitored workflows - manually reading the outputs to check for issues and bugs, and prompting Claude to edit the loop to fix things.
How do you review a PR with +1 million lines added? How do you start to build the confidence needed to responsibly merge large quantities of LLM-authored code?
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.
The new implementation of Bun has been live in Claude Code for nearly a month now:
Claude Code v2.1.181 (released June 17th) and later use the Rust port of Bun. Startup got 10% faster on Linux but otherwise, barely anyone noticed. Boring is good.
A perk of working at Anthropic is that you don't have to pay for your tokens - handy when the estimated cost is $165,000!
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.
This whole thing is a fascinating case study in taking on wildly ambitious projects with the help of coordinated parallel agents.
Via Hacker News
Tags: ai, rust, zig, generative-ai, llms, ai-assisted-programming, anthropic, bun, conformance-suites, agentic-engineering, claude-mythos-fable
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み