Every rewrite reaches the same moment. The new system produces an answer, the old system produces a different one, and somebody has to decide which is right.

Testing research has a name for the thing that decides: the test oracle. Barr and colleagues surveyed the difficulty of building one, “the oracle problem”, in a 2015 paper, and for most software it is a hard problem. A rewrite looks like the easy case. The old system is the answer, isn’t it?

I don’t think it is that simple, and I don’t think teams talk about it enough before they start. “Who is the oracle?” is a decision, not a fact, and the choice shapes everything that follows: what you test, what you are allowed to fix, and how long the project takes.

These are the candidates I keep coming back to, and how each one lets you down.

1. The old source code

The source looks like the spec. Read the function, reproduce the function.

It explains how the old system behaves, which nothing else will. But code describes what could happen, not what does. It contains paths no user reaches any more, branches gated by configuration nobody remembers, and changes merged to a development branch that never shipped. Port all of it faithfully and you can create differences that look like fixes, with the source apparently proving you right.

Code is also full of bugs, and porting a bug faithfully is still porting a bug.

2. What the old system actually produces

Run the old system, capture its output, and make the new one match. Michael Feathers calls tests like this characterization tests: they record what the code does, not what anyone thinks it should do.

This is the closest thing to ground truth. It is what users see. It is also unforgiving in ways that matter:

  • A capture is a moment. The output depends on the data at the time you captured it. Re-capture next week and some differences are data drift, not regressions. Captures go stale, and a stale capture fails your new system for no reason.
  • You have to be sure the old system produced it. If anything else sits in front, such as a cache, a proxy or a page that was already migrated, your “ground truth” is somebody else’s output.
  • It preserves every bug. Hyrum’s Law says it plainly: “With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody.” Matching observed output means matching the mistakes, at least until you decide otherwise.

Randall Munroe drew the purest version of this. In version 10.17 of some piece of software, “the CPU no longer overheats when you hold down the spacebar”. A longtime user is furious: they had configured Emacs to read the rapid temperature rise as “control”. Their request: “Just add an option to reenable spacebar heating.”

xkcd 1172: Workflow. A changelog entry fixes CPU overheating when the spacebar is held down, and a user complains that the fix broke their workflow.

xkcd 1172, “Workflow” by Randall Munroe, CC BY-NC 2.5.

Every rewrite has a spacebar heater somewhere. The only question is whether you find them before launch day or after.

3. The data

“Nobody uses this field, the column is empty.” The database is the most tempting oracle because it answers quickly.

It answers the wrong question. Data tells you how much something matters here, today. It does not tell you what the system promises. An empty table in one installation can be the most used feature in another, and the same binary serves both. Data is good for deciding what to do first. It is a poor reason to decide what not to build at all.

4. The specification

When there is a written spec, it is usually what the system was meant to do years ago. Specs are aspirational, partial and out of date in roughly that order. They are useful for intent (“this was always supposed to round half up”) and weak as an oracle for any individual output.

5. The callers

For an interface, the people and programs calling it are the real contract. If a client depends on a misspelled field name or an error code hidden inside a success response, that quirk is now part of the API, whatever the documentation says.

The trouble is that you cannot ask them all. Some callers are other teams; some are scripts nobody owns; some are systems outside your organisation that you will only hear about when they break.

The strongest answer I know: the Linux kernel

The Linux kernel picked its oracle decades ago and wrote it down. The kernel’s own documentation calls it the first rule of Linux kernel development: “We don’t cause regressions.” It defines a regression in terms of users, not specifications: something that worked with one kernel and “works worse or not at all with a newer version”.

Linus Torvalds has said it more bluntly many times. In one 2012 reply, after someone asked how long a deprecated behaviour must be kept “if two years isn’t sufficient”: “What part of ‘We don’t break user space’ do you have trouble understanding? There is no time limit.” And: “If people reports it breaks user-space, we fix it. And we keep fixing things until nobody uses the old versions any more.”

Two things make this more than a slogan. First, the oracle is the callers: whether a program that worked still works, not whether the old behaviour was correct or documented. Second, the rule has a boundary. The same project is deliberately unstable inside: its guide to internal interfaces explains why there is no stable in-kernel API, and notes that it “describes the in kernel interfaces, not the kernel to userspace interfaces.” Frozen at the edge, free behind it.

The honest caveat is cost. The kernel can promise compatibility with no time limit because it has a person with the authority to enforce it and a community that accepts the price. Most teams can’t pay that forever, which is why the question below about when to stop preserving a bug is still open for the rest of us.

My working answer, for now

This is opinion, not a rule. I’ve settled on using different oracles for different questions, rather than one oracle for everything:

  • Observed output decides what the system must do, for anything someone outside can see.
  • The source explains why, and is where you go when the output surprises you. It never overrules the output on its own.
  • The data decides how much it matters, which orders the work but never cancels it.
  • The callers decide what may change. Where others depend on an interface, keep its quirks, typos included. Behind that boundary, where nobody else is calling, the behaviour is yours to improve.

In practice that becomes two doors. The old interface stays exactly as it was for everyone already using it, quirks included, and translates at its edge into a clean internal model, so its oddities never travel inward. New callers get a new interface designed properly, on the same core. Even at the old door, a few things outrank compatibility: keeping one customer’s data away from another’s, and security. A caller may notice those fixes, and that is the price. And the old door closes the way the kernel closes things: when measured usage says nobody comes through it any more.

When a disagreement gets stuck, one question settles most of them: would anyone who depends on this see a difference? If yes, the old behaviour wins until there’s a deliberate decision to change it. If no, it’s your call.

What I still don’t have good answers to

  • When do you stop preserving a bug? Hyrum’s Law says somebody depends on it. The kernel’s answer is “when nobody uses the old versions any more”. Most of us can’t afford that. Who gets to decide sooner, and how do you tell the people who depend on it?
  • How do you expire a capture? Re-capture everything and you erase real regressions; never re-capture and you chase data drift forever.
  • What is the oracle once the old system can no longer run? At some point the reference implementation is switched off. After that, the captures are the only memory of what “correct” meant.
  • Who owns the decision? Engineering, product, or the people who will be paged when it is wrong?

I’d like to hear how others draw these lines, especially anyone who has finished a rewrite and lived with the result for a few years.

References

  1. Barr, E. T., Harman, M., McMinn, P., Shahbaz, M., & Yoo, S. (2015). The Oracle Problem in Software Testing: A Survey. IEEE Transactions on Software Engineering, 41(5). doi:10.1109/TSE.2014.2372785
  2. Feathers, M. C. (2004). Working Effectively with Legacy Code. Prentice Hall.
  3. Hyrum Wright, Hyrum’s Law. hyrumslaw.com
  4. The Linux kernel documentation, Reporting regressions. docs.kernel.org
  5. The Linux kernel documentation, The Linux Kernel Driver Interface. docs.kernel.org
  6. Linus Torvalds, linux-kernel mailing list, 12 November 2012. Archived message
  7. Randall Munroe, Workflow, xkcd 1172, 11 February 2013. xkcd.com/1172 (CC BY-NC 2.5)