skip to content

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

the override layer

This lesson gives each special case its place in data, in an adapter, or in general code, with one precedence order and a generic fallback.

status of this lesson: from a public source

purpose

A special case in the wrong place makes the next change hard. A branch on a site name in general code grows until a fix for one site breaks a different site. A fixed place for each kind of special case keeps the general code clean and each special case easy to find and remove.

objectives

  1. Select the place of a special case: a data row, a behavior flag, an adapter, or a general rule.
  2. Write an override with a scope, an owner, an evidence reference, an expiry, and a hit counter.
  3. Compute the effective value of a behavior with a precedence order.
  4. Explain why a generic fallback returns an explicit unsupported result and not a weak success.

new terms

behavior flag
A named behavior in a table that a target turns on, so that general code asks about the behavior and not about the target.
override precedence
The order of scopes that gives one effective value when more than one override matches.
generic fallback
The last adapter, which tries general methods and returns an explicit unsupported result when it finds nothing.

how it works

A special case has four possible places. The rule is simple: put each special case in the cheapest place that can hold it.

placewhat goes thereexample
Data rowA changed valueA date format for one target class
Behavior flagA named behavior that a target turns onprice-in-meta
AdapterNew logic for one target or one classA second request for the price
General ruleA change that is correct for each targetA parser that accepts a comma and a point

data first

A changed value goes into data, never into code. The data file has a schema and a version. Thus a change of a value is a change of data, and a test can read the file.

An override is such a data entry. It changes one value for one scope.

Each override holds a behavior ID, a scope, a value, an owner, a reason, an evidence reference, an expiry date, and a hit counter. For example, an override sets the decimal mark to a comma for one target class, with an expiry at the end of the quarter.

ask about a behavior, not about a target

A behavior flag names what a target does. The general code asks about the flag:

  • Wrong: if (target === "lab-target-b").
  • Correct: if (flags.has("price-in-meta")).

The first form grows with each target, and nobody can see why each branch exists. The second form has one branch for each behavior.

A new target with the same behavior gets one data row and no code change. For example, a second target with the price in a meta element gets the flag price-in-meta, and the code does not change.

adapters for new logic

New logic, for example a second request for a price, goes into an adapter. The adapter is behind a small contract. Its mandatory outputs must be present, or the record fails. Its optional outputs can be absent, and they fail softly with an empty field. The full contract of an adapter is the site adapter contract of The adapter contract and templates by target class.

one effective value

Two or more overrides can match one request. The override precedence gives one effective value. I use five scopes, from the weakest to the strongest: default, target class, target, path, and run. The most specific scope that matches wins.

For example, the class override sets a comma, and the target override sets a point. A request to that target gets the point. A request to a different target of the class gets the comma.

the generic fallback

The generic fallback is the last adapter. It tries general methods. When it finds nothing, it returns an explicit unsupported result. It never returns a partial record as a success, because a weak success hides the edge case from each count and each alarm.

For example, a page has no price that the general methods can find. The fallback returns unsupported with the reason "no price". The record then goes to the queue of unknown cases, not to the customer.

the two sides

automation sidedetection side
A behavior table keeps the general code clean. A branch on a target name grows until a fix for one target breaks a different target. Overrides as data, with one precedence order, give one effective value that a test can check.A detection rule set has the same places: a general rule, an exception for one environment, and a threshold. Tune a rule that is too broad for all traffic. Add an exception only for one known-safe source.

design decisions

optiongaincostwhen it is correct
A branch on a target nameFast to writeIt grows with each target, and a fix for one target can break a different target.Never in general code
A data row with a schemaA value change is not a code change.The schema must hold the value.For a changed value
A behavior flagOne branch for each behavior, not for each targetSomeone must name the behavior.When two or more targets can show the behavior
An adapter behind a contractNew logic stays out of the general code.Each adapter is code to keep.For new logic for one target or one class
One precedence orderOne effective value for each requestAll overrides must use the same scopes.Always, when overrides exist
A generic fallback with unsupportedEach failure is visible and counted.The customer sees an explicit gap.Always, as the last adapter

diagram

The first diagram shows the places of a special case. The second diagram shows the precedence order.

where a special case lives, from the cheapest place to the last result

  1. Data rowA changed value, for example a date format, in a data file with a schema and a version.
  2. Behavior flagA named behavior that a target turns on. General code asks about the behavior, not about the target.
  3. AdapterNew logic for one target or class, behind a small contract with mandatory outputs and optional outputs that fail softly.
  4. General ruleA change of the general code that is correct for each target of the class.
  5. Generic fallbackThe last adapter. It tries general methods and returns an explicit unsupported result when it finds nothing.

One record, or an explicit unsupported result, never a weak successpass

Each special case goes to the first place that can hold it, and the fallback never returns a weak success.source: My model of the places of a special case

the precedence stack: the most specific matching scope gives the effective value

  1. RunAn override for one run only. It wins over each scope below it.
  2. PathAn override for one path form, for example the archive pages.
  3. TargetAn override for one target.
  4. Target classAn override for each target of one class.
  5. DefaultThe value of the general code when no override matches.

One effective value for each behavior and each requestpass

The most specific scope that matches the request gives the value.source: My model of override precedence

code example

The example holds four synthetic overrides of one behavior, a resolver, and an expiry test. All target names are lab names. The evidence field holds the ID of a stored capture.

m53-x04-overrides.tstypescript

An override schema with its fields, a resolver for the effective value, and a test that fails after the expiry.

// Overrides as data: a schema, a resolver, and an expiry test. All names are lab names.
type Scope = "default" | "class" | "target" | "path" | "run";
const PRECEDENCE: Scope[] = ["default", "class", "target", "path", "run"]; // later wins

type Override = {
  behavior: string; // behavior ID, for example "decimal-mark"
  scope: Scope;
  match: string; // the class, target, path, or run that the scope names
  value: string;
  owner: string;
  reason: string;
  evidence: string; // ID of the stored capture that shows the behavior
  expires: string; // ISO date
  hits: number; // hit counter: times that the override changed a result
};
type Request = { targetClass: string; target: string; path: string; run: string };

function resolve(all: Override[], behavior: string, req: Request): Override | undefined {
  const key: Record<Scope, string> = { default: "*", class: req.targetClass, target: req.target, path: req.path, run: req.run };
  const matches = all.filter((o) => o.behavior === behavior && o.match === key[o.scope]);
  matches.sort((a, b) => PRECEDENCE.indexOf(a.scope) - PRECEDENCE.indexOf(b.scope));
  return matches.at(-1);
}

// The test fails for each override that is past its expiry date.
function expiryTest(all: Override[], today: string): string[] {
  return all.filter((o) => o.expires <= today).map((o) => `${o.behavior}/${o.scope}/${o.match} expired on ${o.expires} (owner ${o.owner})`);
}

const overrides: Override[] = [
  { behavior: "decimal-mark", scope: "default", match: "*", value: ".", owner: "team-a", reason: "general rule", evidence: "none", expires: "2099-01-01", hits: 0 },
  { behavior: "decimal-mark", scope: "class", match: "shop-eu", value: ",", owner: "team-a", reason: "class uses a comma", evidence: "cap-101", expires: "2026-09-30", hits: 412 },
  { behavior: "decimal-mark", scope: "target", match: "lab-target-b", value: ".", owner: "team-b", reason: "target uses a point", evidence: "cap-117", expires: "2026-05-31", hits: 3 },
  { behavior: "decimal-mark", scope: "path", match: "/archive", value: ",", owner: "team-b", reason: "old pages", evidence: "cap-120", expires: "2026-12-31", hits: 0 },
];

const today = process.argv[2] ?? "2026-06-01";
const requests: Request[] = [
  { targetClass: "shop-eu", target: "lab-target-a", path: "/item", run: "r7" },
  { targetClass: "shop-eu", target: "lab-target-b", path: "/item", run: "r7" },
  { targetClass: "shop-eu", target: "lab-target-b", path: "/archive", run: "r7" },
  { targetClass: "shop-na", target: "lab-target-c", path: "/item", run: "r7" },
];
for (const r of requests) {
  const o = resolve(overrides, "decimal-mark", r);
  console.log(`${r.target}${r.path}: "${o?.value}" from scope ${o?.scope}`);
}
const failed = expiryTest(overrides, today);
console.log(`expiry test on ${today}: ${failed.length === 0 ? "pass" : "fail"}`);
for (const f of failed) console.log(`  ${f}`);

output

The effective value and its scope for four requests, and the result of the expiry test.

lab-target-a/item: "," from scope class
lab-target-b/item: "." from scope target
lab-target-b/archive: "," from scope path
lab-target-c/item: "." from scope default
expiry test on 2026-06-01: fail
  decimal-mark/target/lab-target-b expired on 2026-05-31 (owner team-b)

The output shows that each request gets one value from the most specific scope that matches. The expiry test fails for the target override, and it names the owner who must renew or remove it.

data

block signature data in an early and a late period

status of this figure: documented in my test system

block signature data in an early and a late periodmarker entries1: 142: 14vendor rows1: 62: 6marker groups1: 12: 3ordered steps1: 42: 6unit: items1. early2. late

source: Benchmark platform, code (my test system): block signature data, early and late; date 2026-11-16; sample of 5; condition: The n is the count of changes after the first build of the block signatures. The middle period has one value only (5 steps) and stays out.

data table
block signature data in an early and a late period
serieskind of itemitems
earlymarker entries14
earlyvendor rows6
earlymarker groups1
earlyordered steps4
latemarker entries14
latevendor rows6
latemarker groups3
lateordered steps6
The count of entries stays flat. The groups of markers and the ordered steps grow. Early, the markers are in one list. Late, they are in three classes.

The first chart comes from the code of the benchmark platform, my test system. The special cases of one component moved into data with more structure, and the count of entries did not grow.

f-scores of four generic content extractors on one public evaluation set

status of this figure: from a public source

f-scores of four generic content extractors on one public evaluation setextractor 10.926extractor 20.853extractor 30.807extractor 40.803unit: F-score

source: Public evaluation page of an open-source content extractor (public source, https://trafilatura.readthedocs.io/en/latest/evaluation.html, read 2026-11-12); date 2026-11-12; sample of 990; condition: One mixed evaluation set of documents. The numbers are the F-scores that the page gives for the generic path.

data table
f-scores of four generic content extractors on one public evaluation set
extractorF-score
extractor 10.926
extractor 20.853
extractor 30.807
extractor 40.803
A public evaluation of four extractors on 990 documents. The extractor numbers are local to this chart. The chart is not a ranking of products. The values are a statement of the publisher of the evaluation.

No generic extractor in the second chart gets a full score. Thus the general path must have a generic fallback with an explicit result for the pages that it cannot read.

failure modes

problemcausecorrection
A fix for one target breaks a different target.The general code branches on target names.Move the value into data, or name the behavior with a flag.
Two overrides give two values for one request.The overrides have no precedence order.Use one order of scopes, and let the most specific scope win.
An override stays after its cause goes away.The override has no owner and no expiry.Give each override an owner and an expiry, and run the expiry test.
The customer gets records with empty mandatory fields.The fallback returns a partial record as a success.Return an explicit unsupported result from the generic fallback.
An adapter holds a changed value only.The team put a data change in code.Put a changed value in a data row, and keep adapters for new logic.

check questions

  1. A target writes its dates with the day first. Each other target of its class writes them with the year first. Where does this special case go?

    1. A branch on the target name in the general code
    2. A new adapter for the target
    3. A data row or an override for the target
    4. The generic fallback
    answer

    c. A data row or an override for the target

    A changed value goes into data, never into code. An adapter is for new logic, and a branch on a target name grows with each target.

  2. List the fields of an override, and say why it has an expiry and a hit counter.

    sample answer

    An override holds a behavior ID, a scope, a value, an owner, a reason, an evidence reference, an expiry date, and a hit counter. The expiry makes the owner renew or remove the override. The hit counter shows if the override still changes results.

  3. A class override sets a comma as the decimal mark. A path override for the archive pages sets a point. A request goes to an archive page of a target of that class. What is the effective value?

    1. A point, because the path scope is more specific than the class scope
    2. A comma, because the class override comes first
    3. No value, because two overrides match
    answer

    a. A point, because the path scope is more specific than the class scope

    The precedence order gives one effective value. The most specific scope that matches wins, and the path scope is more specific than the target class.

  4. Explain why the generic fallback returns an explicit unsupported result when it finds nothing.

    sample answer

    A partial record that passes as a success hides the edge case from each count and each alarm. The customer then gets empty fields with no warning. An explicit unsupported result is visible and counted, and the record goes to the queue of unknown cases.

exercise

exercise Do this task on paper with the synthetic overrides and requests below. Today is 2026-06-01. The precedence order is default, target class, target, path, run: the most specific scope that matches wins.

overridescopematchvalue of the date orderexpiry
1defaulteach requestyear first2099-01-01
2target classnews-euday first2026-12-31
3targetlab-target-dmonth first2026-04-30
4runrun r9year first2026-07-01
requesttarget classtargetrun
Anews-eulab-target-er8
Bnews-eulab-target-dr8
Cnews-nalab-target-fr9
  1. Find the overrides that match each request.
  2. Write the effective value of each request.
  3. Write the overrides that fail the expiry test today.
sample answer

The answer uses the four overrides and the three requests of the task.

Request A matches overrides 1 and 2, and the class scope wins: day first. Request B matches overrides 1, 2, and 3, and the target scope wins: month first. Request C matches overrides 1 and 4, and the run scope wins: year first.

Override 3 expired on 2026-04-30, thus it fails the expiry test today. Its owner must renew it with new evidence or remove it.

sources

  1. My model of the places of a special case, of override precedence, and of the generic fallback, 2026-11 (not public).