
The software engine underpinning GitHub Copilot and a growing number of Microsoft products is now written entirely in Rust, with AI agents doing most of the porting work.
The migration cost about $120,000 in AI token usage plus about three weeks of a developer's time. However, managers also had to grapple with a few dozen regressions in the resulting code, pointing to AI’s ongoing challenges in understanding Rust.
The effort updated the runtime module-by-module until the job was completed, spanning over 135 releases across a 14.5-week time period. Roughly 1.3 port pull requests were opened per day.
Overall, agents converted 430,000 lines of TypeScript into 800,000 lines of production Rust. To keep the port as simple as possible, the port only replaced TypeScript modules on a case-by-case basis. It didn’t look to optimize the structure of the runtime itself. That work is next.
And Rust, known for its lean performance, did not disappoint.
One benchmark measured how quickly the runtime could complete 1,000 one-turn session lifecycles, using a shared client and 100 concurrent pipelines. The original TypeScript implementation completed 7.55 of those lifecycles per second, while Rust running in-process managed 120 per second - representing a 15.9x speedup on that particular workload.
In terms of memory, a 10-client batch of agents consumed 1,383 MB with TypeScript while the Rust rewrite consumed only 126 MB serving the same swarm. Within Rust, the work remained in-process instead of spawning external background processes for completion, a requirement for TypeScript.
Copilot from VS Code to Microsoft Office
At first glance, most users may not know how pervasive the Copilot runtime is. It backs the GitHub Copilot command-line interface (CLI), the Copilot app, the SDK and the GitHub Copilot cloud agent. It shows up in VS Code, Visual Studio, Excel, Outlook, PowerPoint, and innumerable other Microsoft cloud services.
Originally, the runtime was written in TypeScript and used Node.js as the framework and V8 for the execution engine. TypeScript and Node were ace for rapid development, but when used at scale, they suffered in terms of providing fast start-up and server density.
“This is in no way a claim that every large TypeScript program should become Rust. Our requirements emphasized embedding through a C ABI, low startup and steady-state overhead, and predictable resource use. Rust made those goals possible,” wrote Microsoft Distinguished Engineer Stephen Toub in a post that explained the entire process.
The project used Copilot to rewrite Copilot, which in turn used several LLMs – GPT-5.6 Sol and Claude Opus 4.8 were both namechecked – to execute different parts of the job, depending on each LLM’s natural strength.
Well-read but chatty agents
Toub assessed the use of agents as largely successful. Indeed, this project would have taken years and cost millions if done by hand.
Agents showed several surprising emergent behaviors, Toub noted. For one, they spent far more time gathering information than actually writing code.
“The popular image of AI spewing code is almost backwards; at this scale, the work looked much more like iterative investigation, inspecting the current state, forming a hypothesis, making a targeted change, rinsing and repeating,” he wrote.
Another surprise was how frequently sessions interacted with other sessions, either those they spawned or other ones entirely.
One of the thorniest conversions was the session.ts file, which was over 30,000 lines of TypeScript that touched all aspects of the runtime. The porting session, which ended up taking 25 hours to complete, began by spending 56 minutes reading the documentation and making 122 tool calls for clarification. It then spawned 15 child sessions, each creating its own worktree and agent. Then, they started communicating with each other.
Using a built-in orchestration skill, one session found every other active session and sent messages to those whose missions overlapped, requesting coordination.
The compiler is a teacher, not an oracle
Given its performance benefits, Rust has proven to be a popular language for rewriting applications. Bun creator Jarred Sumner, for instance, recently ported the Anthropic-owned JavaScript runtime and toolkit, which contained roughly 535,000 lines of Zig code, over to Rust, almost entirely using Claude agents. As of July 30, the experimental Rust port was passing 99.8 percent of Bun's existing tests on Linux x64 glibc, with the stable releases still shipping from the Zig codebase.
That job cost $165,000 in tokens.
But there are hidden dangers in using Rust as well, as Toub has found.
For an LLM and a lazy programmer alike, if the code compiles, then it is valid Rust.
But throughout the process, the project encountered dozens of regressions within the code. A regression is something that used to work, but no longer does after an update.
The compiler has no idea, for instance, whether functions are in the right order, whether the job completes at an acceptable cost, whether it meets the developer's unwritten requirements, or whether it is internally coherent at all, for that matter.
At RustConf, held in Montréal last week, consultant Lisa Crossman warned about the practice of treating the compiler as an “oracle,” or the last word on whether some Rust code is valid or not. “Rust stops the agent writing memory unsafe code; it does not stop the agent writing the wrong program correctly,” she said.
If they’re wise, a human developer treats the compiler as a teacher, decoding the errors as a path to a better understanding of the language’s domain. An LLM, on the other hand, just uses the compiler as a black box, one it can batter with blunt, inefficient workarounds until one passes muster (perhaps this is what Zig creator Andrew Kelley meant when he called Bun’s Rust code “unreviewed slop”).
In Toub’s case, he had found that compiler-approved regressions could come from ambiguous semantics and behaviors, branch drift, missing features that weren’t ported over, and differing behaviors from the replacement code.
“That’s in no way an argument against Rust’s compiler,” Toub wrote. “But ‘if it compiles, it’s correct’ is useful only as a joke.” ®