Solving the Nasty Code Migration Problem with Assisted AI Agents

Code migrations are like cleaning the house. We know we have to do it, but we wish we didn't have to. Yet, we are still only using AI to create new code vs cleaning the existing mess.
CEO @ Aviator

Solving the Nasty Code Migration Problem with Assisted AI Agents

Code migrations are like cleaning the house. We know we have to do it, but we wish we didn't have to. Yet, we are still only using AI to create new code vs cleaning the existing mess.

The 2024 DORA Report found that the most common use of AI in software engineering is for writing code. 67% of respondents report that AI is helping them improve their code. Developers use genAI coding assistants for smarter code completion and AI code editors for prototyping ideas and writing new functionalities.

In real life, developers spend more time modifying existing code than writing new code

As the volume of AI-generated code increases, software engineers are expected to maintain more of it.

With More Code Comes More Responsibility

It’s easy to write fresh code but harder to maintain it. A few years ago, I worked on a massive code migration that seemed simple on paper—renaming a core API used across thousands of files. We wrote scripts, ran tests, and thought we had it under control.

But every time we pushed changes, something broke. Edge cases emerged. Business logic we didn’t even realize was tied to this API failed in production. The migration dragged on for weeks, burning through engineering time and patience. Someone recommended using contractors to take over that task. Six months and thousands of engineering hours later, we finally finished the migration.

Doing Code Migration is Like Cleaning the House

Even the most straightforward changes – renaming a function, refactoring a pattern, or updating a deprecated API – can spiral into an endless cycle of debugging and fixing unforeseen issues. They’re tricky, time-consuming, and let’s be honest – boring. They demand precision but often end up being a brute-force operation riddled with trial and error. 

No developer ever says: “I enjoy doing code migrations.” It’s like cleaning the house – we know we have to do it, but we wish we didn’t have to. It’s the “harder job” that nobody wants to do.

Still, code migrations are inevitable. If there is a need from the business side due to security considerations, deprecated functionality, scalability, or performance reasons, you cannot say no. 

But, since code migrations are a cost center and, in most cases, do not add immediate business value to the customer, they can be hard to prioritize. At Google, there used to be a saying that all the internal frameworks were either deprecated or in beta, which reflects the breadth of code migrations at such a large scale.

Can AI go beyond generating new code and actually work on the mundane tasks of code migrations?

Google published a paper last year on Code migrations supported by AI, and engineers at Slack also wrote about their experience with AI-assisted code conversion project. Most forward-thinking companies are already exploring the possibilities of taking over this gigantic task.

The Conventional Way: Using AST 

A traditional approach to performing large-scale migrations is using the AST transformations. These work like compilers, where you write rules on how the compiler understands code and then perform very well-defined targeted tasks. These are easy to execute but can be extremely hard to write. The changes needed in each framework or library can be large enough that writing an AST transformation may not be possible. But it’s a good starting point.

In large organizations, you may need to get several teams and stakeholders involved in a room to get commitments for prioritizing the migration work. In most cases, there is very little documentation available; the developers who wrote the code may have already left the organization, and everyone is scared of touching the code.

The trouble with LLMs: Lack of context and hallucinations

Without this additional context, the LLM’s accuracy could be all over the place. All LLMs are trained on public source code and documentation. They may understand that the migrations can be performed broadly but miss out on the nuances from the tribal knowledge of the company.

The other issue is hallucinations. An LLM model (or, rather, any AI model) works like a black box. It is trained on public data, and when given a problem, it will pattern match with that data. For anything that does not match the pattern, LLMs will make their best guess. Hallucinations happen when those guesses go wrong.

Another common issue is understanding the large code base. This problem is nowadays largely solved using RAG, which stores the codebase in a vector database and can query for references and context.

The common theme in all of these approaches and challenges so far is that – even though modern LLMs are getting great at understanding and generating code, they cannot perform the tasks end to end without supervision.

Assisted LLM Approach: Agents and developers working together

To solve the complex challenges associated with large-scale migrations, we can try an assisted LLM approach. Think about a group of junior engineers coming together, led by a Team Lead, to solve a problem. The junior engineers can interact with each other and come up with a thesis, check with the TL for feedback, and iterate on it. We can apply the same approach using LLM, where the agents are the junior engineers and the Team Leads supervise their work and provide feedback.

Here’s an example of how AI Agents would work:

  1. Define the migration – You would specify the change you want to make. This could be renaming an API, refactoring a code pattern, or updating dependencies.
  2. Search online – AI agents search for references in public sources online and in the company’s private documentation, and find examples of prior work.
  3. AI generates initial suggestions – The agent analyzes your codebase and produces a migration plan, applying transformations in a sandboxed environment.
  4. Human-in-the-loop refinement – You review, modify, and guide the AI’s changes, ensuring correctness.
  5. Automated execution at scale – Once validated, agents define the playbook and roll out the migration across your entire codebase.
  6. Continuous learning – Further feedback helps regenerate parts of the migrations and continue improving accuracy.

What type of maintenance can agents perform, and how well? That depends on how well you can define the scope and the requirements. The better you define the scope and requirements, the easier it will be to get good results. AI-assisted code maintenance could work well with framework upgrades, internal API deprecations, and security fixes.

Framework Migration

Automate the transpilation of component trees between UI frameworks while preserving component hierarchy, state management patterns, and event handling. Maintain functional equivalence through static analysis and runtime behavior verification.

API Deprecation Resolution

Perform targeted AST transformations across repository boundaries to replace deprecated method calls with their current equivalents. Including dependency graph analysis to ensure consistent updates throughout the codebase and verification of semantic equivalence.

Security Vulnerability Remediation

Apply standardized patches with context-aware code transformations, validated through comprehensive test suite execution.

Offloading the bulk of migration work to AI while keeping humans in control turns code migrations from a painful, drawn-out process into a streamlined, efficient workflow.
The result? Developers spend less time on busywork and more time building.

Sign up for early access to Aviator Agents, an LLM-based Agentic framework to perform large-scale code migrations.

Subscribe

Be the first to know once we publish a new blog post

Join our Discord

Learn best practices from modern engineering teams

Get a free 30-min consultation with the Aviator team to improve developer experience across your organization.

Powered by WordPress