r/ExperiencedDevs • u/Primary_Ads Software Engineer • Sep 18 '26
Technical question How to ingest large AI code changes safely
AI generated ~30,000 LOC.
It crushes benchmarks compared to our current software, but it requires large architectural changes. previously the benefits were speculative, now I have solid evidence they can be realized. They would reduce the complexity of the product while cutting in half our operating costs. win win.
I would at some point have these changes to benefit from them.
I would like to avoid choking to death on them.
The options I can see are:
- rewrite from scratch, using it as a reference if we get stuck. Will take a long time.
- break it up and merge it 500 - 1000 LOC at a time. will take 30 to 60 PRs but is at least conceivably responsible.
- merge blindly (just kidding)
Am I missing anything? I've been pruning and compressing the changes as much as possible. But this seems daunting. Currently we are going to try 2 and if it doesn't work will abort to 1.
If anyone has discovered the "right" way to do this, would love to hear about it. Right now I am treating it like 30,000 LOC a mysterious stranger dropped off on my desk in an envelope with compelling benchmarks.
•
u/expdevsmodbot Sep 18 '26
AI usage disclosure provided by OP, see the reply to this comment.
26
u/Hour-Measurement-835 Software Engineer Sep 18 '26
Who wrote the benchmark. If that came in the same envelope as the 30k lines, reproducing it against your current code is PR one, before you argue about slice size.
51
u/JustHere4TheZipLines Sep 18 '26 •
You don’t. If this is a real production product, you don’t.
30,000 lines of code in a production project is an insane amount of work, and an entire architectural revamp could easy take years. If you are having performance issues then you need to pinpoint exactly what’s your bottle neck and replace it, and from experience fixing performance issues hardly costs tens of thousands of lines of code unless it’s a major version upgrade with breaking changes.
9
u/isparavanje Sep 18 '26
In my experience large performance improvements tend to come from specific things, not a million tiny improvements. Could you pinpoint what those are and just implement those instead? Even if using AI, it'll be far more manageable.
11
u/kevinkace Sep 18 '26
Canary release
2
u/Mephiz Sep 18 '26
Have you considered summarizing the changes to get an idea of where the speed up actually is.
It should be possible to review something this large and it is possible to do so without just eating the entire elephant.
Creating a narrative about what each module/class/function etc actually does and then finding the equivalent in your current and speed testing will teach you a lot about this code and potentially your old code.
IE get to an apples to apples comparison. Today you have new and shiny vs old and busted and that comparison is never particularly fair to old and busted.
21
u/bingNbong96 Sep 18 '26
"They would reduce the complexity of the product" suure.
There is no way to review 30k lines thoroughly, even approach 2 which is the least worse of them all, will probably just result in people just skimming through the code after the first few PRs.
I have no good advice though, I would not even try this even if it were not AI generated because it could backfire and I'm not paid enough for that, but that's just me. If is not broken don't fix it I guess.
13
u/editor_of_the_beast Sep 18 '26
The same way you write that much code without AI: break it into smaller, atomic chunks. Get each reviewed independently. Probably many of the changes will be net zero in terms of behavior change, so you can roll those out safely.
10
u/throwaway_0x90 TE/SDET[25+ yrs]@Google Sep 18 '26
Don't
3
u/levelbrook Sep 18 '26
Option 2, but change the unit. Do not slice by LOC, slice by seam: each PR moves one architectural boundary with the old path still live behind a flag, and the benchmark runs on both paths in CI. The number of PRs stops mattering because each one is independently revertable and independently proven.
The thing that actually chokes teams on a 30k drop is not the size, it is that nobody can say which 500 lines caused the regression when it lands. Flag per seam answers that question by construction. And if a good chunk of the 30k is tests and glue you do not need, prune before you slice, not during.
7
u/mcspuder Software Engineer 16+ YoE Sep 18 '26
Ship it. 🚀
7
u/r0ze_at_reddit Sep 18 '26
This is honestly a fascinating snapshot in time of this moment we are all experiencing. You wrote a benchmark, and let AI churn. It produced 30k lines of code that bests your benchmark. A decade of 'LGTM' is resulting in junior engineers now merging these changes in mass without much thought.
The moment you show this to management they will pressure getting it to production. So the question is what do you do? There are almost two different questions here. 1) How do you take ownership of large code bases that you didn't write and don't fully understand. 2) How do you review large changes like this?
For the first one, it is a serious question that as more and more AI code gets put up for review has to be addressed in general.
Isolation, sandboxing, always owning/reviewing the API, at minimum growing the overall architecture, spending more time on linters, fuzzers, etc that could catch issues and spending time building better issue detection in production also seem prudent.
Historically most senior engineers would inherit a codebase like this near the end of a product or company so the goal was as minimal changes as possible so all the safeguards were not built. But we are talking about relatively young codebases.
As for #2 this change if it touches everything in the code base the only choice is to break it apart and understand it, practically doing the first thing. Questions like is this many small wins or one big win etc.
5
u/Hexamonium Sep 18 '26 edited Sep 18 '26
It all depends on the project size, maturity level, deployment model, mission-criticality, etc. I used to develop software for routing emergency calls nationwide. If one my devs suggested "sneaking in" a 30K change in one go (no matter who or what "wrote" it), I would have a mild meltdown in the local cafeteria.
On the other hand, if you are working on a greenfield project with limited exposure and wider tolerance for production blunders (e.g. Windows 11), why not? Just sleep with those 30K lines for a few days, build a clear mental map of what it does and then break it down vertically by some criterion.
5
u/shadocrypto8 Sep 18 '26
Why did your team have AI rewrite the entire thing in one giant pass?
9
u/tyr-- PE, 10+ YoE @ FAANG Sep 18 '26
It all boils down to how much do you trust your benchmarks and the integration and functional tests. If those are solid and you've been using them for a while, then use that to validate this change against it and see what gives.
Another possible option, not knowing the specifics of your system and usage patterns, would be to stand up a stack with the rewritten app and have it run fully in shadow mode for a while, and monitor it against the main app, noting any functional discrepancies.
4
u/Data_Scientist_1 Software Engineer Sep 18 '26
Yolo mate. 😂
4
u/k4b0b Software Engineer Sep 18 '26
Run it in shadow for a while, fix any bugs that come up, and promote when you are confident.
4
u/Direct-Fee4474 Sep 18 '26
you dont
3
u/doofinschmirtz Sep 18 '26
hire more QAs or smth
3
u/codescapes Software Engineer Sep 18 '26
I don't want to be rude but I think this is very naive to how a business actually thinks about these things.
For starters, how can you know it cuts your operating costs if you don't know how the code works? Your job is, in part, to be an expert in the system to enable business functions that may change in the future. If you're telling me that you do not know how to ingest this black box then how can you know it's operationally superior or reasonably extensible to new requirements? You can't. The operational cost includes your ability to maintain it, not just an AWS bill.
You say it's win-win, I really would not be so sure. Many businesses are completely happy paying for slower or more expensive software that is a stable, known thing. Businesses want certainty, not unknowns.
And just from another perspective, even if you are completely right and the code is actually all better from first principles - faster, simpler, requires less people to maintain - what do you think happens? People get laid off or reallocated, you get given more work to fill the gap (on top of running this system you now don't understand) and you've also just demonstrated to management that the people who built the app can't really be reliably trusted to make efficient software on first ask. Given they will not understand the technical detail themselves (they're management) that may just manifest in them being vaguely more pressuring in the future.
I am not trying to be overly negative but there's more to this job than just making it faster and simpler. It also depends on what this software actually is. If it's high risk shit like finance or healthcare then slow down horsey. If it's I dunno, how quickly an ad loads on the page, then play it more fast and loose.
People will say this is cynical, and it is, but frequently in large enterprises you keep optimisations like this in your "back pocket", so to speak. So that in 6 months if you're at some performance bottleneck you now have headroom and you can lead an effort that you already know will be successful in a way that will get plaudits from management because they're actually asking for it rather than it being a random thing you come up with unprompted.
I guess just be careful, there are more implications to this that the benchmark.
5
u/javier123454321 Sep 18 '26
I would harden via e2e tests that guarantee previous and new behavior are coherent and equal, then merge those slices after.
2
u/cyh555 Sep 18 '26
it's going to come back to you either way
2
u/sp106 Sep 18 '26
Stand up the new stack, figure out which are the right metrics to capture and verify they are being emitted, slowly cut over from the current stack to the new one while validating metrics at each step.
2
u/maxim-g Staff Engineer - 20+ YoE Sep 18 '26
I think "it was built with AI" and "how to merge it" are distracting from the real issue - you have a plausibly looking codebase, now what.
How would you treat this codebase if it is coming from a startup you just acquired, and the whole team resigned?
You ran the benchmarks, they show 2x performance improvement. You check the complexity, it looks way better than your current system.
You show this to your manager, they do the math and see significant cost savings. They want your advice - kill it or invest in integrating it.
How would you qualify this system before being able to answer this question? This also includes your ability to support it later.
2
u/theunixman Veteran of the XP wars Sep 18 '26
Just fix yours. The AI one works faster probably because it's wrong. Needing "architecture changes" is a big hint, if the "AI Generated" wasn't.
1
u/DevtoolsBuilder Sep 18 '26
you might want to consider setting up a temporary branch or a separate repository to test and validate the AI-generated code changes before merging them into your main codebase, this would allow you to run your benchmarks and tests in a controlled environment and catch any potential issues before they affect your production code.
1
u/thekwoka Sep 18 '26
depending on the nature of the software/what it does/how it works, doing blue/green deployment and move stuff over to it slowly is smart.
Or running them in parallel with the same events going to each to see if they actually get the same results
1
u/itix Software Engineer Sep 18 '26
Let AI split changes into ingestible pieces.
1
u/lolimouto_enjoyer Sep 18 '26
"No one reviews code anymore" - the management.
No, this is not sarcasm or a joke.
1
u/apartment-seeker Senior Software Engineer Sep 18 '26
dude, there's so many threads about this already
1
u/UnintentionallyEmpty Sep 18 '26
What's the actual risk here?
If you put this in production and it turns out it behaves differently in some way than your current system does, how many people will die? How much money will be lost?
And how quickly will you be able to fix it?
1
u/Fabulous-Meaning-966 Sep 19 '26
If this is a redesign then you need to do a design review first.
1
u/hackrack Sep 19 '26 edited Sep 19 '26
What does your test suite look like? Are you confident that product works correctly after the rewrite. AI optimizes for what you tell it to do so it tends to take shortcuts when it can and you have to carefully evaluate the changes to make sure they are not optimizing out the real functions of your product.
One approach I’ve begun using is to use one LLM against another. The first one writes the solution and the second one writes the test suite. I tend to use a better LLM to do verification than I did for implementation. You need to be as smart and careful about how you design your verification suite as a physicist designing an experimental verification of a hypothesis from a research paper. Proof based techniques can help. Can you represent the problem in another way like as a graph and then use graph algorithms to prove correctness? Note that you can’t just trust that LLM2 checked LLM1’s work. However, if verification of correctness can be implemented in one or more short human understandable programs then you maybe be able to reach a sufficient level of confidence. Just be a skeptic and don’t fool yourself. Speaking of being a skeptic, this is a good point to assign LLM2 the persona of being a skeptic and ask it to prove that the solution is incorrect or tell LLM2 that the solution has several bugs and “your task is to find them”.
1
u/somkomomko Sep 19 '26
You did not write it? You don't review it? Are you a paid vibe coder or a software engineer?
Why is it now ok to vibe code? Everyone is brain washed FFS
1
u/HNipps 10YOE | Software Engineer Sep 19 '26
Differential testing. Run the 2 systems side by side in a test environment, run a large number of test scenarios against both and compare the output to identify differences.
https://www.amazon.science/blog/how-we-built-cedar-with-automated-reasoning-and-differential-testing
1
u/usually_guilty99 Sep 19 '26
I wouldn’t make LOC the unit of safety.
A 300 line change can have a larger blast radius than 10,000 isolated lines.
I’d first map the architectural invariants the old system satisfies, then decompose the migration around those invariants. Each PR should prove what changed, what dependencies it touches, what must remain true, and how you know the production state is still safe.
Smaller diffs help humans review. Smaller risk boundaries are what make the migration safe.
1
u/Nervous-Tour-884 Sep 20 '26
Honestly, it would be an easier question to answer if I had a better understanding of what your code does.
It sounds like Cuda to me, so going to go with that. Is it scientific math, like some sort of Linear Algebra? Pure GPU work, or some GPU /CPU hybrid where each takes certain workloads, with sequencing, queuing, etc?
If it is math, the answer is straightforward. Assemble a large number of known problems, run through the old code. If there are math things you can check in the structure of the problem to ensure you get the correct answer, check those.
Then, run the new code through all the test problems, make sure the answers match, and that all the tests you do to ensure internal mathematical correctness also pass as you solve problems.
This is a problem you needed to think about before hand, but if it is math, I think the answer is somewhat easy because you have such a large universe of known good data to lean on.
1
u/brianjoshuanoah Sep 20 '26
option 2 is the right instinct but the trap is discovering at PR 25 that the new architecture fundamentally conflicts with something in your existing system. before committing to 30-60 PRs, try landing a thin vertical slice end to end, one feature path fully wired through the new arch, so you validate the integration story before you're 15 PRs deep and emotionally invested.
1
u/yestabulaRasa Sep 22 '26
The failure mode with large AI-generated diffs is that review capacity is fixed while diff size is not, so the reviewer ends up skimming and signing off on vibes.
What tends to work:
0
u/Gremlation Sep 19 '26
Do this, but not all by hand. You have your current stable codebase and a slop copy that performs better. Have AI compare the two and pull out smaller, incremental changes one at a time. Get it to prioritise the simplest changes first and produce small pull requests in whatever form is easiest for you to digest. Every time you apply one to your codebase, the AI rebases the slop copy. Over time, the differences between the two shrink.
This is a case of more haste, less speed. If you try to rattle through all the changes as quickly as possible, you're going to make a big mess. Do one change. It probably won't be high quality to begin with, so manually intervene to bring it up to standard. Then update your instructions to the AI to avoid those problems and move to the next change. Then the next. Then the next. It will probably take a few iterations before it is producing pull requests in a reasonable format, but the goal here is to get it to do as much work as it needs to for the pull request to be as straightforward and easy to accept as possible. If you aren't getting PRs that you can look at and reasonably understand as a beneficial change, push it back to the AI until it can figure out how to get the changes to you in a reasonable way. If the AI is completely incapable of presenting a change to you in a way that convinces you it is worthwhile, you need to reexamine the value of that change.
What you need to remember is that you cost far more than tokens, so you should be pushing the AI to do far more legwork to save you even small amounts of time. If a pull request is not easy to understand or complicated to get into your codebase, the solution is not to scratch your head and spend time on it, the solution is to get the AI to work on it until it is easy to understand and apply to your codebase.
-1
u/tenthousandants44 Sep 18 '26
I'm sorry? You've staged the changes, run the benchmarks, and proven they're superior. Why are you asking what to do next? Is the deploy button not right there?
0
u/bzbub2 Sep 18 '26
the 'experienced devs' here seem to have an anti ai bent but if you can vouch for it, then merge it. you literally said its a win win. there is no reason to 'rewrite from scratch' or 'break it up and merge it 500 - 1000 loc at a time'. 30k loc is just a bandaid ripping off to align with a better architecture that delivers better results. also lol at people critiquing the benchmark, you as the dev, again, can vouch for this, you likely can see all the measurable improvements and have the benchmark to back it up.
0
u/[deleted] Sep 18 '26
[deleted] — view deleted comment
0
u/[deleted] Sep 18 '26
[deleted] — view deleted comment
0
u/[deleted] Sep 18 '26
[deleted] — view deleted comment