Skip to content
Linkdrop
Links

I Was Wrong About AI Rewrites in Rust

ForrestKnight discusses GitHub’s AI-assisted migration of the Copilot runtime from TypeScript to Rust, revisiting the claim that Rust’s compiler is the main reason agents work well with the language. The video covers the rewrite’s incremental workflow, compiler feedback, production rollout, and performance results.

videoForrestKnight · 20 min · Nov 12, 2026 · youtube.com · Saved Nov 13, 2026

rust, coding agents, agent-generated pull requests, production deployment

Description

So I was wrong about AI rewrites in Rust...

Check out WorkOS, it's really good: https://jetty.to/workos

GitHub published the most documented Rust rewrite I've ever seen. It is a 65 minute read that has so much good information - it is super well done. It's about how one of their engineers had AI agents port the Copilot runtime from TypeScript to Rust, and he logged everything. From every prompt he used to every compiler error, command the agents ran, every tool call, every token and every dollar, unsafe block, every known regression and bug they shipped, grouped by why it happened. And before and after benchmarks on everything you'd want to know. Absolutely insane. Hope you enjoy!

Sources:
Migrating the GitHub Copilot runtime to Rust, using Copilot (GitHub Blog, Sep 16 2026): https://github.blog/ai-and-ml/migrating-the-github-copilot-runtime-to-rust-using-copilot/
Rewriting Bun in Rust (Bun, Jul 8 2026): https://bun.com/blog/bun-in-rust

A portion of this video is sponsored by WorkOS.

My Newsletter, Dev Notes (coming back soon) 👉 https://www.devnotesdaily.com/

My Socials
🐦 X: https://www.twitter.com/forrestpknight
🐙 GitHub: https://github.com/forrestknight
💼 LinkedIn: https://www.linkedin.com/in/forrestpknight
📸 Instagram: https://www.instagram.com/forrestpknight

Transcript

0:00 So, I was wrong. A while back, I tweeted this. The compiler is a huge reason why AI is so good at rust. Rust C gives the agent a deterministic feedback loop with really good error messages so we can iterate without you until it compiles and all tests pass. And you may have heard me say this before because I also said it in some of my videos. And you may be thinking, well, no, that that actually is true because it has the error messages and go back and forth with the compiler, everything that it catches and do everything without you.

0:27 Yes, but it's not entirely true, especially when listed as the only reason because it's not even the main reason. GitHub published the most documented rust rewrite I've ever seen. It is a 65-minute read with just some of the most valuable information in this space. We're not going to read through all of it. I encourage you to do that on your own, but it's about how one of their engineers used AI agents to port the Copilot runtime from TypeScript to rust. And he logged everything from every prompt he used to every compiler error, command the agents ran, every tool call, every token, every dollar, unsafe blocks, every known regression and bug they shipped grouped by category, and before and after benchmarks on everything you'd ever want to know. And the write-up based on all of that with a lot of that included in it is this right here. And what I've

1:17 done is I've deduced down everything that I feel is applicable for this topic about rust. But in doing so, I removed so much good information that I still want to talk about, but that can be categorized in a whole different video. So, I'm thinking I'm going to make a whole another video using this article but boiling down how he used AI agents to do this because regardless of whether you're rewriting something or just using AI to help you code one way or another, it will help you. But I say I was wrong because out of those compiler errors, the rust-only stuff, the borrowing, the ownership, the lifetimes only made up 1.7% of all of them. And 84% of so the vast majority, were just plain type errors that Java or Go would have caught as well. So the compiler, while very obviously useful, isn't exactly what

2:10 makes Rust special here. So I may have overstated it, but I want to set the record straight with this video. Now don't get me wrong, I do think Rust is one of the, if not the best programming language for AI. Go is a close second. I'm a Java dev, but I mean it it's good, but it's not as good as the other two.

2:27 But I do want to go over the actual reasons why AI is so good at Rust, not just because of the compiler, but also the reasons that really make this type of rewrite possible in the first place and the best practices that were implemented and I mean just everything else that we can learn from this write up in that context. So let's go through it. But first, a word from the day's sponsor, WorkOS and specifically Pipes.

2:50 If you've built an AI agent into your app, your users are going to want that agent to work with their other apps, like their GitHub or their Notion or their Slack. And you see a panel like this where you can easily connect to every single one of your tools, that is WorkOS Pipes. And Pipes has over 300 tools that you can connect to. Now normally without Pipes, every single one of these connections is its own OAuth flow and its own token life cycle. And that's for every app provider you want to offer your users. But with Pipes, you just drop in a widget. When your back end or your agent needs to act as that user, it makes one call to get access token and gets back a valid token. And Pipes handles the expiry, the refresh and the concurrency for all of your tokens, which is important. That way if

3:36 you have an agent running for hours, it won't fail because your token expired. And maybe most importantly, credentials stay encrypted in vault. The agent can only access what the user granted and when a user disconnects, the access stops. If you want to help out your users and include Pipes into your own application, click the link in the top of the description or just go to jetti.2/workos.

3:57 So for context, here's what happened. They rewrote the Copilot runtime, which is the engine that is under the co-pilot app, co-pilot CLI, the SDK, VS code, the Microsoft Office apps, and it was written in TypeScript running on Node. However, that is now changed. Using the GitHub co-pilot app and the co-pilot CLI, we completely rewrote the runtime into more than 800,000 lines of production rust. AI agents wrote most of the code, spanning 128 pull requests that landed in main and shipped incrementally rather than waiting for a single cut over at the end, which I think is a great idea on two fronts at the very least. One, for marketing. I mean, if you say you're completely replacing your runtime like Bundled with a rust rewrite of it, well, it's not good for optics. But in two, it just makes it it doesn't it just make more sense to roll it out

4:52 incrementally so that way you can test each bit of code as it enters the codebase and you can address any sort of breaking changes beforehand, and then you can push that little bit into production for your users to catch the few things that you may have missed instead of a sudden 800,000 lines of rust. I don't know, maybe that's just me, but I'm sure Bun also wanted it for the marketing since they're owned by Anthropic.

5:17 Makes sense that way as well. The few inevitable regressions were discovered and fixed quickly along the way while the performance of the runtime improved by orders of magnitude. A project that would have taken a whole team of developers a year or two before agents was now completed primarily by a single developer in only a few months, all while the rest of the team continued to greatly expand the runtime's capabilities and reach. And this is exactly what I've been talking about in recent videos. I mean, it's kind of what my entire Java 8 video was about. You can finally migrate to modern Java with less people in less time while still maintaining your existing codebase and adding features without putting the rest of your development on hold. And this rewrite in particular took about 14 and 1/2 weeks. Roughly 430,000 lines of TypeScript went in and 832,000 lines of

6:08 rust came out plus another 469,000 lines of rust tests with a small caveat there that there was also incoming rust code separate from the port over the time frame. And you'll notice when looking at this chart here that as the rust lines go up, the amount of TypeScript in the codebase isn't really going down. That's because they were continuing the development in TypeScript while incorporating the rust code along the way until they finally started stripping more and more out to finally in August of 21 there was zero TypeScript in over 800,000 lines of rust. So that's the what, but why did they do it? Well, he laid it out beautifully here. The idea here is that every product that uses Copilot's agent, all the ones that I mentioned earlier, well, anything built on the SDK written in C Sharp or Python or Go didn't really load it. It spun up

7:01 the whole Copilot CLI as a separate process running node in V8 and talking to it over a pipe. That's obviously not ideal with a second language runtime per client about 100 megabytes minimum with every single message needing to run into another process. So they wanted the runtime as one native library any of those languages can load straight into its process with having the outer process server is optional for anything that wants it. So that's the what, the why, the before and after. Now we can talk about the how. And part of it was the loop that I talked about at the beginning of this video. It ran in such a way that the agents would change just a small piece of code, run cargo check, fix whatever the compiler had flagged and keep doing that until there was nothing left to flag. And out of about

7:41 4,500 of those checks, 87% came back clean, which in his own words is what you get from editing in small increments and recompiling constantly. It is a much different approach than the binary, right, or a lot of these other rewrites that we're seeing and even, you know, some that I have encouraged where you [snorts] are very much out of the loop and it's doing large increments at a time. You still want to be able to ensure that you can be out of the loop, and that's where, you know, the compiler and other things that we'll go over here in a second really, really help. But not so much out of the loop that it is just completely unbearable. That is an arguable take. Some people say it doesn't matter for a human to be in the loop anymore. I still think there needs to be to some extent, but the fact that

8:27 it's even being argued, and argued by people that I think are really, really smart and really, really good developers on that, you know, more extreme end, I mean, that's saying something. And one of my favorite little tidbits here that is in the article is, well, first I want to say, what is a really good approach to coding? You read and understand as much as you possibly can regarding whatever problem you're trying to solve, whatever bit of code you're trying to write, and then you write the code. That's what these AI agents did. They did 10 times as much exploration as mutation. So they read and understood and explored the codebase 10 times more than they actually wrote code, which is contrary to how a lot of people picture it. They picture a lot of AI writing way more code than it actually is understanding in the codebase. And I'm

9:18 I'm saying understanding. I have to say this in every single video. AI is not alive. I'm talking about the LLMs here, the computers understanding of the codebase. And also just to reaffirm that I wasn't necessarily crazy in my take. Well, well, maybe it is indicative of me being crazy because he says there's a popular meme that Rust is an unusually good target for AI generated code because Rust's strict compiler catches what the model gets wrong. But here's where the caveat comes in. 8,678 compiler errors, 37% it can't find a name, 22% a missing method or field, 14% the types don't match, 11% a trait bound isn't satisfied, which that makes up the 84% of everything the compiler ever said to the agents being just plain type errors, like I previously said. Tube, which I should have mentioned, Steven Tube is the um author of this and the one who

10:13 performed this rewrite, you know, along with the agents, but he's obviously the one steering it. And I believe he is a distinguished engineer at GitHub. So very, very smart. This is not, you know, your brother who just started using computers trying to rewrite an entire codebase. That did You still need some knowledge here. For all of that 84% he calls it bread and butter static typing. In other words, a Java compiler, C# compiler, a Go compiler all would have caught these.

10:41 And your first to the borrow checker, finding the ownership, the lifetimes, the borrowing, the thing that made up the 1.7% from earlier, a quiet background presence. So it's nice that it caught that, but it's not necessarily what makes Rust a better language than any of those others that are just listed in terms of AI writing it. Now, in terms of performance and things of that nature is not the discussion that we're having right here. What I'm talking about is how AI performs writing code in a specific language with this one being Rust and with my claim of what is the best language for AI being Rust, which I mean, it's arguable. Go is very, very arguable. But what happened to all of the bugs that compiled and then made it through? See, this is the part that I really, really like because it's not just

11:27 the agent writing the code, the compiler checking it, and then, you know, fixing anything that the compiler catches. It's what they put in place after all of that. Because remember, for them to make it through that means they compiled. So obviously the compiler isn't the end all be all of of bugs, although that would be nice, wouldn't it? So if you've heard the whole um if it compiles it's correct line, obviously that's not exactly true.

11:50 So there were some expected, inevitable regressions. But you know what upsets me the most and one of the reasons why I guess I'm wrong here is the biggest group of these bugs would fall into lifecycle, ownership, ordering, and races, which is everything that you want the borrow checker to catch. But the way they got through is that the TypeScript that was left was holding a handle to state that now lived in Rust, which basically all that is is it's a it's a number pointing into a table. And unlike a real reference, that handle can outlive the thing that it's pointing at.

12:25 And the thing that it's pointing at, the compiler can't see that. But edge-to-edge tests do see that. Every single change that was performed here ran against the full suite of tests. And while they caught a lot, one of the things that Tube said was that he should have written more of those tests before he started. And to be clear, he does mean it's something that he wishes he did not have an AI agent do because something that actually happened is one of the agents deleted a test along with the feature it was there to protect. So a rule that was put in place is that the agents aren't allowed to touch these tests. I mean, I guess the logic behind some of these agents is like, well, if I can't get this code to pass the test, I can just delete the test. And would

13:06 you look at that, no more tests are failing. I mean, [laughter] that's not how it That's not how you're supposed to go about things, but I think I mean, it's it's a computer. What do you expect? And both of them, the Bun rewrite as well as this rewrite, they had a second agent review every single change. Whereas the first one saw all of the reasoning behind the code, you had another one not have any of that context for the reasoning behind the code and was just looking at it standalone. And these come in the form of adversarial reviewers where they were told just to assume that all of the code was wrong. That what Bun had. And then what GitHub had was actually review agents on three different models comparing the old TypeScript to the new Rust line by line by line. And both of

13:48 these ports came as a faithful port. And then you can add the improvements afterwards, which is a very wise thing to do, apparently, because Tube says every time he caved and then let them clean things up mid-port, it cost him more regressions, which cost him more time, which cost him more tokens, which cost the company more money. Now when it comes to Microsoft and GitHub, were those, you know, drops in the bucket? Yes, but if we're trying to take this to, you know, a company that doesn't have an endless budget. Well, it's something to keep in mind. But again, none of that is exactly Rust. Uh, so why not rewrite it in Java? Or well, maybe not this in Java or Go or any other language that can also have these end-to-end tests. Well, don't take my word for it because Tube actually answers this. And I I think that's how

14:35 you pronounce his last name. I've been saying it. If that's how you pronounce his last name, awesome last name, by the way. But he said the reason he chose Rust for this had nothing to do with the compiler. He said, I didn't set out to move to Rust. I set out to move away from Node.js and V8 because remember that diagram I showed you earlier, every client is dragging along its own node process. He needed a native library, a single native library that all six SDK languages could load straight into their own process. And to do that with minimal dependencies, which is another trend that I've seen happen a lot in the industry, because you can either use some sort of dependency or you can write your own for your specific use case using AI. In either way you splice it, I mean, you are depending on humans for

15:19 these dependencies that you're using, like for them to look at the code, but you're also not looking at the code for these dependencies or libraries that you're important to your own project. But he wanted them with minimal dependencies and less supply chain risk and Rust fit the bill. But those weren't the only things that were accomplished because remember I mentioned the before and after benchmarks. Before the rewrite, if you were to spin up a client and a session, warm it up and get one reply, it went from 5.25 seconds to 55.3 milliseconds. Memory for 10 clients went from 1,383 megabytes to 126. It removed about 60 npm packages, which again, that's less supply chain risk, especially with all of the hacks and malicious actors and things of that nature going on and basically everything from npm to the AUR for Arch Linux to basically everything that we

16:16 kind of depend on and trust. It a worrying time out there. Now he says other changes landed in the same window as they were before. So take all of these with a bit of a grain of salt. But the real gain here is just not needing to boot a JavaScript engine every single time you want to use the Go pilot runtime. But if we take a look back at Bun, which I have made a video about them before. I've mentioned them in numerous videos.

16:39 The the Bun Zig to Rust rewrite because it was one of the most prominent ones and it is such a contrast on how they went about it to how GitHub went about it while also overlapping in many different regards. But they chose Rust for a completely different reason. Jared opens his post about the entire rewrite, the blog post that took longer than the initial rewrite to write. But he opened it with a bug list from uh a single release that they had which had use after free and double frees and memory leaks. In safe Rust those don't compile.

17:08 And after the port from Zig to Rust, 128 of those bugs were fixed. And I don't know if you remember just how many thousands or over 10,000 unsafe blocks they had. Or it was it was some crazy number that I don't recall off the top of my head, which they were going to continue to address. At least at least half of them they're able to address, whereas the other under half were part of the codebase and were going to be because of the other languages that they used in it. But in the GitHub rewrite there were only 158 unsafe blocks. And every one of them sits where Rust talks to C or the operating system. None in the agent code though and not a single known bug lived in one. So the borrow checker did earn its keep at least a little bit. But there is something to

17:52 really keep in mind and that is Tube is very careful here. His numbers come from a port out of TypeScript, which is garbage collected. So of course the agents are rarely going to trip the borrow checker. Whereas Bun was coming from Zig where memory was their whole problem. Like that's the biggest reason why they went from Zig to Rust for their use case. And unfortunately we don't have quite the same breakdown that Tube gave us. But it did specify something very important because I know people will run with this rewrite and say everything needs to be rewritten in rust. To be fair to myself, every single rewrite type of video or anything like that, I give the caveat this doesn't mean that the rust is in all be all that you need to rewrite everything in rust. And that's exactly what he says. He says this is in no way

18:38 a claim that every large TypeScript program should become rust. So with all of this being said, where I land in terms of the compiler, in terms of rust, the loop of it all is incredibly helpful. Having the agent be able to communicate with the uh compiler without you to go over all of those mundane little things so you don't have to look at them and then specifically prompt the AI to fix all of those type errors or what made up the other 13 to 17% that the compiler caught. It can do that without you, but any typed language is going to give you most of that. What really made these rewrites work were those end-to-end tests that the agents could not touch, which is a very important part. A second agent checking the first agent and translating before improving. And you'd want all of those

19:29 things in place regardless of what language you're porting to, rust or otherwise. And for all of the reasons discussed in this video, rust was the right language for this project. And this write-up here, I mean it's a it it's a better case for rust than any that I've made. So if you do want to see that video that I mentioned at the beginning of this video based on this same write-up, let me know because I think I'm going to make it, but I'm still on the fence about it. And for right now, if you want to learn why so many others are porting and rewriting their code bases from whatever language to rust, well I've made a video on that. Or if you want to hear about some other interesting things, well here's a video right next to here. Hopefully you'll subscribe to the channel because you made it to the

20:12 end of this video and I assume you liked it. I hope you liked it. But as for this one, that's all I've got. Y'all have a good one.