skip to content

data pipeline and data quality · lesson 5 of 9 · sources checked 2026-11-22

repair and data poisoning

This lesson withdraws bad rows with a stamp and a predicate on stored evidence, and finds three sources of poisoned data.

status of this lesson: documented in my test system

purpose

Bad rows reach each store, also with good checks. A repair that deletes them or rewrites them also deletes the evidence that a later audit uses. And some bad rows are not an error of the collector at all: a site can change its content on purpose.

objectives

  1. Withdraw bad rows with a quarantine stamp and a predicate that reads stored evidence.
  2. Select the repair for each row type: quarantine, delete, rewrite, or flag.
  3. Write the rules of a safe remediation script.
  4. Identify three sources of poisoned data, and name the check that finds each source.

new terms

predicate
The condition that selects the rows for a repair.
label set
A sample of captures with human labels that measures the error of the oracle.

how it works

A quarantine stamp is a time and a reason on a row. The stamp removes the row from each published rate. To quarantine a row is to set this stamp. The row and its evidence stay in the store.

For example, a row gets the values quarantined_at "t1" and quarantine_reason "false pass: stored body has the block text". Each rate reads only the rows with no stamp.

the row type decides the repair

A repair has four options: quarantine, delete, rewrite, and flag. The row type decides which option is correct:

  • An event row is evidence. It gets a quarantine stamp. A delete or a rewrite loses the evidence.
  • A rolling aggregate is a cache of event rows. When it mixes counts of an old rule, a delete is correct, and a rebuild from the event rows follows.
  • An append-only history row is a dated change. It gets a stamp, never a rewrite, because the rewrite loses the change date.
  • A flag for a later read keeps the row in each rate.

the predicate reads stored evidence

A predicate is the condition that selects the rows for a repair. It must read stored evidence, for example the stored body of a page. A predicate that guesses from a date or a count can stamp good rows.

For example, the predicate "result is pass, and the stored body holds the text of a block signature" finds false passes. Each repair starts with a dry run that only counts the matches. A dry run with zero matches on a known bad row means that the predicate is broken.

a filter that never fired

On the benchmark platform, my test system, each aggregate had a filter for stamped rows. The store had the columns quarantined_at and quarantine_reason. But no script set the stamp, and thus the filter never fired. The cure is a remediation script that sets the stamp from stored evidence.

The rules of such a script are:

  1. A dry run is the default.
  2. A write must have an explicit flag.
  3. The script refuses each database host that is not local.
  4. The script exports each deleted row inside the transaction, before the delete.

three sources of poisoned data

data poisoning is content that a site changes on purpose so that a collector stores wrong values. For example, a site serves a price list in which each price is a little too high. Poisoned data has three sources, each with its own check:

sourcewhat occurscheck that finds it
A site that recognizes the fleetThe site serves a block or plausible but changed dataProven configurations fail together on one site, or a capture differs from a trusted control
A test page that alters the measurementThe page changes the result of each tool that visits itResults keyed by tool and by target disagree on that page only
A third-party source of outcomesRows from a third party mix with measured rowsA provenance column on each row

a fleet burn or a detection change

A fleet burn is a state where a site recognizes the collection fleet and blocks all of its configurations. A configuration is the set of factors of an attempt, for example the client, the address class, and the pace.

The second diagram shows a grid of configurations against sites. A real detection change breaks some results on one site. A fleet burn breaks all proven configurations on one site. A tool break fails one configuration on all sites.

After a fleet burn, the rows of that site since the burn get a stamp. The output is a diagnosis of my own system, a slower pace, a volume cap, the declared path, or a stop at that site.

a capture of high trust

Two values compare a trusted control with a fleet capture of the same page:

  • the structural similarity: a score from 0 to 1 for the structure of the two captures. The code example uses a simpler score in its place: the count of common tag paths, divided by the count of all different tag paths.
  • the semantic divergence: the share of fields whose values differ by more than a limit. The code example also counts a field that the fleet capture does not have.

A high similarity with a high divergence is the sign of poisoned data. For example, the page has the same form, but each price is 10% higher. A low similarity shows a change of the page form. Then the divergence alone does not show poisoning.

a test page that alters the result

A test page can change the result of each tool that visits it. For example, one page gives each tool the same fingerprint result. Thus each result has the key tool and target, and the system publishes the mode of the captures for each pair.

outcomes from a third party

Provenance says where a row comes from: measured by the fleet, reported by a third party, or declared. A rate never pools rows of two kinds of provenance. For example, a reported pass from a third party never goes into a measured pass rate.

labels for the human queue

The success oracle decides if one attempt got the real content. For example, it reads the stored body and finds the product list.

When the oracle cannot decide, it gives the verdict ambiguous, and the attempt goes to a human queue.

A label set is a sample of captures with human labels that measures the error of the oracle.

The chart in the section "Data" shows the share of attempts that go to the human queue in two rule periods. No label came back in either period. Thus the queue cannot measure the error of the oracle.

The cure is to label a random sample of all classes, not only the ambiguous attempts, and to store the labels.

the two sides

automation sidedetection side
Withdraw bad rows with a stamp and a reason. Keep raw evidence, so that a later audit can judge old rows again.A defender can recognize a fleet and serve it a block or plausible but changed data. Proven configurations that fail together on one site are the sign of this response.

design decisions

optiongaincostwhen it is correct
Quarantine with a stamp and a reasonThe evidence stays, and the stamp is reversibleEach rate must filter the stampEvent rows and history rows
DeleteThe table is cleanThe evidence is lostA rolling aggregate that mixes counts of an old rule, with a rebuild from the events
Rewrite the valueThe table shows the new valueThe old value and its date are lostNever for event rows and history rows
A predicate on stored evidence, with a dry runEach stamp has a reason that an audit can read againThe evidence must be storedEach repair
Compare with a trusted controlFinds plausible but wrong valuesA second capture from a channel of high trustA sample of pages, and each site with a suspect pattern
Label a random sample of all classesMeasures the error of the oracleHuman time for each labelEach oracle with a human queue

diagram

The first diagram shows the repair matrix.

A matrix of four repair options against three row types. Quarantine is correct for event rows and history rows. A delete is correct only for a rolling aggregate that mixes counts of an old rule. A rewrite is never correct for event rows and history rows. A flag keeps the row in each rate.

the repair matrix: each repair option against the row type, with its risk
repair optionevent rowrolling aggregatehistory row
Quarantine with a stamp and a reasonCorrect; the evidence staysPossible; a rebuild is betterCorrect; the evidence stays
DeleteNever; the evidence is lostCorrect when old rule counts mixNever; the dated row is lost
Rewrite the valueNever; the old value is lostOnly by a rebuild from eventsNever; the change date is lost
Flag for a later readPossible; rates still use the rowPossible; rates still use the rowPossible; rates still use the row
A delete is correct only for a rolling aggregate that a rebuild from the events can replace.source: My model of the repair of each row type

The second diagram shows the grid of configurations against sites.

A matrix of four configurations against four sites, with pass or fail in each place. All results of site 2 fail. All results of configuration 3 fail. On site 4, configuration 1 also fails. The other results pass.

proven configurations against sites: three patterns of failure
configurationsite 1site 2site 3site 4
Configuration 1passfailpassfail
Configuration 2passfailpasspass
Configuration 3failfailfailfail
Configuration 4passfailpasspass
Site 2 fails for all configurations: a fleet burn. Configuration 3 fails on all sites: a tool break. On site 4, configuration 1 also fails: a detection change.source: My model of the patterns of failure in a grid of configurations and sites

code example

The three examples use synthetic rows and captures. No code sends a request.

The first example runs a quarantine with a dry run, a predicate on the stored body, and a reversible stamp.

m27-x05-dry-run-quarantine.jsjavascript

Run a quarantine with a dry run by default, a predicate on stored evidence, and a reversible stamp. Stop on zero matches.

// A quarantine run with a dry run by default, a reversible stamp, and a
// predicate that reads stored evidence. Synthetic rows only.
const apply = process.argv.includes("--apply");
const signature = process.argv[2] ?? "access denied";

const rows = [
  { id: 1, verdict: "pass", body: "24 product tiles", quarantinedAt: null, reason: null },
  { id: 2, verdict: "pass", body: "Access denied. Reference 0x1", quarantinedAt: null, reason: null },
  { id: 3, verdict: "fail", body: "Access denied.", quarantinedAt: null, reason: null },
  { id: 4, verdict: "pass", body: "access denied for this region", quarantinedAt: null, reason: null },
];

// The predicate reads the stored body, never a guess from a count or a date.
const predicate = (r) =>
  r.verdict === "pass" && r.quarantinedAt === null && r.body.toLowerCase().includes(signature);

const matches = rows.filter(predicate);
console.log(`dry run: signature "${signature}", rows that match: ${matches.map((r) => r.id).join(", ") || "none"}`);
if (matches.length === 0) {
  console.log("zero matches: the predicate is broken, or the evidence is not stored. Stop.");
  process.exit(1);
}
if (!apply) {
  console.log(`${matches.length} rows would get a stamp. Run again with --apply.`);
  process.exit(0);
}
for (const r of matches) {
  r.quarantinedAt = "t1";
  r.reason = `false pass: stored body has "${signature}"`;
}
console.log(`stamped: ${matches.length} rows`);
// A published rate reads only the rows with no stamp.
const live = rows.filter((r) => r.quarantinedAt === null);
const passes = live.filter((r) => r.verdict === "pass").length;
console.log(`pass rate with no stamped rows: ${passes} of ${live.length}`);
// The stamp is reversible: remove it, and the row is back in each rate.
const undo = (r) => { r.quarantinedAt = null; r.reason = null; };
undo(rows[1]);
console.log(`after undo of row 2: ${rows.filter((r) => r.quarantinedAt === null).length} rows without a stamp`);

output

The rows that match, the count of stamped rows, the pass rate with no stamped rows, and the count after an undo.

dry run: signature "access denied", rows that match: 2, 4
stamped: 2 rows
pass rate with no stamped rows: 1 of 2
after undo of row 2: 3 rows without a stamp

The second example holds the rules of a remediation script.

m27-x06-remediation-rules.jsjavascript

Apply the four rules of a safe remediation script to rolling rows of an old rule.

// The rules of a remediation script: a dry run by default, an explicit flag
// for the write, a refusal of each host that is not local, and an export of
// each deleted row inside the transaction. An in-memory store stands in for
// the database. Synthetic rows only.
const args = process.argv.slice(2);
const host = args[0] ?? "";
const write = args.includes("--write");
const LOCAL = new Set(["localhost"]);

if (!LOCAL.has(host)) {
  console.log(`refused: host "${host}" is not local`);
  process.exit(2);
}

// Rolling rows that mix counts of an old rule. The event rows stay.
const store = {
  rolling: [
    { key: "tool-a/page-1", passes: 7, trials: 9, rule: 1 },
    { key: "tool-b/page-1", passes: 3, trials: 4, rule: 2 },
    { key: "tool-a/page-2", passes: 5, trials: 5, rule: 1 },
  ],
};
const predicate = (r) => r.rule === 1;

function transaction(work) {
  const copy = structuredClone(store);
  try {
    work(copy);
    Object.assign(store, copy);
    console.log("commit");
  } catch (e) {
    console.log(`rollback: ${e.message}`);
  }
}

const matches = store.rolling.filter(predicate);
console.log(`host: ${host}; mode: ${write ? "write" : "dry run"}; rows that match: ${matches.length}`);
if (!write) process.exit(0);

const exported = [];
transaction((db) => {
  for (const r of db.rolling.filter(predicate)) exported.push(JSON.stringify(r));
  if (exported.length !== matches.length) throw new Error("export count differs");
  db.rolling = db.rolling.filter((r) => !predicate(r));
});
console.log(`exported rows:\n${exported.join("\n")}`);
console.log(`rolling rows left: ${store.rolling.length}; rebuild them from the event rows`);

output

The mode and the count of matches, the commit, the exported rows, and the count of rows left.

host: localhost; mode: write; rows that match: 2
commit
exported rows:
{"key":"tool-a/page-1","passes":7,"trials":9,"rule":1}
{"key":"tool-a/page-2","passes":5,"trials":5,"rule":1}
rolling rows left: 1; rebuild them from the event rows

The third example compares fleet captures with a trusted control.

m27-x07-control-compare.tstypescript

Compare a fleet capture with a trusted control capture by structural similarity and semantic divergence.

// Compare a fleet capture with a trusted control capture of the same page.
// A structure score: the Jaccard index of the tag paths. It is a simple stand-in for the structural similarity.
// Semantic divergence: the share of fields whose values differ by more than a limit.
// Synthetic captures only.
type Capture = { paths: string[]; fields: Record<string, number> };

const LIMIT = Number(process.argv[2] ?? "0.02");

function jaccard(a: string[], b: string[]): number {
  const A = new Set(a), B = new Set(b);
  const inBoth = [...A].filter((x) => B.has(x)).length;
  return inBoth / new Set([...A, ...B]).size;
}

function divergence(fleet: Capture, control: Capture): number {
  const keys = Object.keys(control.fields);
  const off = keys.filter((k) => {
    const c = control.fields[k], f = fleet.fields[k];
    return f === undefined || Math.abs(f - c) / Math.abs(c) > LIMIT;
  });
  return off.length / keys.length;
}

const control: Capture = {
  paths: ["html/body/main/ul/li", "html/body/main/ul/li/span", "html/body/main/h1"],
  fields: { "price-1": 10.0, "price-2": 20.0, "price-3": 30.0, "price-4": 40.0 },
};
const cases: [string, Capture][] = [
  ["same page", { paths: control.paths, fields: { ...control.fields } }],
  ["changed layout", { paths: ["html/body/div/table/tr", "html/body/main/h1"], fields: { ...control.fields } }],
  ["prices 10% higher", { paths: control.paths, fields: { "price-1": 11.0, "price-2": 22.0, "price-3": 33.0, "price-4": 44.0 } }],
];

for (const [name, fleet] of cases) {
  const s = jaccard(fleet.paths, control.paths);
  const d = divergence(fleet, control);
  const flag = s >= 0.9 && d > 0 ? "suspect poisoning" : s < 0.9 ? "structure change" : "ok";
  console.log(`${name}: similarity ${s.toFixed(2)}, divergence ${d.toFixed(2)}: ${flag}`);
}

output

The similarity, the divergence, and the result for three synthetic captures.

same page: similarity 1.00, divergence 0.00: ok
changed layout: similarity 0.25, divergence 0.00: structure change
prices 10% higher: similarity 1.00, divergence 1.00: suspect poisoning

A run of the second example with a host that is not local stops with the line "refused". A run of the first example with a text that no row holds stops with the line "zero matches".

data

share of attempts that go to the human queue, in two rule periods

status of this figure: measured by me

share of attempts that go to the human queue, in two rule periodsrule period 110.7%rule period 212.2%unit: %

lines: interval, level 0.95

source: Benchmark platform, data (my test system): attempts that go to the human queue, two rule periods; date 2026-11-03; sample of 65,765; condition: An attempt goes to the queue when the oracle cannot decide. The chart n is the sum of the two periods (derived).

data table
share of attempts that go to the human queue, in two rule periods
rule period%interval
rule period 110.710.4 to 11.1 (level 0.95)
rule period 212.211.9 to 12.6 (level 0.95)
Rule period 1 has 30,830 attempts, and rule period 2 has 34,935. No label came back from the human queue in either period. The intervals are at attempt level and too narrow for a comparison.

The chart comes from stored attempts of the benchmark platform. A share of attempts goes to the human queue in each period, but no label comes back. A queue with no labels cannot correct the oracle.

failure modes

problemcausecorrection
The filter for stamped rows never fires.No script sets the stamp.Write a remediation script that sets the stamp from stored evidence.
A repair stamps good rows.The predicate guesses from a date or a count.Write a predicate that reads stored evidence, and start with a dry run.
A repair stamps no row.The predicate is broken, or the evidence is not stored.Treat zero matches on a known bad row as a fault of the predicate.
An audit cannot judge old rows again.The repair deleted or rewrote event rows.Quarantine event rows, and keep the raw evidence.
A script changes the wrong database.The script has no host check and writes by default.Refuse each host that is not local, and write only with an explicit flag.
Wrong values look plausible.A site serves changed data to the fleet.Compare a sample of captures with a trusted control.
One page changes the result of each tool.The results are pooled over all pages.Key each result by tool and by target.
The error of the oracle is unknown.Only ambiguous attempts go to the human queue, and no label comes back.Label a random sample of all classes, and store the labels.

check questions

  1. A dry run of a repair matches zero rows, but you know of a bad row. What does the result mean?

    1. The store has no bad rows
    2. The predicate is broken, or the evidence is not stored
    3. The repair can run with the write flag now
    4. The stamp is already on each row
    answer

    b. The predicate is broken, or the evidence is not stored

    A predicate reads stored evidence. Zero matches on a known bad row show a fault of the predicate or of the stored evidence.

  2. A rolling aggregate mixes counts of an old rule. Which repair is correct?

    1. A quarantine stamp on each event row
    2. A rewrite of the totals by hand
    3. A flag for a later read
    4. A delete with an export, and a rebuild from the event rows
    answer

    d. A delete with an export, and a rebuild from the event rows

    A rolling aggregate is a cache of event rows. A rebuild from the events replaces it, thus a delete loses no evidence.

  3. Give the four rules of a safe remediation script.

    sample answer

    A dry run is the default. A write must have an explicit flag. The script refuses each database host that is not local. The script exports each deleted row inside the transaction, before the delete.

  4. Name three sources of poisoned data, and the check that finds each source.

    sample answer

    A site that recognizes the fleet: proven configurations fail together on one site, or a capture differs from a trusted control. A test page that alters the measurement: results keyed by tool and by target disagree on that page only. A source of outcomes with no attribution: a provenance column on each row.

  5. A fleet capture has the same tag paths as the trusted control, but each price differs. What does this show?

    1. Possible poisoned data
    2. A change of the page form
    3. A tool break
    4. A correct capture
    answer

    a. Possible poisoned data

    A high structural similarity with a high semantic divergence is the sign of poisoned data. A change of the page form gives a low similarity.

exercise

exercise Do this task on paper. The rows are synthetic. The block text is "access denied".

rowrow typeverdictstored body
1Event rowpass12 product tiles
2Event rowpassAccess denied
3Rolling aggregate(a total of an old rule)none
4Event rowfailAccess denied

A grid of 3 configurations against 3 sites has these results:

configurationsite 1site 2site 3
1passfailpass
2passfailpass
3passfailpass
  1. Write the predicate for false passes.
  2. Write the rows that a dry run matches.
  3. Write the repair for each matched row and for row 3.
  4. Write the diagnosis of the grid, and the output for site 2.
sample answer

The answer uses the repair matrix and the grid patterns of "How it works".

The predicate is "verdict is pass, and the stored body holds the block text". The dry run matches row 2 only. Row 4 is a fail, thus it is not a false pass.

Row 2 is an event row, thus it gets a quarantine stamp with the reason "false pass". Row 3 mixes counts of an old rule. Thus a delete is correct, with an export of the row inside the transaction and a rebuild from the event rows.

All configurations fail on site 2 only. This is the pattern of a fleet burn. The rows of site 2 since the burn get a stamp. The output for site 2 is a diagnosis of your own system, a slower pace, a volume cap, the declared path, or a stop.

sources

  1. My model of the repair of each row type, the three sources of poisoned data, and the grid of configurations and sites, 2026-11 (not public).
  2. Benchmark platform, design (my test system): the quarantine columns and the filter for stamped rows, 2026-11 (not public).
  3. Benchmark platform, data (my test system): attempts that go to the human queue, two rule periods, 2026-11 (not public).