Migrating the GitHub Copilot runtime to Rust, using Copilot
For decades, the dream of rewriting massive legacy systems in modern languages was often dismissed as a pipe dream reserved for startups with infinite runway and zero constraints. The idea that an engineering team could take a critical, safety-critical agent runtime composed of millions of lines of code and successfully port it to Rust without burning the entire organization to the ground seemed like fiction. Yet, at GitHub, we didn't just attempt it; we executed it while simultaneously using the very tool we were building—Copilot—to write the new code. This paradox, of using an AI agent to rewrite itself, transformed what was once considered a multi-year, multi-million dollar undertaking into a project that was not only affordable but incredibly fast.
The sheer scale of the Copilot agent runtime was the primary adversary. We were looking at roughly 800,000 lines of production code, a body of work that had evolved over many years to handle complex reasoning, tool use, and memory management. In the pre-agent era, refactoring a project of this magnitude would require months of manual code review, architectural debates, and the constant fear of introducing subtle bugs that could cripple the service. The cost of failure was too high for a slow, iterative manual approach. The traditional path demanded a "big bang" rewrite strategy that risked a complete outage or a months-long deployment window, neither of which were viable for a platform that needs to be always on and constantly evolving.
Enter the concept of the self-driving port. By leveraging Copilot, we shifted the paradigm from manual translation to guided evolution. Instead of developers staring at legacy code for hours, trying to mentally map every function and data structure to a Rust equivalent, we provided the AI with the context of the original implementation and asked it to generate the new Rust code. The result was a dramatic acceleration of the workflow. Developers could focus on the high-level architecture and the tricky edge cases, while Copilot handled the bulk of the boilerplate, type conversions, and idiomatic Rust patterns. It was a symbiotic relationship where the human acted as the conductor and the agent served as the virtuoso orchestra.
However, this approach was not without its challenges. The AI doesn't just copy-paste; it interprets intent. There were moments where the generated code required significant human intervention to align with our specific safety protocols or to optimize for performance in a way the model hadn't initially considered. The process became a rigorous cycle of generation, review, and refinement. We found that the more context we fed into the agent, the fewer rewrites were needed, turning the port into an iterative conversation rather than a linear task. This dynamic reduced the cognitive load on the team, allowing us to tackle problems that would have been overwhelming under the old model.
The outcome of this migration is a system that is not only faster to develop but also more robust and maintainable. Rust's ownership model has forced us to address memory safety issues that had been latent in the previous language for years, resulting in a codebase that is fundamentally cleaner. The speed at which we achieved this port has allowed us to pivot quickly to new features and improvements, something that would have taken years in the past. We proved that with the right tools and a shift in mindset, the barrier to entry for large-scale modernization vanishes.
Ultimately, this story is less about the technical brilliance of Rust and more about the evolution of how we build software. It represents a fundamental shift from heroics to automation, where the most complex tasks are broken down into manageable pieces and solved by intelligent collaboration. We didn't just rewrite the Copilot runtime; we rewrote the rules of large-scale software engineering, proving that the future of development is a partnership between human ingenuity and machine efficiency.
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 →