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 idea of rewriting a complex, production-grade service in a new language was a luxury reserved for greenfield projects, not a maintenance necessity. The GitHub Copilot runtime, a sophisticated agent system managing hundreds of millions of lines of code and orchestrating real-time AI assistance for developers, was originally built in JavaScript. The decision to migrate this critical infrastructure to Rust was not just a technical exercise; it was a strategic imperative to achieve memory safety and performance without sacrificing the agility of our development cycle. Before the advent of AI agents capable of understanding context and executing multi-step logic, such a massive undertaking would have been prohibitively expensive in terms of time and resources, likely requiring years of dedicated engineering effort.

The irony of using Copilot to rewrite Copilot is a story that defies conventional software history. We faced the daunting task of porting approximately 800,000 lines of production code, a scale that usually demands armies of engineers and months of planning. Instead, we leveraged the very system we were building to assist in its own reconstruction. By feeding the existing JavaScript logic and intended Rust architecture back into the Copilot agent, we created a feedback loop where the AI analyzed the old patterns and generated idiomatic Rust code. This approach transformed a potential decade-long bottleneck into a manageable sprint, allowing our team to focus on verification and integration rather than the brute force of line-by-line translation.

However, the migration was never truly a "set and forget" operation. The initial outputs required significant human oversight. AI-generated code, no matter how intelligent, often produces solutions that are syntactically correct but semantically fragile or inefficient for specific runtime constraints. Our team spent cycles reviewing the generated Rust, tweaking edge cases, and ensuring that the agent's understanding of our internal libraries remained aligned with reality. It was a dance between machine intuition and human precision, where the AI suggested the path forward, but engineers held the steering wheel, ensuring the ship didn't drift into undefined behavior or memory leaks.

The results speak for themselves, but the process offers a deeper lesson for the industry. We are entering an era where the definition of "human-written code" is expanding to include human-AI collaboration as the primary driver of productivity. By automating the heavy lifting of porting, we freed our senior engineers to tackle architectural improvements and solve novel problems that the AI couldn't anticipate. The performance gains in Rust provided by the migration are substantial, reducing latency and memory footprint, but the cultural shift toward trusting AI as a co-pilot in infrastructure maintenance is perhaps even more significant.

This rewrite serves as proof that the tools we build today are becoming the architects of our own evolution. What started as a necessary infrastructure upgrade evolved into a demonstration of how autonomous agents can handle the most tedious and risky parts of software development. As we look toward the future of software engineering, the boundary between developer and machine continues to blur, not in a way that diminishes human skill, but in a way that amplifies our ability to build better, safer, and faster systems. The journey to Rust was just the beginning of a new chapter in how we write, maintain, and evolve the code that powers the 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 →