SUGATA AI
GitHub Blog

Migrating the GitHub Copilot runtime to Rust, using Copilot

Migrating the GitHub Copilot runtime to Rust, using Copilot

For years, the decision to rewrite a system in Rust was a theoretical exercise, a fantasy of performance that never quite aligned with the cost of labor. The GitHub Copilot runtime, a complex engine managing 800,000 lines of code, was no exception. Before the rise of AI agents, this migration would have been a logistical nightmare, a project requiring a dedicated army of engineers to parse, translate, and validate every line. The sheer volume of business logic, the intricate dependencies, and the critical nature of the codebase made the risk of failure too high to justify the reward. It was a problem that simply didn't have a solution until the tools caught up with the ambition.

The turning point came when we realized that the very agents we built to generate code could also be the architects of that code. We stopped treating the rewrite as a manual translation task and started framing it as a generation problem. By feeding the existing Python implementation into the same models used to write new features, we turned the rewrite into a conversation. The process wasn't about blind trust; it was about a rigorous loop of generation, critique, and refinement where the agent proposed a Rust equivalent, and the human team validated the semantics, safety constraints, and edge cases. This symbiotic relationship between the tool and the developer fundamentally changed the economics of the rewrite.

What surprised us most wasn't that it worked, but how quickly the momentum built. Once the initial scaffolding was in place, the agents became increasingly proficient at the specific idioms and patterns of our Rust codebase. They learned to handle the specific concurrency models, the memory safety guarantees, and the error handling strategies that made the original Python runtime tick. It was less like hiring a fresh junior developer and more like having an intern who had been reading your code for years, capable of suggesting optimizations you hadn't considered. The feedback loop accelerated, turning a potential multi-year slog into a focused, iterative sprint.

Of course, the path wasn't without its stumbles. There were moments where the generated code was syntactically perfect but semantically wrong, introducing subtle bugs that required deep human intervention to untangle. The agents struggled with the nuance of legacy codebases where the intent was buried under layers of historical decisions. This forced us to develop new workflows, better prompt engineering strategies, and a clearer definition of what "production-ready" meant in the context of an AI-assisted rewrite. We had to build guardrails that were as sophisticated as the code itself.

Ultimately, this migration demonstrates a shift in how we approach software engineering. The barrier to entry for rewriting complex systems is no longer just the cost of labor, but the ability to orchestrate intelligence. By leveraging Copilot to rewrite Copilot, we proved that the tools we create can evolve the very infrastructure that supports them. It is a testament to the potential of AI not just as an accelerator for individual tasks, but as a partner in the grand architecture of software. The result is a faster, safer, and more performant runtime, but the real victory is the validation of a new paradigm where machines help us build the machines that run our world.

🦋 Free for 60 days

On Bluesky? Meet HomeSky.

Follower analytics, a growth toolkit, scheduling and AI posting — built for Bluesky. Connect your account and use everything free for 60 days.

Try HomeSky free →