← Back to Reading
ByteByteGo 2026-11-10

How GitHub Used AI to Port Copilot From TypeScript to Rust in Record Time

GitHub originally implemented the shared Copilot runtime in TypeScript running on Node and V8, which required client applications in other languages to manage an external background process. This architecture introduced inter-process communication latency, stability risks, and an unavoidable baseline memory footprint of roughly 100 MB per client. To satisfy stricter performance, memory, and scalability needs, GitHub decided to port the runtime into a standalone library that applications could load directly into their own process. Rust was selected for its minimal resource overhead and predictability, leading to a migration that ultimately encompassed 430,000 lines of production TypeScript code. GitHub adopted an incremental, in-place porting strategy to migrate its runtime from TypeScript to Rust while product development remained active. Instead of undertaking a high-risk complete rewrite, the engineering team swapped individual components in isolated pull requests, deleting the old TypeScript implementation immediately to avoid maintaining duplicate versions. Temporary thin wrappers were used as bridges to connect remaining TypeScript code to new Rust components. The team prioritized behavioral parity and validated functionality through comprehensive end-to-end tests before rolling changes out via pre-releases. GitHub began its porting process with small, manageable examples to evaluate Rust integration before tackling larger components. Initial pull requests established core Rust tooling, automated checks, runtime libraries, and TypeScript-Rust interoperability. The porting sequence was organized strictly by dependency, transitioning from small helper utilities to state management, tools, and model clients. Complex subsystems such as session orchestration were deliberately reserved for the final stages due to their iterative nature.

Read the original ↗
Contents 8 sections
  1. 01The Need for Porting the Copilot Runtime
  2. 02The Porting Strategy
  3. 03How the Porting Work Started
  4. 04The Role of Agent Fleets
  5. 05How the New Code was Reviewed
  6. 06What Were the Issues
  7. 07The Performance Impact of Porting
  8. 08Cost of Porting and Learnings

The Need for Porting the Copilot Runtime

GitHub originally implemented the shared Copilot runtime in TypeScript running on Node and V8, which required client applications in other languages to manage an external background process. This architecture introduced inter-process communication latency, stability risks, and an unavoidable baseline memory footprint of roughly 100 MB per client. To satisfy stricter performance, memory, and scalability needs, GitHub decided to port the runtime into a standalone library that applications could load directly into their own process. Rust was selected for its minimal resource overhead and predictability, leading to a migration that ultimately encompassed 430,000 lines of production TypeScript code.

  • The Copilot runtime serves as GitHub's shared software engine handling AI agent behavior across various products.
  • The initial TypeScript runtime executed via Node and V8, forcing clients to spawn a separate background process that incurred at least 100 MB of memory overhead each.
  • Running the runtime as an external background process added inter-process communication latency and complicated crash-handling across consumer applications.
  • GitHub decided to rebuild the runtime as an in-process library separate from user interface logic, choosing Rust for low overhead and predictable resource usage.
  • While initial estimates anticipated porting 130K lines of TypeScript, the migration ultimately handled 430K lines due to expanded scope and ongoing feature development.

The Porting Strategy

GitHub adopted an incremental, in-place porting strategy to migrate its runtime from TypeScript to Rust while product development remained active. Instead of undertaking a high-risk complete rewrite, the engineering team swapped individual components in isolated pull requests, deleting the old TypeScript implementation immediately to avoid maintaining duplicate versions. Temporary thin wrappers were used as bridges to connect remaining TypeScript code to new Rust components. The team prioritized behavioral parity and validated functionality through comprehensive end-to-end tests before rolling changes out via pre-releases.

  • GitHub avoided a high-risk 'big bang' rewrite by migrating from TypeScript to Rust incrementally during active feature development.
  • Each component was rewritten and replaced in a single pull request, immediately deleting the legacy TypeScript code to maintain only one active version.
  • Temporary thin wrappers served as bridges allowing existing TypeScript callers to interface with ported Rust components until those callers were also rewritten.
  • The migration began with small, independent helpers that had strong test suites and lacked shared state to establish packaging and cross-language communication.
  • Behavioral parity took precedence over architecture changes, postponing major redesigns until after migration and validating workflows via end-to-end tests.

How the Porting Work Started

GitHub began its porting process with small, manageable examples to evaluate Rust integration before tackling larger components. Initial pull requests established core Rust tooling, automated checks, runtime libraries, and TypeScript-Rust interoperability. The porting sequence was organized strictly by dependency, transitioning from small helper utilities to state management, tools, and model clients. Complex subsystems such as session orchestration were deliberately reserved for the final stages due to their iterative nature.

  • GitHub started its porting effort by establishing foundational Rust infrastructure, automated checks, and TypeScript interop mechanisms.
  • The first functional port migrated three independent helper functions through the entire build, packaging, and integration pipeline.
  • Migration tasks were ordered by dependency, moving from utilities to state management, tools, and model clients.
  • Session orchestration was left for the end because larger runtime subsystems required multiple rounds of work.

The Role of Agent Fleets

Agent fleets coordinate complex code migration tasks by allowing a primary coordinating agent to analyze large codebases and delegate subtasks across specialized child agents and sessions. While subagents investigate code within the parent workspace, child sessions work on independent Git branches to modify code safely without collision. In practice, coordinating 15 simultaneous sessions during a large-scale migration to Rust overwhelmed local hardware during concurrent builds, necessitating serialized build queues managed by a dedicated session. Beyond code generation, the agent fleet focused heavily on dependency analysis, comprehension, and test verification under continuous human supervision.

  • Coordinating agents can analyze large components and divide tasks among subagents and independent child sessions.
  • Subagents operate within the parent workspace for investigations, whereas child sessions use isolated Git branches to implement independent changes.
  • In an example involving a 30,000-line file, a coordinating agent analyzed the code and distributed work across 15 child sessions.
  • Simultaneous builds and tests across 15 sessions overwhelmed local hardware, requiring builds to be serialized and offloaded from child agents.
  • Agent fleet responsibilities extended beyond writing Rust code to reading code, checking dependencies, and validating system behavior with human oversight.

How the New Code was Reviewed

The engineering team established an automated review process called 'rust-rebase-review' to keep ported Rust code synchronized with concurrent TypeScript updates on the main branch. A coordinating agent and multiple review agents powered by different AI models performed line-by-line behavioral and compatibility checks against the original TypeScript while ensuring end-to-end tests remained unchanged. The process ran in an iterative cycle where agents detected and resolved issues until reviews came back clean. Additional tooling, including Copilot Code Review, provided commit feedback while human reviewers focused on high-level architecture, contracts, and flagged risks.

  • A reusable instruction named 'rust-rebase-review' was used to synchronize ongoing repository changes with the port.
  • Deleting original TypeScript files served to intentionally trigger merge conflicts when other developers modified those files.
  • Review agents powered by multiple AI models conducted line-by-line comparisons to check behavior, performance, and compatibility between TypeScript and Rust.
  • End-to-end tests were intentionally kept unmodified to serve as the ground truth for expected system behavior.
  • Coordinating agents corrected identified issues across repeated cycles until all automated checks and reviews passed.
  • Human reviewers concentrated primarily on architecture, interface contracts, and highlighted risk factors.

What Were the Issues

A software rewrite and porting project introduced subtle functional regressions that broke compatibility with existing systems despite successful code compilation. Problems included unexpected data-type conversions, discrepancies in string and time-zone handling, and mismatched error handling from replacement libraries. Teams also faced state management defects, incomplete feature migrations, and concurrency problems. Additionally, performance and integration challenges surfaced when Rust tasks blocked Node's main thread, alongside platform-specific glitches on Windows.

  • Translated code introduced subtle behavioral regressions, such as changing whole numbers to decimals, which broke downstream SDKs.
  • Code compiled cleanly but failed at runtime due to mismatched error handling, time zone inconsistencies, and empty string behaviors.
  • State management issues caused incomplete cancellations of operations and stuck sessions due to prematurely released resources.
  • Some features were not fully migrated or were lost entirely during the porting effort.
  • Rust tasks running directly on Node's main thread caused performance bottlenecks and interface freezes.
  • Missing process-launch configuration settings on Windows resulted in unwanted console windows appearing.

The Performance Impact of Porting

Porting GitHub Copilot's agent runtime to Rust substantially reduced overhead, latency, and memory consumption. By embedding the Rust runtime directly into the host process, the team eliminated the need to initialize Node, V8, and related JavaScript tooling, while also avoiding inter-process communication costs. Testing revealed an 18-fold speedup in single-turn client lifecycles, a significant throughput increase from 7.55 to 120 session lifecycles per second, and a reduction in peak memory usage from 1383 MB to 126 MB in a 10-client workload. Because the rewrite preserved original algorithms, future redesigns tailored to Rust's memory ownership and concurrency model may yield further performance improvements.

  • Rewriting Copilot's agent runtime in Rust eliminated the initialization overhead of Node, V8, and the JavaScript application.
  • The Rust runtime can be loaded directly into an application's process, avoiding inter-process communication costs.
  • A single client turn and cleanup dropped from 5.25 seconds to 292 milliseconds, representing an almost 18x speed improvement.
  • Multi-session throughput increased from 7.55 to 120 completed session lifecycles per second.
  • Peak private memory usage in a 10-client test fell from 1383 MB to 126 MB.
  • The port preserved the original algorithms, leaving room for further optimization via Rust's native concurrency and ownership models.

Cost of Porting and Learnings

Porting the GitHub Copilot runtime cost approximately $120,000 across 136 billion AI tokens, with prompt caching playing a critical role in mitigating repetitive context expenses. In addition to token usage, developer effort was necessary for tasks such as packaging, reviews, and integration. Key takeaways from the migration emphasize providing explicit instructions to AI agents, protecting robust end-to-end tests from being weakened by agents, and prioritizing direct translation over redesigns to control costs and prevent regressions.

  • The migration required roughly 136 billion tokens and cost about $120,000, heavily subsidized by input caching for repeated context.
  • Beyond AI token costs, developer time was needed for integrations, packaging, build improvements, and peer reviews.
  • Initial AI prompts led agents to port only core logic while leaving surrounding code in TypeScript, demanding clearer instructions.
  • Robust end-to-end tests with oversight are essential to avoid regressions and prevent AI agents from weakening tests or altering expected results.
  • Migrations should prioritize translating existing behavior directly rather than coupling the port with architectural redesigns.