skip to content

general code and the edge-case tail · lesson 6 of 9 · sources checked 2026-11-30

the regression corpus and the differential run

This lesson gates each change to general code with a noise baseline and a diff on a stored corpus, counted for each target class.

status of this lesson: from a public source

purpose

A change to shared extraction code reaches each target at the same time. A small test set does not show which targets change. A stored corpus with a measured noise level shows the effect of the change before the release.

objectives

  1. Keep a regression corpus of stored pages and responses with expected records.
  2. Measure the noise of the old code against itself on the full corpus.
  3. Count the changed records of the new code for each target and each target class, with the noise removed.
  4. Classify each change as intended, neutral, or regression, and gate the merge on a limit.

new terms

how it works

A regression corpus is the test input of general code. It holds stored pages and responses, each with its expected record. A stored page does not change. Thus a diff on it shows a change of the code, not a change of the target. The first set comes from The extraction regression suite and selector drift (not yet published).

what one corpus entry holds

Each entry of the corpus holds four parts:

  • the stored response: the status, the headers, and the body;
  • the expected record that the extractor must give;
  • the target and its target class, for example "product pages";
  • the version of the extractor that wrote the expected record.

The corpus grows with each new case. For example, the failed input of a new case becomes a stored page with its expected record. The procedure for a new case is in Add one case without a regression.

the three instances

The open-source tool Diffy runs three instances opendiffy, source 1:

  • a candidate instance with the new code;
  • a primary instance with the last known-good code;
  • a secondary instance with the same known-good code as the primary.

The project documentation states the meaning of a difference between the primary and the secondary. Such a difference shows behavior that is not deterministic, and the tool treats it as noise. When the noise rate and the diff rate of the candidate are comparable, the tool reports no real regression for the candidate opendiffy, source 1.

the differential run on a corpus

I use the same three instances on the stored corpus. A differential run has three steps:

  1. Run the old code two times on the full corpus. The differences are the noise baseline. For example, a field with a random order of related items differs between two runs of the same code.
  2. Run the new code on the same corpus, and compare it with the first run of the old code.
  3. Remove the noise fields from the diff. Then count the changed records for each target and for each target class.

Without the noise baseline, volatile fields fill the diff report. A reader of the report then stops to read it.

classify each change

Each changed record gets one of three classes:

  • intended: the change is in a field that the change request names, for example a price that gets its currency;
  • neutral: the record changes only in a noise field;
  • regression: a field changes that the change request does not name.

the gate

The gate compares the count of regressions with a limit for each target class. For example, the limit is zero regressions in each class. A count above the limit stops the merge.

The count for each class also shows how far the change reaches. A change that reaches all article pages is a different risk from a change that reaches one target.

The result of the gate goes to the staged release in Roll-out order by target cohort (not yet published). The regression suite for each browser release on test pages is in The regression suite for each release (not yet published). This corpus is for a change to general code on target pages.

the same method on the detection side

Elastic documents a rule preview. It runs the query of a rule over a past time range before the rule is on. The preview shows the matches of the rule in that range, and it creates no alerts Elastic, source 2.

A detection team can use such a preview as a differential run. For example, it compares the matches of the old rule and of the changed rule on the same recorded traffic.

the two sides

automation sidedetection side
Without a noise baseline, volatile fields fill the diff report, and the team stops to read it. A diff count for each target class shows how far a change reaches before the release.A detection team runs a changed rule again on recorded traffic before it acts. A rule preview runs a rule on a past time range and creates no alerts.

design decisions

optiongaincostwhen it is correct
Test on live pagesNo corpus to keepA diff shows target changes and code changes together.Never as the gate of a code change
Small set of stored pagesFastRare page forms are not in the set.For a quick check before the full run
Full corpus with a noise baselineThe diff shows only the change of the code.Two runs of the old code on the full corpusBefore each change to general code
One total countShort reportA change to one class hides in the total.Never as the only count
Count for each target classIt shows how far the change reaches.A longer reportFor each gate

diagram

the three-instance comparison on a stored corpus

The secondary instance runs the old code again, so that the difference with the primary is noise.source: My model of the differential run on a stored corpus

code example

The example runs the three steps on a corpus of five synthetic pages in two page classes. The candidate has one intended change and one planted change.

m53-x11-diff.tstypescript

Compare the old code with itself and with a candidate on a synthetic corpus. Remove the noise, classify each change, and gate the merge.

// A differential run over a stored corpus of synthetic pages. No page is a real target.
type Page = { id: string; cls: string; title: string; price: string | null };
type Rec = Record<string, string>;

const corpus: Page[] = [
  { id: "p1", cls: "product", title: " Lamp A ", price: "12.00" },
  { id: "p2", cls: "product", title: "Desk: B", price: "80.00" },
  { id: "a1", cls: "article", title: "Notes: part 1", price: null },
  { id: "a2", cls: "article", title: "Notes: part 2", price: null },
  { id: "a3", cls: "article", title: "Short note", price: null },
];

// A fixed pseudo-random source, so that each run of the example gives the same output.
let seed = 11;
const rand = () => (seed = (seed * 48271) % 2147483647) / 2147483647;

// Old code. The field "related" has a random order: it is a volatile field.
function oldCode(p: Page): Rec {
  const r: Rec = { title: p.title.trim(), related: rand() < 0.5 ? "x,y" : "y,x" };
  if (p.price) r.price = p.price;
  return r;
}

// Candidate. Intended change: the price gets its currency. Planted change: a title with ":" is cut.
function candidate(p: Page): Rec {
  const r = oldCode(p);
  if (r.price) r.price = `${r.price} EUR`;
  if (r.title.includes(":")) r.title = r.title.split(":")[0];
  return r;
}

const changed = (a: Rec, b: Rec) =>
  [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((k) => a[k] !== b[k]);

// Step 1: old code against old code gives the noise fields.
const primary = corpus.map(oldCode);
const secondary = corpus.map(oldCode);
const noise = new Set(corpus.flatMap((_, i) => changed(primary[i], secondary[i])));
console.log(`noise fields: ${[...noise].join(", ") || "none"}`);

// Step 2: old code against the candidate, with the noise fields removed.
const INTENDED = new Set(["price"]);
const byClass: Record<string, { pages: number; intended: number; regression: number }> = {};
corpus.forEach((p, i) => {
  const fields = changed(primary[i], candidate(p)).filter((f) => !noise.has(f));
  const kind = fields.length === 0 ? "neutral" : fields.every((f) => INTENDED.has(f)) ? "intended" : "regression";
  const c = (byClass[p.cls] ??= { pages: 0, intended: 0, regression: 0 });
  c.pages++;
  if (kind === "intended") c.intended++;
  if (kind === "regression") c.regression++;
  console.log(`${p.id} (${p.cls}): ${kind}${fields.length ? " [" + fields.join(", ") + "]" : ""}`);
});

// Step 3: the gate. The limit is zero regressions in each page class.
for (const [cls, c] of Object.entries(byClass)) {
  console.log(`${cls}: ${c.pages} pages, ${c.intended} intended, ${c.regression} regression`);
}
const total = Object.values(byClass).reduce((s, c) => s + c.regression, 0);
console.log(total === 0 ? "gate: pass" : `gate: stop the merge (${total} regressions)`);

output

The noise fields, the class of each changed page, the counts for each page class, and the gate result.

noise fields: related
p1 (product): intended [price]
p2 (product): regression [title, price]
a1 (article): regression [title]
a2 (article): regression [title]
a3 (article): neutral
product: 2 pages, 1 intended, 1 regression
article: 3 pages, 0 intended, 2 regression
gate: stop the merge (3 regressions)

The output shows that the volatile field is noise and goes out of the diff. The planted change to the title gives regressions in both page classes, and the gate stops the merge.

data

diff rate by page class: noise and one candidate change

status of this figure: measured by me

diff rate by page class: noise and one candidate changeproduct pages1: 17.6%2: 32%3: 18.4%article pages1: 0%2: 32%3: 32%event pages1: 23.2%2: 42.4%3: 24.8%listing pages1: 0%2: 26.4%3: 26.4%unit: %1. old code against old code2. old code against candidate3. candidate, noise removed

lines: interval, level 0.95

source: Lab result of this course: differential run on a stored corpus of synthetic pages; date 2026-11-13; sample of 500; condition: Synthetic pages, own lab code, one planted candidate. 125 records for each class. Teaching values for one host, not values for a real service.

data table
diff rate by page class: noise and one candidate change
seriespage class%interval
old code against old codeproduct pages17.611.92 to 25.21 (level 0.95)
old code against old codearticle pages00 to 2.98 (level 0.95)
old code against old codeevent pages23.216.67 to 31.33 (level 0.95)
old code against old codelisting pages00 to 2.98 (level 0.95)
old code against candidateproduct pages3224.46 to 40.61 (level 0.95)
old code against candidatearticle pages3224.46 to 40.61 (level 0.95)
old code against candidateevent pages42.434.09 to 51.16 (level 0.95)
old code against candidatelisting pages26.419.46 to 34.75 (level 0.95)
candidate, noise removedproduct pages18.412.59 to 26.1 (level 0.95)
candidate, noise removedarticle pages3224.46 to 40.61 (level 0.95)
candidate, noise removedevent pages24.818.06 to 33.05 (level 0.95)
candidate, noise removedlisting pages26.419.46 to 34.75 (level 0.95)
A differential run on 100 lab pages in 4 page classes. Intervals are Wilson 95%. The candidate is a planted change to the title rule. Noise is a diff of the old code against itself.

The chart is a lab result of this course on synthetic pages, not a value of a real service. Its first series compares the old code with itself. Two page classes show noise, and two show none. After the noise is removed, the planted change still changes records in each page class.

failure modes

problemcausecorrection
The diff report is too long to read.Volatile fields are in the diff.Measure the noise baseline first, and remove the noise fields.
A test fails when the target changes, not when the code changes.The test reads a live page.Use a stored page for each regression test.
A change breaks one page class, and the total looks small.The report gives one total count.Count the changed records for each target class.
A regression passes as noise.The noise baseline ran on a part of the corpus only.Run the old code two times on the full corpus.
A new page form breaks after a later change.The failed input of the case did not go into the corpus.Add the input of each new case to the corpus, with its expected record.
An intended change stops the merge.The change request names no fields.Name the fields of the intended change before the run.

check questions

  1. A test of a change to general code reads a live page, and it fails. What can the cause be?

    1. Only a fault of the new code.
    2. A change of the target or a change of the code, because a live page can change.
    3. Only noise of the old code.
    answer

    b. A change of the target or a change of the code, because a live page can change.

    A live page can change. A stored page does not change, so a diff on it shows a change of the code only.

  2. Explain why you run the old code two times on the full corpus before you compare it with the new code.

    sample answer

    The differences between two runs of the same code on the same input are the noise baseline. They show the volatile fields, for example a field with a random order. You remove these fields from the diff of the new code. Else they fill the diff report, and a regression can hide among them.

  3. A change gives a small total count of changed records, but all of them are in one target class. Which report shows this?

    1. One total count for the corpus.
    2. A count for each target class.
    3. The noise baseline alone.
    answer

    b. A count for each target class.

    A change to one class can hide in a total. A count for each target class shows how far the change reaches.

  4. After the noise fields are removed, a record differs in the field "title". The change request names only the field "price". How do you classify the record?

    1. Intended.
    2. Neutral.
    3. Regression.
    answer

    c. Regression.

    A field that changes and that the change request does not name is a regression. A record that changes only in a noise field is neutral.

  5. The limit is zero regressions in each target class. One class has one regression. What does the gate do?

    1. It stops the merge.
    2. It merges, because the other classes have no regression.
    3. It removes the class from the corpus.
    answer

    a. It stops the merge.

    The gate compares the count of each class with the limit. A count above the limit stops the merge.

exercise

exercise Do this task on paper. Use these synthetic results of a differential run on a stored corpus. The limit is zero regressions in each target class.

recordclassfields that differ, old code against old codefields that differ, old code against new code
r1productupdated timeupdated time, price
r2productnonenone
r3eventupdated timeupdated time
r4eventnonedate, title

The change request names the field "price".

  1. Write the noise fields.
  2. Remove the noise fields from each diff.
  3. Classify each record as intended, neutral, or regression.
  4. Write the count of regressions for each class, and the gate result.
sample answer

The answer uses the four synthetic records of the task.

The noise field is "updated time". After its removal, r1 differs only in "price", which the change request names, thus it is intended. R2 has no change. R3 differs only in a noise field, thus it is neutral. R4 differs in "date" and "title", which the request does not name, thus it is a regression.

The class "product" has zero regressions, and the class "event" has one. The gate stops the merge.

sources

  1. Diffy, opendiffy, source code, read 2026-11-22
  2. Validate and test rules, Elastic, documentation, read 2026-11-22
  3. My model of the differential run on a stored corpus, the three classes of a change, and the gate for each target class, 2026-11 (not public).