Skip to main content

Quick Overview

In this episode of Serverless Expeditions by Google Cloud Tech, host Martin Omander interviews developer JK Gunnink about techniques for maintaining legacy software. The discussion examines how AI coding agents can be integrated into existing development workflows to update complex, undocumented codebases safely.

Key Points

  • 1.AI coding agents can trace data dependencies across frontends, APIs, and databases to update complex legacy codebases.
  • 2.A change request driven strategy breaks legacy modernization into three distinct phases: plan, execute, and verify.
  • 3.Documenting local toolchains in a README file allows AI agents to run compilers, linters, and tests to autonomously self-correct syntax errors.
  • 4.Planning mode enables agents to map the entire blast radius of a change across files and database tables before editing code.
  • 5.Decoupling test authoring from code generation prevents AI agents from creating self-serving tests that mask implementation flaws.
  • 6.A three-layer verification system consisting of human review, secondary CI/CD AI review, and staging smoke tests ensures bugs do not reach production.

Summary

Modernizing legacy codebases often presents severe challenges, including missing documentation, complicated data flows, and an absence of automated tests. Rather than trying to understand an entire system at once, developers can adopt a change request driven approach that modernizes code incrementally as specific requirements arise. Because AI coding agents excel at tracing data paths from user interfaces through APIs down to databases, they can update interdependent code paths across a system when a single field or feature changes. This approach organizes legacy modernization into three main phases: planning, execution, and verification.

The planning stage centers on preparing a safe development environment and mapping dependencies before writing code. Developers should document the local setup, including compilers, linters, and test runners, in a central README file. This documentation allows the agent to execute commands autonomously, catch syntax errors, and iterate in a tight feedback loop. Encapsulating this workflow in a Docker container ensures the environment remains disposable and easy to reset. In the Antigravity IDE or CLI, developers engage planning mode to instruct the agent to inspect the codebase and identify every file, API endpoint, or database table that could be affected by a change. Rather than immediately generating code, the developer collaborates with the agent by requesting multiple architectural designs, critiquing plans, and prompting the agent to ask clarifying questions about overlooked requirements.

The execution stage transforms these plans into code while strictly managing the agent's context window. To prevent the agent from becoming confused during extended sessions, large features are divided into distinct subtasks tracked in a markdown checklist. After completing each task, the agent summarizes its changes and carries that context into the next step. To maintain software quality, developers apply test-driven and behavior-driven development. Advanced reasoning models like Gemini Pro analyze tickets to define acceptance criteria and write failing tests, after which higher-throughput models like Gemini Flash write the minimum code needed to pass the tests. Defining strict agent rules ensures the AI respects formatting standards, runs builds, and never commits code without human approval.

The verification stage establishes safety barriers to keep model hallucinations and regressions out of production environments. This step applies a three-layer filter. First, human engineers perform manual diff reviews to guarantee that new code remains readable and maintainable for both future developers and AI tools. Second, the CI/CD pipeline uses a secondary AI model to perform code reviews on pull requests, requiring the initial authoring agent to justify its implementation decisions. Third, automated deployments send code to a staging environment where developers conduct smoke tests to ensure runtime stability.

Planning and Sandboxing

Modernizing legacy code begins with preparing an isolated environment and setting up clear operational boundaries. By documenting local commands for compilers, linters, and unit tests in a README file, developers enable AI agents to run tools and self-correct mistakes automatically. Using containerized setups like Docker provides a disposable sandbox where agents can safely experiment. Before modifying code, developers activate planning mode in tools such as Antigravity to explore the repository, calculate the blast radius of changes, and brainstorm architectural options with the AI acting as a collaborative coworker.

Context-Driven Execution

To prevent agents from losing context during long sessions, large modifications are broken into sequential subtasks tracked in a markdown checklist. The execution phase relies on test-driven and behavior-driven development principles. A reasoning model such as Gemini Pro drafts acceptance criteria and failing tests based on issue specifications, while a faster, cost-effective model like Gemini Flash generates the code required to pass them. Establishing explicit agent rules enforces coding conventions, ensures tests run first, and prevents unauthorized repository commits.

Verification and Quality Guardrails

Because generative models can hallucinate, a multi-layered verification strategy prevents defective code from reaching production. First, human developers conduct manual diff reviews to verify readability and maintainability. Second, an automated CI/CD pipeline triggers a secondary AI model to review pull requests while the authoring agent defends its implementation choices. Finally, changes deploy automatically to a staging environment for real-world smoke testing, ensuring the application behaves properly across actual workflows.

The Bottom Line

This video establishes a structured, three-phase framework for leveraging AI coding agents to refactor and modernize undocumented legacy codebases safely. It demonstrates that integrating automated tool execution, test-driven prompting, and multi-tiered verification turns unpredictable legacy code edits into a repeatable process. The presentation leaves tool selection details for specific language ecosystems and organization-wide migration policies for developers to tailor to their own stacks.

FAQ

What are AI coding agents and how do they assist in updating legacy codebases?

AI coding agents are generative tools capable of tracing data dependencies across frontends, APIs, and databases, allowing them to modify complex and undocumented legacy software safely when new features or fields are added.

Why should developers document their local setup in a README file for AI coding agents?

Documenting build, lint, and test commands in a README allows the agent to run local tooling autonomously, catch syntax errors, and self-correct code changes in real time.

How does using planning mode help map the blast radius before AI coding agents modify legacy code?

Planning mode instructs the agent to analyze the codebase and identify all files, APIs, and database tables that could break prior to writing or modifying any implementation code.

Why is breaking features into small subtasks essential for managing context with AI coding agents?

Breaking features into smaller subtasks tracked in a checklist prevents the agent from losing focus during long chat sessions by feeding compact summaries of completed work into each subsequent step.

What role do test-driven development and behavior-driven development play when prompting AI coding agents?

They ensure the agent writes failing unit and behavior tests based on requirements before any code is generated, preventing the agent from authoring self-serving tests that overlook flaws.

What three verification layers prevent AI coding agents from shipping broken code to production?

The three-layer filter includes a manual human review of code diffs, an automated CI/CD code review conducted by a secondary AI model, and real-world smoke tests in a staging environment.

Worth watching for

Software engineers, tech leads, and development teams tasked with refactoring, extending, or maintaining large, undocumented legacy software systems using AI tooling.

  • ai-coding-agents
  • legacy-code
  • software-engineering
  • test-driven-development
  • google-cloud
  • code-refactoring