AI 写代码比合并更快,Uber 如何改造合并队列
原题AI Writes Code Faster Than Uber Can Merge It - Preetam Dwivedi & Manjari Akella, Uber
推荐理由Uber 用准入控制、依赖分析和主干验证缓解 AI 编程引发的合并拥堵,帮助工程团队把提速从写代码延伸到交付。
看前速览
AI 生成的变更推高了合并压力,Uber 通过减少合并前的串行验证、增加合并后的检查,把等待时间降了下来。
在队列入口调节负载
高峰期限制高成本变更,暂存到延期队列,等容量允许时自动放行。
有选择地放宽较弱的冲突
为目标重叠及新增依赖评分,较强冲突继续串行,变更入队时的安排可以复用。
合并后验证整体主干
Stovepipe 检查新提交的组合。通过前保留最后一个已验证提交,失败时通知值班工程师。
完整摘要
合并请求从每小时约 90 次增到 130 次时,Uber 的 P95 合并时间从 30 分钟拉长到三四小时。团队先用准入限制和延期队列调节负载,再按依赖重叠程度放宽较弱的冲突,让更多变更并行。Stovepipe 在合并后检查主干,验证通过才移动指向最后一个可用提交的引用。团队报告,峰值吞吐量达到每小时约 300 次,P95 回到 30 分钟。
章节
文字稿
Brief Description
Preetam Dwivedi and Manjari Akella describe how Uber adapted SubmitQueue as AI-generated changes increased merge traffic. They explain the trade-offs of admission gating, deferrals, and conflict relaxation, and show how Stovepipe verifies trunk after merges.
Table of Contents
- Content
- What changed when AI increased merge traffic
- Admission gating and the cost of rejection
- Deferring expensive changes
- Relaxing weak conflicts
- Verifying trunk after merges
Content
Preetam Dwivedi: Hello everyone. We are here to present our talk merging at AI scale. This is Uber's journey from an always-green trunk to one that can temporarily break. I'm Preetam Dwivedi. I'm a staff engineer at Uber working in developer platform.
Manjari Akella: Hi, I'm Manjari Akella. I'm a senior engineer working alongside Preetam. I work on Uber’s Developer Platform team.
Preetam Dwivedi: Great. So here's the outline for the talk. We're going to go over like how the merging works at Uber at the moment and then how AI changed the landscape and then I'll respond to that how we adapted and then discuss the results and talk about what are we planning next. So at Uber we have a six language-based monorepos where more than 5,000 developers are contributing over 36,000 commits 27,000 PRs every week and pretty much every changes to the services libraries are being done in one of these monorepos. For the purpose of this talk we're going to focus mostly on go code when we talk about anything because that is our the biggest one and that's where where we face most of our scaling challenges. So let's understand the problem a little bit and understand like why we need a merge queue here.
So given here basically we have two users user A and B creating PR A and B on a base HEAD from the trunk and when the PRs are created and CI is run the CI is green builds are passing everything is good. Now when a is merged into the trunk, we can see the builds for the merge commit are still green. Bills are still passing. But when the PR B is merged into the trunk, builds are no longer green. And the reason is that B was never tested with the changes that were merged by A. So we never tested the combination of those two things before merging and hence the when B is merged it's broken. Now imagine when we have thousands of engineers working in a monorepo and everyone is making changes like hundreds and thousands of those every day. This is a constant problem where trunk is broken very frequently and there is a burden on fixing and there is a toll across the company to sort of figure it out and fix it.
So here we're going to present a solution to that problem and that solution is SubmitQueue. That is our Uber's merge queue that we deploy to solve this problem. And in this case we can see our two examples here PR A and PR B. And here we essentially what we are doing is we are predicting the futures that would be u that could be true on main. So there are like three things here. A could land on main on its own, B could land on its own, or A and B could land together. In general I think what we want to do is that we want to land the change that is going to keep the trunk green as a whole. So in this case when we land A and B together the trunk is green and that's how basically sort of SubmitQueue works and keeps the trunk green for our monorepos.
Now how does it scale in this version of it? There are three things that SubmitQueue employs. The very first thing is target analysis. What it means is when two users are working across two different services they don't really have any overlapping changes. So those two things can be built and tested independently of each other and then can be merged. So this allows us to basically get higher throughput and not serialize every change that is entering into the queue. Second is probabilistic speculation. What it means is we are using historical the build information and also the change characteristics to predict what is the success score for a given change and then we are using that to basically decide what all builds are likely needed in order to land that change.
And so in that case we prioritize the build that are most likely needed and are important for that change to be merged to the trunk rather than like every other build that comes from the speculation. The third part is bypassing the large changes. What it means is that if we have a large change sitting in the queue which is taking longer to build and at the same time if we have a smaller changes entering into the queue those can be built faster and so though those changes don't need to wait for large changes to land before they can land. So in this case we can land the smaller changes without landing the larger changes first and this optimization allows us to basically move fast and get a higher throughput of the queue. So this is what has worked when it was just humans landing changes creating PRs but then we had AI and the rate at which PRs were created and landed changed.
What changed when AI increased merge traffic
So to understand it better let's look at some of the numbers. So in January 2026 we were doing roughly 90 requests every hour and by March we were doing 130 requests every hour. So that's roughly a 44% increase in two months and the reason for this increase is primarily because of the AI generated changes. Now given the way the system was built it had the rate of these changes had effect on it. So looking into those like we had 30 minutes of P95 landing times when we were doing 90 requests every hour and that went to roughly 3 to four hours when we were doing 130 requests every hour. So in this case we were still keeping the trunk green at all times but at the cost of developers essentially waiting for 3 to four hours to land their changes to the trunk. Now I'm going to hand over to Manjari and she's going to talk about our response to it and how we adapted to the situation.
Admission gating and the cost of rejection
Manjari Akella: Great. Thanks, Preetam. So, Preetam just walked us through a few optimizations that SubmitQueue had that worked so far in keeping up with the demand that humans generated. But once AI came into the picture, the optimizations we had were no longer sufficient. Our response essentially was another set of optimizations to our existing SubmitQueue and we approached the response in three different ways. The first was we introduced this concept of admission gating which helped us to shape the traffic that we accept into the queue. Next we introduced the concept of deferrals which is a secondary queue that we introduced that helps with developer experience from the pain that comes with admission gating. And lastly, we implemented what we call conflict relaxation which helps us buy back more parallelism within the queue itself.
Next we will look at each of these interventions in a little bit of depth and understand exactly what each of them are doing. So the first one admission gating is basically what it sounds like. There is a gate at the admission of every request into the main SubmitQueue. We look at the request that comes in and we categorize it as one of two things. Either it's a small change or it's an expensive change. And the definition of this could be anything. One of the definitions that we use is the target analysis that Preetam talked about earlier in the slides. A small change touches fewer targets. An expensive change might be something that spans across multiple targets, the entire build graph, something like that. So a smaller change is more likely to give you higher parallelism and we basically say admit it during peak hours and add it to the active SubmitQueue build and test as usual and move along.
But an expensive change has the capability to basically be a bottleneck by holding resources needing to validate against everything else that's in the queue. So to protect the rest of the queue, what we do in this phase is just to reject any expensive change during peak hours. What this means is that the developer has to come back and retry their expensive change outside peak hours. So this gives us control into what enters the queue by moving the burden onto a subset of developers and changes. Let's look at the trade-off of admission gating. After we implemented this, we definitely observed an increase in our throughput. We were able to achieve over 20% increase. Our land rate went from 130 to about 160 during business hours. But it came at a cost and the cost is that developers become the schedulers.
Not all developers since we do protect the smaller changes. But you can imagine if you are a developer who owns any types of libraries that span the entire code, you will be particularly targeted in this because the work that you do naturally falls into this expensive change bucket. So we managed to protect the capacity during peak hours but had to make developers wait. Next slide. So the next thing that we do is targeted more towards bettering the developer experience of the cons that come from admission gating. What if instead of outright rejecting expensive changes, we are able to record them and replay them back into the main queue based on the status of the queue when we have let's say a better handle on capacity. And that's exactly what deferrals implement.
Deferring expensive changes
During peak hours, if an expensive request comes in, we no longer reject it, but put it into a deferred queue where it is persisted. And once the gates permit, usually upon for example, we can say after peak hours we put this persisted request back onto the active SubmitQueue. So essentially we shape the traffic in a way where we release more expensive changes when the queue is able to handle it. So what this solves is a developer submits once and then we automatically release it for them when the capacity allows. Next slide. So the trade-off here is it solves the problem for the developer. They don't have to wake up early, stay up late, try to find a particular window where the queue looks good and hit the button on their end. We will handle that for them. But the other side of this, the bad that comes with this with this is that it doesn't really solve the waiting for the developer.
You still have to wait the same amount of time for your expensive change to go in to the queue. Next slide.
Relaxing weak conflicts
So before we look at the next and final optimization that we did I want to touch a little bit about the on the concept of what a target overlap is and how that serializes work in something. So recall that Preetam mentioned the target analysis that we perform to determine whether two requests should be serialized or can they go in parallel. So an example that we are looking at here is a strict one connected component. What this means is that each of these requests A through F touch some subset of targets and all of there's at least one overlap of targets between each neighboring pair in the example. So like A and B overlap on at least one target, B and C overlap at least one target.
Similarly for C, D, E, and F. And what this makes SubmitQueue do is group all of these requests into a single component. And that means that all of these have to go together. And this is basically what prevents us from doing work faster. And the next optimization we do is how do we break this? Is there a way where we can break this up in a smart way? Next slide. So conflict relaxation is what helps us break these links in an informed fashion. Before is basically the status quo. Any relevant overlap between two requests makes them conflict with each other and makes them serialize one behind the other. But with relaxation we essentially do three steps. First we rank the overlap. So it's no longer a binary decision of is there at least one overlap between these two requests.
Think of it more as a how strong is this overlap. Once we have that we keep the stronger links and relax the weaker ones to buy back parallelism based on a config value that we set. Next slide. So the first step is essentially scoring these edges or these overlaps. We use a Jaccard scoring for computing this dependency overlap. We basically have overlapping targets. We check for that and any new dependency edges that are introduced. We compute a combination of these two into a continuous valued score between zero and one where a higher value of score indicates a stronger overlap and a lower value of the score indicates a weaker edge with fewer targets that overlap between requests. Next slide. Once we are armed with this knowledge, we basically make this conflict graph again.
Right? So taking the same example and adding some numbers to the conflicts that we have from the earlier slide. Let's say we have these six changes and the config value we set says we want at least 50% parallelism in the queue at all times. What this means is that we need at least three separate queues that are working independent of each other and based on the u overlap scores that we have computed we are able to make this choice of dropping certain edges in order to be able to achieve that target Q size that we have. So in this case the weakest edges are between B and C and B and E and we drop those two which gives us three separate connected components. And this is how we essentially go from a serial chain of six requests to a parallelized chain where two each exist in three separate queues.
Next slide. So next comes a question of where exactly do we make this determination of dropping the edges right so there are two places where we can do this one is at a global level every time we are trying to assign conflict graphs and building them we can basically recompute this every time and what that does is it introduces some level of instability into the graph which is determined by any new requests that enter the queue, any work that finishes and exits the queue. So essentially what we can do that but what we chose to do instead was a more local assignment of overlaps and the place that we choose to do this at is only at the new arrival checkpoint. So once a new request comes in, we essentially take that and compute the edges of this with everything that exists in the queue, make the decisions and that's how it stays.
The next decision making will only happen when another new arrival comes in. So the concept is simple. We assign once at entry time and basically reuse this. What this helps us do is any work that we schedule based on previous conflict graphs that we have created is preserved and it helps us hang on to speculative builds that can help us move faster towards a finalization of request. Next slide. So the tradeoff of this final intervention was the biggest that we saw. We saw over 50% increase in the throughput. So we went from about 160 merges per hour to almost 250 sometimes even greater during peak hours. So it worked in that it not only helped us significantly improve our throughputs while giving us extremely good P95 land times but it came at a cost as everything does and the trade-off that we have given away here is basically what Preetam alluded to in the very first slide talking about the integration testing some combinations of changes will land untested because we are dropping edges from our conflict graph.
What this means is main can now be broken. And this creates essentially a new obligation where we have to validate what lands after it has landed. And to talk a little bit more about how we do this, I will hand it back to Preetam.
Verifying trunk after merges
Preetam Dwivedi: Great. Thanks, Manjari for walking us through the those three sort of the solutions that we employed. So taking back this example that we had initially we had basically two changes here A and B and say we do a premerge validation independently after relaxing those conflict between those two things and then say we land it. So now our the landed state is essentially a lands first then b and now the combination of a plus b fails on the trunk. Right? So this is where we started at the start of this talk and so now we have a broken trunk again. So now how are we dealing with this? So we have a system here called Stovepipe and Stovepipe is our like post land validation system. It's responsible for validating any commit that lands on to the main and then making sure that it detects basically if builds are broken and if so then it creates a recovery strategy for that.
Now here we have basically two things. One is every change that is being landed by SubmitQueue lands onto the main trunk and then we have the second reference here or the trunk the pointer if you call is the verified main and the verified main is essentially the one that is being managed by Stovepipe. So let's take an example to understand it better. So imagine we have this commit A u where main and verified main both are pointing to it. This is a known-good commit. This is a building this is green on the trunk. Now let's say we have another set of commit that land onto the main say B C and D. Now main moves to point to the D commit. So at this point a Stovepipe is going to take this range of commits essentially B, C and D on top of A and validate this newly landed changes to see if this new state is still buildable and is still passing or not.
In this case we can see it fails. And so now Stovepipe is not going to move the verified main pointer in this case. It will just keep it at a because that's what the last known-good commit is on the trunk. Now over time more commits land onto the trunk and main moves to commit G. So now between the new state that we have G and the previously known-good state which is A we have more commits in between. So we have B C D E F and G commits in between. So now Stovepipe is going to take those commit range and basically validate and see if those are buildable and if builds are passing. So now say in this case builds are passing and so the Stovepipe will basically take the verified main pointer and point it to the newly validated known-good commit g in this case. So that's what a Stovepipe does is it is essentially observing the newly landed commits onto the main verifying if they can build or not and if they pass move the pointer if not then continuously look for more changes and keep validating.
So now let's look at like when a commit landed on main breaks the trunk. So what happens in that case as I said earlier Stovepipe is essentially validating and then detecting that it failed and on failure it basically alerts. So on call gets paged and as a response to this broken trunk on call is responsible to prepare a fix or revert that change remove it and land the fix through SubmitQueue and then eventually it merges back into the trunk and then a Stovepipe continuously validates the new state to see if it has been fixed or not and then accordingly move the pointer to the newly landed commit. So with all of this I want to just recap on basically what we have achieved. So at peak times we are able to do roughly 300 lands per hour. We are still able to maintain our P95 land time to 30 minutes and this is essentially a 233% increase since the January numbers that we had which were like 90 merges per hour.
We’re doing this work in the open. we have SubmitQueue and Stovepipe being developed and everything is in the open source. So if you want to explore and contribute do scan the QR code explore the project and feel free to contribute to the project. What are we doing next? And as we have already done this work we are still looking ways to make it better optimize for throughput handle the recovery process in better way and also like improve on our like how we how we sort of identify what is green. So as a first thing we are thinking about is on SubmitQueue side basically batching related changes together so that way we run less number of builds and we can do more work with the same amount of resources. Second is today we have a single pointer verified main which points whether a repository head is green or not or a given commit is green or not.
We want to do better where basically we can say a given service or project is green. So even if a commit on the trunk is broken, we can essentially tell which part of the trunk is broken and not all of it. So that would allow us to basically do a better sort of rollouts of those services and changes and we don't have to block everything. And the third one is basically as I said the recovery process from a broken trunk is manual. So the most of the investment is around automating the fixes or reverting the fixes and then landing those to SubmitQueue in automated way so that our time to recovery can be reduced and we can fix the broken trunks faster. And so as a closing point I want to call out that we chose a hybrid approach to validating the changes.
One we are still doing the premerge validations. We are still making sure that we test the changes where it matters and relax the changes where we can take that hit and validate them later after they land to the trunk and then we are running the whole exhaustive validation with the help of a Stovepipe post landing to the trunk and that allows us to basically have this balance where we are validating whatever matters before and then validating everything at the end to make sure it is still good. And our consumers can use the verified-good state and with that would be our end of the talk. If you want to learn more about SubmitQueue and inner workings of it, feel free to scan these QR codes. These are the previously talks that we have done on SubmitQueue in depth and they go over like in detail on how it functions internally and again thank you.
Manjari Akella: Thank you.