Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
ReleaseInsight · On RadarHabr AI→ original

Yandex 360 Taught AI Agents Not to Copy Legacy Code: PR Reviews in 5–17 Minutes

Agents in the Yandex 360 mobile app were copying outdated code, such as EventBus instead of Flow. The project is 12 years old and contains 400,000 lines of code. The team put its rules into the .ai/ folder of the repository, and now an agent checks every pull request (PR, a request to merge changes) in 5–17 minutes. The takeaway: state "we don't write it this way" before the task, not in a comment on finished code.

AI-processed from Habr AI; edited by Hamidun News
Yandex 360 Taught AI Agents Not to Copy Legacy Code: PR Reviews in 5–17 Minutes
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1The project has 150–200 modules and over 7,500 files; the rules drive about 20 skills
Key metric #2From June to August 2026, the main branch gained almost 1,000 JVM tests
Key metric #3Another 150 snapshot tests (105 visual, 45 accessibility) became mandatory

Anyone who has run an AI agent in an old repository knows the problem: the code works, but it is written in a way the team no longer wants to write. The agent finds a working example, copies it, and doesn't know that the agreement has changed long ago. For instance, it will update a loading state on a screen through EventBus (the old event bus), even though the team uses Flow (coroutine-based data streams) on newer screens.

Yandex 360 mobile developer Maxim Kiryakov described on Habr how the team handled this in a 12-year-old project with 400,000 lines of code. The result: the agent reviews every pull request (PR, a request to merge changes into the main branch) in 5–17 minutes and flags deviations from the team's rules.

What the problem was

The app has 150–200 Gradle modules, more than 400,000 lines of Kotlin, Java, and XML, and over 7,500 source files. Since 2012, XML has given way to Compose, Java to Kotlin, and MVP, MVVM, and MVI have all come and gone. All of it remains in the repository, and the agent readily takes the old code as a template. It may use LiveData instead of Flow, or call an old command where a UseCase with coroutines is expected.

Knowledge about how to write things correctly was scattered: some of it lived in the wiki, and some was passed on verbally. Hard bans did not work, because nobody wanted to rewrite old code with every change. The rules had to be written down. To do this, AI analyzed the code, extracted recurring patterns, and separated legacy code from what the team wants to develop further. Then developers tested the instructions on real tasks.

How the system works

All the rules live in the .ai/ folder inside the repository. Developers use different models and clients, but each connects the same set through small adapters. There are no copies, so the instructions don't drift apart. The team writes a new skill (a ready-made instruction for a recurring scenario) once the same scenario has been run several times. There are about 20 of them now.

Alongside the rules, the agent uses architecture documentation, source code, and the ast-index structural search tool. It builds a map of the code: where a needed class is and how modules are connected. The rules answer the question "how to do it," while the documentation and source code show where to find examples.

The rules are simple:

  • a small change in a legacy module: follow the module's patterns and do not migrate;
  • a new feature next to legacy code: isolate it in the new architecture (MVI + Compose).

So on an old screen the agent keeps EventBus, and on a new one it builds a chain of ViewModel, UseCase, and Flow.

For complex tasks, several role-based agents work together:

  • Researcher studies the code and changes nothing;
  • Architect builds the plan, boundaries, and acceptance criteria;
  • Developer implements the plan and reports if it needs to depart from the architecture;
  • Bug hunter looks for the cause of a bug;
  • Tester writes tests;
  • Reviewer checks whether the changes solve the task and comply with the rules.

The chain is selected by Router, whose rules are also stored in .ai/ as markdown. For a bug with an unknown cause, the chain is: Bug hunter, Architect, Developer, Reviewer. If tests are needed, Tester is added after Developer.

Review in CI and results

At first, Reviewer was run manually. Now, when a PR is opened, the continuous integration (CI) system runs the check against the project's rules automatically. The agent looks at the diff and leaves comments on specific lines. The review takes 5–17 minutes, not counting the wait for the run to start. While the PR waits for colleagues, the author has time to fix some of the comments.

In one PR, the agent found that a failed write of a service metric could interrupt the main background operation. In another, it noticed that navigation interface actions were changing the screen state. In a third, it required tests for errors, interruptions, and recovery. Six test methods were added, and a second pass found one more bug: during recovery, some pending actions could be lost.

The requirements for comments had to be tightened. The agent must explain under what conditions an error occurs and what it leads to. The phrase "the code may be dangerous" is not accepted. An author has the right to reject an incorrect comment with an argument.

From June to August 2026, almost 1,000 JVM test methods (fast tests that run without an emulator) were added to the main branch. In addition, 150 snapshot tests were added, which compare a screen against a reference: 105 visual and 45 accessibility. Since August they have been mandatory for PRs. The authors are candid about the limits: they did not count how many of the tests were written by agents specifically, and the number of methods is not the same as code coverage. They also did not measure how many hours the review saves; there is only the team's impression.

The same rules were connected to Gene, an executor agent that runs the full cycle from studying the task to fixing review comments. A human joins at the final check and approval, and steps in earlier if the automation fails. Architectural changes are not entrusted to machines: a PR, CI, and peer review by colleagues remain mandatory.

What to take away

Keep the rules next to the code: which approaches are current, where the old implementation remains, and what must be agreed on before a rewrite. Point to where to read about the architecture and how to search for code. Along the way, you will have to state clearly which changes are allowed in legacy code and what supports a review comment. This helps not only the agents but the team itself.

Story

Key Questions Answered

What the problem was?

The app has 150–200 Gradle modules, more than 400,000 lines of Kotlin, Java, and XML, and over 7,500 source files. Since 2012, XML has given way to Compose, Java to Kotlin, and MVP, MVVM, and MVI have all come and gone. All of it remains in the repository, and the agent readily takes the old code as a template. It may use LiveData instead of Flow, or call an old command where a UseCase with coroutines is expected.

How the system works?

All the rules live in the .ai/ folder inside the repository. Developers use different models and clients, but each connects the same set through small adapters. There are no copies, so the instructions don't drift apart. The team writes a new skill (a ready-made instruction for a recurring scenario) once the same scenario has been run several times. There are about 20 of them now. Alongside the rules, the agent uses architecture documentation, source code, and the ast-index structural search tool.

What are the key details on Review in CI and results?

At first, Reviewer was run manually. Now, when a PR is opened, the continuous integration (CI) system runs the check against the project's rules automatically. The agent looks at the diff and leaves comments on specific lines. The review takes 5–17 minutes, not counting the wait for the run to start. While the PR waits for colleagues, the author has time to fix some of the comments. In one PR, the agent found that a failed write of a service metric could interrupt the main background operation.

ZK
Zhemal Khamidun — Head of AI at Alpina Digital · MIPT (academic supervisor of the Tech Entrepreneurship department). Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Free · Waitlist · Hermes + DeepSeek

Free 2-Day Vibecoding & AI Agents Intensive

Day 1: the autonomous Hermes + DeepSeek AI agent — vibecoding and development on par with Claude Code / Codex / Gemini. Led by Jemal Hamidun, Head of AI at Alpina Digital and academic supervisor at MIPT. Right after you register with our bot Nika: the recording + 11 materials from the previous intensive.

Join the waitlist →Nomad AI Workspace
Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Yandex 360 Taught AI Agents Not to Copy Legacy Code: PR Reviews in 5–17 Minutes https://news.hamidun.com/en/news/18939/yandex-360-taught-ai-agents-not-to-copy-legacy-code-pr-revie

What do you think?
Loading comments…