AI refactoring without losing correctness
Published
Refactoring legacy code with coding agents can speed up the writing. Whether the gain is worth it depends on something else: correctness. The new system has to behave like the old one wherever the business still depends on it. Speed without correctness only brings the incident forward.
The thesis is simple: in legacy refactoring, correctness comes before speed. Three practices support it: characterization tests against behavior in production, humans on the team who read what goes in, and a recorded session from request to promotion. With supervision and a trail, speed becomes an auditable result; without them, it becomes opaque debt.
Who this article is for
For the CTO and the head of engineering who have already watched AI assistants write diffs quickly and who ask how to make sure the refactored slice does not change the rule the business still uses. It also serves readers who arrived from Legacy modernization without stopping the business or from Coding agent observability and want to understand correctness before requesting an assessment. It does not replace the commercial offer or the Dr. Consulta case.
The risk that speed hides
In a critical legacy system, the documentation has aged and the people who wrote the code have left. What still holds of the business rules lives in the system running today. A coding agent that “rewrites it better” without an anchor in that behavior can change a silent rule, speed up the wrong backlog or erase the history of the session. Without the request, steps, model, cost, result and authorship, the team cannot reconstruct what was accepted or who promoted it.
None of these risks is an argument against coding agents. They are arguments for a design in which the agentic development platform requires checking, reading and a trail: level 4, not a dark factory. The contrast with level 5 is in What a dark factory is.
Before starting, it is worth checking the risk signs of a legacy system.
Correctness before speed
The sentence from the legacy offer serves as this article’s criterion: speed and cost show up first; correctness decides whether either is worth anything.
In practice, the order of the work changes:
| False priority | Useful priority |
|---|---|
| “How many lines did the agent write?” | “Does the new slice replicate the old one’s behavior at the points the business still uses?” |
| “How many days did the feature take?” | “Before it went in, was it checked against the system in production?” |
| “Did the AI write it on its own?” | “Did the team read what goes to production, and was the session recorded?” |
Correctness, here, is not “clean code” or “zero bugs forever”. It is fidelity to the behavior that still serves the business (measured, reviewed and attributable) while the replacement grows beside it.
Characterization tests: anchoring what the legacy system does
Before rewriting, the team needs an anchor for current behavior. The classic practice is characterization tests, described by Michael C. Feathers in Working Effectively with Legacy Code: tests that document what the system does today, not what the documentation says it should do.
In refactoring with coding agents, this becomes routine:
- Reading: code, documentation and anonymized data go into the Knowledge base before any new line.
- Characterizing: the chosen slice gets tests (or oracles) that pin down the responses, side effects and invariants observed in production.
- Building alongside: coding agents write the replacement; the old system keeps serving.
- Checking: the new slice is compared with the old one’s behavior (and with the characterization tests), not with what the aged documentation asks for.
- Switching piece by piece: only what was checked goes in; the next slice starts afterwards.
The “characterizing” step stops the AI from “improving” the system by changing the rule. Without it, “AI refactoring” becomes an optimistic rewrite. The full method (read → alongside → check → switch) is in Legacy modernization without stopping the business. Here the educational point is a single one: without characterization, there is no way to talk about correctness.
Humans read what goes in
Coding agents do most of the writing. The team sets the autonomy limit, reads what goes to production and answers for the result. That is level 4 on the scale Dan Shapiro described (covered in detail on the dark factory page): the AI executes; humans supervise and read. Level 5 (a specification that becomes software with no human reader) stays out.
Human reading in refactoring is not compliance theater. It catches a rule change the characterization test does not cover yet; it defines what requires human approval before executing and what the agents do without prior approval; and it sustains the system after the switch. Code nobody read is code nobody can explain when it breaks.
The controlled evidence on acceleration points the same way: in an experiment with GitHub Copilot (Peng et al., 2023), developers completed a programming task 55.8% faster than the control group (95% CI between 21% and 89%). It is a study of one task, with one assistant, and not an Ithaca measurement. Supervision and characterization play a different role: getting the gain into production with checked behavior, code that was read and every session recorded. In legacy work, reading closes the correctness loop.
Recorded session: the trail that makes correctness auditable
Correctness without a trail turns into opinion at the post-mortem. Every coding-agent session needs to record, at a minimum: request, steps, model, cost, result (accepted / rejected / rollback and verification evidence) and authorship (who requested, executed, supervised and promoted).
With that trail, the team can answer: which slice, against which characterization tests, with which approval, went into production? Without it, speed can be neither audited nor improved. The six fields in detail: Coding agent observability. C-level checklist: AI governance in software development.
The thesis closes like this: human supervision + recorded session make the use of coding agents in refactoring auditable and improvable. That is where speed and cost become a business result, without giving up correctness.
How the platform applies this to legacy systems
Ithaca is an agentic development platform. In refactoring (Challenge B), coding agents do most of the writing; the team sets the specification, limits, reading and promotion. Knowledge base before any new line; replacement alongside; switch only after it has been checked. Four stages (short view): Knowledge base → building/refactoring → observability → sustainment. Category: Agentic development platform. Thesis: AI software development with human supervision.
Operational proof (Dr. Consulta)
The proof comes from Dr. Consulta, which modernized its subscription system, years in production, using the platform (Challenge B, refactoring legacy). Compared with the period before the modernization:
| Dimension | Result | Note |
|---|---|---|
| One feature | from two weeks to the same day | Representative example, not a measurement of the whole backlog |
| Maintenance | from manual work to supervising the agents’ operation | Team in control |
| Infrastructure cost | −85% | Compared with the period before the modernization |
These numbers are not a measure of correctness. They show what becomes possible with checking against the old behavior, human reading and a recorded session.
What this article does not promise
- It is not zero risk: a failure is still possible; what changes is the size of the damage and how easily the trail shows the cause.
- It is not a measurement of the whole backlog: the two weeks → same day feature is a representative example.
- It is not a dark factory. The code that goes into production passes through human reading. The full method is in legacy without stopping.
Quick checklist: AI refactoring and correctness
Before scaling coding agents on a legacy system:
- A slice that can be checked end to end (not the whole system at once)
- A behavior anchor (characterization tests / oracles) against what runs today
- The replacement grows alongside; the old system keeps serving until the checked switch
- Humans on the team read what goes to production (level 4, not a dark factory)
- Every session records request, steps, model, cost, result and authorship
- An explicit autonomy limit: what requires human approval before executing
- Sustainment with the team supervising: the platform does not “deliver and disappear”
If any item fails, there is speed, but the correctness that sustains the modernization is still missing.
Frequently asked questions
What does AI refactoring without losing correctness mean?
Using coding agents to modernize slices of a legacy system anchored in current behavior (characterization tests), with the team reading what goes in and every session recorded: speed without giving up fidelity to what the business still uses.
Are characterization tests the same as “ideal” unit tests?
No. Classic unit tests express the intended behavior. Characterization documents the observed behavior of the legacy system (including quirks the documentation does not cover) and anchors the check before the switch.
Doesn’t human supervision cancel out the speed gain?
It does not have to. The agents take on the writing the team delegates; the team spends its time characterizing, reviewing and deciding. In the Dr. Consulta case, a two-week feature started shipping the same day (representative example), with the team in control and every session recorded.
Is this a dark factory?
No. Dark factory is level 5: nobody reads the code before it goes to production. The platform operates at level 4. Details in dark factory.
What result does refactoring with the platform show?
The Dr. Consulta case: a two-week feature down to the same day (representative example); maintenance shifting to supervising the agents’ operation; and, compared with the period before the modernization, infrastructure cost 85% lower. See the case study and legacy modernization.
Where is the platform hosted? Does the code go to Ithaca?
The platform is deployed in the client’s environment (a cloud the client controls, or a data center). The repository does not go to an Ithaca SaaS; model calls follow the client’s policy (provider, region and contract).
Request a free assessment
If the question is already “how to refactor legacy code with correctness, human reading and recorded sessions”, the first step is a free assessment: the agents read the system with your team.

