general code and the edge-case tail · lesson 4 of 9 · sources checked 2026-11-30
the unknown class and the review loop
This lesson gives each classifier a closed list with an unknown member, and a queue that an owner works at a fixed interval.
status of this lesson: documented in my test systempurpose
A classifier that guesses on an input that it does not know gives a wrong result with no warning. The wrong result looks like a correct one, and nobody finds it. An explicit unknown class makes each such input visible, and a queue with an owner turns it into a rule.
objectives
- Build a closed output list with an unknown member, and name the part that emits each pattern.
- Explain the difference between the unknown policy of verdict code and of dispatch code.
- Write the cost of a wrong guess and of an unknown result for one classifier.
- Set an alarm on the unknown rate with a sample floor.
- Describe the four parts of a queue rule for the unknown queue.
new terms
how it works
A classifier reads one input and gives one class from a closed list. A closed list holds each class that the classifier can give, and no other. The last member of the list is "unknown". The classifier gives it when no rule matches.
two policies for an unknown input
I use two policies, one for each kind of code:
- Verdict code gives a verdict or a class that other parts trust. Examples are an error classifier and the reader of a page form. When no rule matches, it refuses to guess. It returns the unknown member, and it stores the input.
- Dispatch code chooses one path, for example a parser for each format. The work must continue. Thus the switch has a default arm that records "not covered". A silent default arm is the fault: it takes the absent case and records nothing.
For example, a lab error "request timed out after 3000 ms (stream closed)" is near the class "timeout". It does not match the timeout rule. Verdict code returns unknown, because the stream close can have a different cause.
the closed list on the benchmark platform
The error classifier of the benchmark platform, my test system, gives one reason from a closed list, or no class. For an error that no rule matches, it returns no class. The closed list starts in Reconstruct why an attempt failed: the class and the evidence chain (not yet published).
The platform records show faults of this kind. A tool can give no rows and no error class. The correction is a function that fills the default from catalog data, and a classifier that knows the old error shape.
what to store with an unknown input
A stored unknown input is evidence for the next rule. Store the input, each facet of the response, and the version of the configuration. For example, the record "empty body with status 200" keeps the status, the body size, and the configuration name. A record with no facets cannot go into a cluster later.
A tolerant extractor can give a partial record on an unknown page. Thus make the extractor tolerant only when it can parse the page, and give the output step a fail closed design.
The output step can quarantine the record for a later review.
the cost of each wrong answer
Write two costs for each classifier before you set its policy:
- the cost of a wrong guess: for example, a false record reaches a customer, or a false verdict reaches a rate;
- the cost of an unknown result: one item in the queue, and one review.
When the first cost is higher, the classifier refuses. A detection classifier has the same choice. A guess on an unknown client can give a false positive on a real user.
the alarm on the unknown rate
The unknown rate is the count of unknown results divided by the count of attempts in one day. An alarm fires when the rate is over a limit. It must have a sample floor: with few attempts, one unknown result gives a high rate. For example, with a floor of 40 attempts, a day with 30 attempts gives no decision.
the queue rule
An unknown result goes to a review queue. A queue with no owner grows until nobody reads it. The platform records show such a queue for unknown detectors. That queue has no owner, no fixed interval, and no path to a rule. The queue rule below closes these gaps.
The queue rule has four parts:
- An owner: one person or team.
- A fixed interval for the review, for example each seventh day.
- Clusters: the owner reviews groups of similar inputs, not single items.
- A path for each cluster. The path is a new rule with a test, an entry on the exclusion list, or a wait.
The full design of the queue is in Operate a review queue (not yet published).
the two sides
| automation side | detection side |
|---|---|
| An unknown page form must not give a partial record to the customer. The record goes to quarantine, and the input goes to the review queue. | A detection classifier that guesses on an unknown client gives false positives on real users. An explicit unknown class with a review queue keeps that cost visible. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| Guess the nearest class | No queue to work | A wrong result looks correct. | Never in verdict code |
| Return unknown and store the input | Each new form becomes visible. | The queue must have an owner. | For verdict code |
| Default arm that records "not covered" | The work continues, and the gap has a count. | The record of each case is short. | For dispatch code |
| Silent default arm | No code for an absent case | The gap has no record. | Never |
| Review clusters at a fixed interval | One review closes many items. | Rare items wait. | When the queue has an owner |
diagram
The first diagram compares the two policies.
A matrix of two columns, verdict code and dispatch code, against five rows. The rows are an example, the action when no rule matches, the record, the effect, and the next step. Verdict code returns the unknown member and sends the item to the queue. Dispatch code takes the default arm and sends a count to the alarm.
| question | verdict code | dispatch code |
|---|---|---|
| Example | error classifier, page form reader | switch over formats or methods |
| When no rule matches | refuse: return the unknown member | take the default arm |
| What it records | the input, its facets, its config | one not covered record |
| Effect on the work | no record goes out | the work continues |
| Next step | the item goes to the unknown queue | the count goes to the alarm |
The second diagram shows the path of an item through the queue.
the unknown queue from capture to a decision
code example
The first example is a classifier with a closed list. Each pattern names the part that emits the error. The errors are synthetic lab lines.
Classify synthetic lab errors with a closed list, return null for an unknown error, and send it to the queue with its facets.
// A closed list of error classes. Each pattern names the part that emits the error.
type ErrorClass = "timeout" | "tool-did-not-start" | "field-missing" | "status-5xx";
type Pattern = { cls: ErrorClass; emitter: string; test: RegExp };
const PATTERNS: Pattern[] = [
{ cls: "timeout", emitter: "http client", test: /^request timed out after \d+ ms$/ },
{ cls: "tool-did-not-start", emitter: "tool launcher", test: /^launch failed: exit code \d+$/ },
{ cls: "field-missing", emitter: "extractor", test: /^no record: field "[a-z]+" missing$/ },
{ cls: "status-5xx", emitter: "http client", test: /^status 5\d\d$/ },
];
type Known = { cls: ErrorClass; emitter: string };
// The classifier returns null when no pattern matches. It never guesses.
function classify(message: string): Known | null {
for (const p of PATTERNS) {
if (p.test.test(message)) return { cls: p.cls, emitter: p.emitter };
}
return null;
}
// An unknown input goes to the queue with its facets and its configuration version.
type QueueItem = { message: string; facets: Record<string, string>; config: string };
const queue: QueueItem[] = [];
// Synthetic errors of a lab collector. No line comes from a real system.
const errors = [
{ message: "request timed out after 3000 ms", facets: { status: "none" } },
{ message: "status 503", facets: { status: "503" } },
{ message: 'no record: field "price" missing', facets: { status: "200" } },
{ message: "request timed out after 3000 ms (stream closed)", facets: { status: "none" } },
{ message: "launch failed: exit code 1", facets: { status: "none" } },
{ message: "empty body with status 200", facets: { status: "200", bytes: "0" } },
];
for (const e of errors) {
const r = classify(e.message);
if (r) {
console.log(`${r.cls.padEnd(18)} ${("from " + r.emitter).padEnd(18)} <- ${e.message}`);
} else {
queue.push({ message: e.message, facets: e.facets, config: "lab-config-7" });
console.log(`${"unknown".padEnd(18)} ${"to the queue".padEnd(18)} <- ${e.message}`);
}
}
const rate = (100 * queue.length) / errors.length;
console.log(`unknown: ${queue.length} of ${errors.length} (${rate.toFixed(1)}%)`);
console.log(`first queue item: ${JSON.stringify(queue[0])}`);output
One line for each error, the unknown count, and the first queue item.
timeout from http client <- request timed out after 3000 ms
status-5xx from http client <- status 503
field-missing from extractor <- no record: field "price" missing
unknown to the queue <- request timed out after 3000 ms (stream closed)
tool-did-not-start from tool launcher <- launch failed: exit code 1
unknown to the queue <- empty body with status 200
unknown: 2 of 6 (33.3%)
first queue item: {"message":"request timed out after 3000 ms (stream closed)","facets":{"status":"none"},"config":"lab-config-7"}The output shows that the line with "stream closed" goes to the queue, and not to the class "timeout".
The second example is the alarm on the unknown rate, with a sample floor. It reads a synthetic lab table.
Compute the daily unknown rate of a synthetic lab table, and give an alarm only on a day at or over the sample floor.
// Unknown-rate alarm with a sample floor, on a synthetic lab table.
// Each row is one attempt. errorClass is null for a success, a class of the
// closed list for a known error, and "unknown" when no rule matches.
type Attempt = { day: number; errorClass: string | null };
const SAMPLE_FLOOR = 40; // example value: attempts in one day
const LIMIT_PCT = 10; // example value: alarm limit in percent
// Make the synthetic table: [day, attempts, unknown results, known errors].
const plan: [number, number, number, number][] = [
[3, 60, 9, 4],
[1, 25, 5, 1],
[2, 90, 6, 3],
[4, 44, 4, 2],
];
const table: Attempt[] = [];
for (const [day, attempts, unknowns, known] of plan) {
for (let i = 0; i < attempts; i++) {
const errorClass = i < unknowns ? "unknown" : i < unknowns + known ? "timeout" : null;
table.push({ day, errorClass });
}
}
const daily = new Map<number, { attempts: number; unknowns: number }>();
for (const a of table) {
const d = daily.get(a.day) ?? { attempts: 0, unknowns: 0 };
d.attempts += 1;
if (a.errorClass === "unknown") d.unknowns += 1;
daily.set(a.day, d);
}
console.log("day,attempts,unknowns,unknown_pct,state");
for (const day of [...daily.keys()].sort((x, y) => x - y)) {
const { attempts, unknowns } = daily.get(day)!;
const pct = (100 * unknowns) / attempts;
const state =
attempts < SAMPLE_FLOOR ? "no decision: below the sample floor" : pct > LIMIT_PCT ? "alarm" : "ok";
console.log(`${day},${attempts},${unknowns},${pct.toFixed(1)},${state}`);
}output
One row for each day in day order: the attempts, the unknown results, the unknown rate, and the state.
day,attempts,unknowns,unknown_pct,state
1,25,5,20.0,no decision: below the sample floor
2,90,6,6.7,ok
3,60,9,15.0,alarm
4,44,4,9.1,okThe output shows that day 1 has the highest rate, but it gives no decision, because its attempts are below the floor.
data
unknown rate of page runs on each seventh lab day, with the alarm line
status of this figure: measured by me
band: interval, level 0.95
source: Lab result of this course: own lab collector, one run of 120 lab days; date 2026-11-13; sample of 1,332; condition: Seed 1 of 5. The review labels come from the true page form, not from a person. The n is the sum of the runs of the 18 points. Teaching values for one host.
data table
| lab day | % | interval |
|---|---|---|
| day 0 | 0 | 0 to 79.35 (level 0.95) |
| day 7 | 17.65 | 6.19 to 41.03 (level 0.95) |
| day 14 | 13.79 | 5.5 to 30.56 (level 0.95) |
| day 21 | 8.82 | 3.05 to 22.96 (level 0.95) |
| day 28 | 4.65 | 1.28 to 15.46 (level 0.95) |
| day 35 | 6.45 | 2.54 to 15.45 (level 0.95) |
| day 42 | 6.94 | 3 to 15.25 (level 0.95) |
| day 49 | 2.44 | 0.67 to 8.46 (level 0.95) |
| day 56 | 3.26 | 1.12 to 9.15 (level 0.95) |
| day 63 | 2 | 0.55 to 7 (level 0.95) |
| day 70 | 1 | 0.18 to 5.45 (level 0.95) |
| day 77 | 1 | 0.18 to 5.45 (level 0.95) |
| day 84 | 2 | 0.55 to 7 (level 0.95) |
| day 91 | 4 | 1.57 to 9.84 (level 0.95) |
| day 98 | 0 | 0 to 3.7 (level 0.95) |
| day 105 | 2 | 0.55 to 7 (level 0.95) |
| day 112 | 2 | 0.55 to 7 (level 0.95) |
| day 119 | 3 | 1.03 to 8.45 (level 0.95) |
The chart is a lab result of this course, not a value of a real service. It shows the unknown rate fall under the alarm line after the first reviews. The review labels in the lab come from the true page form, with no person and no delay. Thus the fall is a best case.
failure modes
| problem | cause | correction |
|---|---|---|
| A new page form gives a partial record to a customer. | The extractor is tolerant also at the output step. | Fail closed at the output step, and quarantine the record. |
| A new error goes into the nearest class. | The classifier guesses when no rule matches. | Return the unknown member, and store the input. |
| An absent format gives no record. | The switch has a silent default arm. | Record "not covered" in the default arm, and count it. |
| The unknown queue grows, and nobody reads it. | The queue has no owner and no fixed interval. | Give it an owner, a fixed interval, and clusters. |
| The alarm fires on a quiet day. | The alarm has no sample floor. | Give no decision below the floor. |
| A reviewed cluster cannot become a rule. | The stored items have no facets or configuration. | Store the facets and the configuration version with each item. |
check questions
An error classifier with a closed list gets the line "request timed out after 3000 ms (stream closed)". No pattern matches it exactly. What does verdict code return?
- The class timeout, because it is the nearest class.
- The unknown member, and it stores the input with its facets.
- No result, and it deletes the input.
answer
b. The unknown member, and it stores the input with its facets.
Verdict code refuses to guess. It returns the unknown member and stores the input, so that the owner of the queue can review it.
Explain the difference between the unknown policy of verdict code and the unknown policy of dispatch code.
sample answer
Verdict code gives a result that other parts trust. When no rule matches, it returns the unknown member and stores the input, and no record goes out. Dispatch code must let the work continue. It takes a default arm that records "not covered", and the count goes to the alarm. A silent default arm records nothing, and that is the fault.
For one classifier, a wrong guess sends a false record to a customer. An unknown result adds one item to the queue. Which policy is correct?
- Guess, because the queue costs time.
- Use a silent default arm.
- Refuse and return unknown, because the cost of a wrong guess is higher.
answer
c. Refuse and return unknown, because the cost of a wrong guess is higher.
When the cost of a wrong guess is higher than the cost of one review, the classifier refuses and returns the unknown member.
The sample floor is 40 attempts and the limit is 10%. A day has 25 attempts and 5 unknown results. What does the alarm give?
- No decision, because the day is below the sample floor.
- An alarm, because the rate is 20%.
- Ok, because 5 results are few.
answer
a. No decision, because the day is below the sample floor.
Below the sample floor, one unknown result gives a high rate. Thus the alarm gives no decision for that day.
Describe the four parts of a queue rule for the unknown queue.
sample answer
An owner, which is one person or team. A fixed interval for the review, for example each seventh day. Clusters, so that the owner reviews groups of similar inputs. A path for each cluster: a new rule with a test, an entry on the exclusion list, or a wait.
exercise
exercise Do this task on paper. Use the synthetic daily counts of a lab collector. The sample floor is 40 attempts, and the alarm limit is 10%.
| day | attempts | unknown results |
|---|---|---|
| 1 | 30 | 6 |
| 2 | 120 | 9 |
| 3 | 80 | 12 |
| 4 | 50 | 4 |
| 5 | 45 | 6 |
- Compute the unknown rate of each day.
- Mark each day below the sample floor as "no decision".
- Mark each other day as "alarm" or "ok".
- Write the four parts of the queue rule for the owner of this queue.
sample answer
The answer uses the five synthetic days of the task.
Day 1 has 20.0%, but 30 attempts are below the floor, thus it gives no decision. Day 2 has 7.5% and is ok. Day 3 has 15.0% and gives an alarm. Day 4 has 8.0% and is ok. Day 5 has 13.3% and gives an alarm.
The queue rule has one owner, a review each seventh day, and clusters of similar inputs. Each cluster gets a new rule with a test, an entry on the exclusion list, or a wait.
sources
- Benchmark platform, code (my test system): the closed list of error reasons, and no class for an unknown error, 2026-11 (not public).
- Benchmark platform, code (my test system): the fault of an empty field, and a queue with no owner, 2026-11 (not public).
- My model of the two unknown policies and of the cost of each wrong answer, 2026-11 (not public).
- My model of the queue rule, 2026-11 (not public).