CSE Roadmap

Core tier · about 6 hours · 13 parts

Part 4 of 13 · 2 min read

A rule's precision is where it hurts, and the right threshold is a cost trade-off

A detector that never misses a real fault is worthless if it also screams about half of everything that's perfectly fine.

Think of a smoke detector so sensitive it goes off every time you make toast. Technically it never misses a real fire. But everyone starts ignoring it, which defeats the entire point of having one.

In plain words: precision is the share of a detector's flagged traces that truly have the fault, recall is the share of truly faulty traces it catches, and the two trade off against each other through a threshold — a wider net (a lower bar to flag something) catches more real faults but also catches more harmless look-alikes, so the right threshold is chosen by weighing the cost of a missed fault against the cost of a false alarm, not by picking the number that looks best on a single metric.

A worked example. A first version of the retry-storm rule flagged any run of 3+ identical consecutive tool calls, with no regard for whether they succeeded — this gave it precision of only 0.48, because a plan loop also produces repeated identical-looking tool calls but isn't a retry storm at all. Requiring the repeated calls to specifically be failing ones raised precision to 1.00 with no loss of recall. Separately, the latency-spike rule's threshold directly trades the two off: at 2 times the median duration, precision is just 0.07 (almost everything flagged is a false alarm) with recall 1.00; at 8 times the median, precision rises to 0.99 but recall falls to 0.81 (some real spikes are missed).

The key lines. From code/mini-debug/detect.py:

# from code/mini-debug/detect.py
def retry_storm(t, k=3, errors_only=True):
    """k or more identical consecutive tool calls. v1 (errors_only=False) also fires on plan loops, whose tool
    calls are identical but succeed; v2 requires the repeated calls to be failing ones."""
    run, best, prev = 0, 0, None
    for s in tool_spans(t):
        if errors_only and s.status != "error":
            run, prev = 0, None
            continue

Read it as: the docstring names the exact false-positive source before the code even runs. The fix was not a cleverer algorithm. It was one added condition (errors_only) that encodes the actual distinction between the two causes that share a symptom. You only find that kind of fix by reading what a rule gets wrong, not by reading what it gets right.

Precision and recall of a detector

Precision is, of the traces a detector flags, the share that truly have the fault. Recall is, of the traces that truly have the fault, the share the detector flags.

Example: the retry-storm rule's jump from 0.48 to 1.00 precision, with recall unchanged at 1.00, is what a genuine fix to a detector looks like — recall didn't have to be sacrificed to buy the precision gain, because the added condition targeted exactly the false-positive source and nothing else.