Skip to content

fix(matching): a 4x-overstated block size, and the u pre-flight re-derived from what the sampler actually does - #596

Merged
athvin merged 1 commit into
mainfrom
bm/profile-u-measurability
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/profile-u-measurability

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Two things in the publish advisories, both found by checking a claim against the code rather than against its comment.

The block-size number was wrong

dedupe_core::profile::top_values divides by count(<col>), so a mode's share is over the column's populated rows. The skew advisory multiplied it by row_count, which overstates the block by 1/fill and the comparisons by 1/fill² because the count is squared.

On a half-populated column it reported 799,980,000 comparisons where the truth is 199,990,000. Every existing test used a fully populated column, where fill is 1 and the mistake cannot show — so the new test uses a half-empty one, and was observed failing against the old arithmetic before the fix went in.

The u pre-flight needed its motivation rebuilt

It was specified against a hazard that does not exist: that a comparison level the u-sample never observes normalizes to a sentinel read as u = 1e-6, producing a large spurious match weight.

It does not. estimate_u records ProbEstimate::NotObserved, populate_from_trained_values filters those out, and the slot is left alone so the level falls back to its built-in default — which is deliberate and better than a sentinel. A stale doc comment outlived the variant it described, and a design note took it as fact.

The real cost is quieter, and worth saying: nobody is told when a level's u came from a prior instead of from their data. For most levels the default is a considered position on the ladder. For an exact level it can be far off, because the true u of an equality is the corpus's own collision probability.

So profile_advisories now names the exact levels this corpus cannot supply:

comparison email declares an exact level, and at u_max_pairs = 1000000 the u-sample examines about 1000000 pairs — with 50000 distinct values over 100001 populated rows, an exact agreement is expected at most 20 times, short of the 100 observations the sampler asks for. Its u-probability will fall back to a built-in default rather than being measured on your data; reaching it would take a u_max_pairs of at least about 5000000

and, when raising the setting cannot help:

… an exact agreement is expected at most 0 times … no two records share a value on it at all, so no u_max_pairs can reach it — its u stays at the default until the data repeats

The arithmetic, and why it only errs quiet

Over d distinct non-null values with counts n_v summing to M out of N rows, agreeing pairs are A/2 for A = Σ n_v(n_v−1), and A ≤ M(n_max − 1) via the mode count. It fires only when that upper bound times the pairs examined falls short of the sampler's own 100-observation target — so a level that merely might go unmeasured stays silent. Chunking and early stopping can only reduce pairs examined, which keeps it an upper bound in practice too.

n_v(n_v−1) and not n_v²: a value appearing once contributes no agreeing pair, which is exactly the case this exists for. The first draft used the square and predicted ten agreements on a perfectly unique column that cannot produce one.

Checked against real data, not asserted

The closed form was validated against rust/fixtures/golden/fake_1000/model_after_u_simple.json — that golden runs unchunked with early stopping off, so it examines every pair of the corpus:

column M predicted golden rel. err
first_name 831 0.00579357 0.00579357 0
surname 819 0.00488998 0.00488998 0
dob 1000 0.00174775 0.00174775 0
city 813 0.05514757 0.05514757 0
email 789 0.00219387 0.00219387 0

All five exact u-probabilities reproduce to zero relative error, and both bounds hold on every column. An earlier draft's lower bound was falsified by this same check (email's measured u fell below it), which is what surfaced the n_v² error.

Scoped to exact deliberately — every other token compares a derived or fuzzy key whose agreement rate column statistics cannot bound.

Also: four inert config fields

training.u_seed, u_sampling_method, u_min_count_per_level and u_num_chunks have no reader outside er-config. dedupe_core::linker builds UOptions { max_pairs, ..Default::default() }, so none of them reaches the sampler.

u_seed's doc comment claimed a defaulted seed would make the determinism test's byte-equality claim unreproducible — which asserts a causal role it does not have. Determinism comes from hash(<uid>) % 1e9, with or without a salt; changing u_seed in a tenant config produces a byte-identical model, and lint rule V10 enforces a knob that changes nothing.

The comments now say so, and the advisory reads UOptions::default() rather than the inert field. Wiring them is not done here — it would move every committed golden, so it belongs to a deliberate decision rather than a side effect of this change.

Verification

make check green from the repo root: fmt, clippy, doc, entities-check, skills-check, test — 825 tests, 0 failures, goldens unmoved. 29 tests in config_check (22 before).

The advisory path is wired end to end: profile_advisories → publish_advisories → the publish response's advisories → config-studio.tsx.

🤖 Generated with Claude Code

…rived from what the sampler actually does

Two things in the publish advisories, both found by checking a claim against
the code rather than against its comment.

**The block-size number was wrong.** `dedupe_core::profile::top_values`
divides by `count(<col>)`, so a mode's share is over the column's POPULATED
rows. The skew advisory multiplied it by `row_count`, which overstates the
block by 1/fill and the comparisons by 1/fill² because the count is squared.
On a half-populated column it reported 799,980,000 comparisons where the truth
is 199,990,000. Every existing test used a fully populated column, where fill
is 1 and the mistake cannot show — so the new test uses a half-empty one and
was watched failing against the old arithmetic.

**The u pre-flight needed its motivation rebuilt.** It was specified against a
hazard that does not exist: that a comparison level the u-sample never observes
normalizes to a sentinel read as `u = 1e-6`, producing a large spurious match
weight. It does not. `estimate_u` records `ProbEstimate::NotObserved`,
`populate_from_trained_values` filters those out, and the slot is left alone so
the level falls back to its built-in default — which is deliberate and better.
A stale doc comment outlived the variant it described and a design note took it
as fact.

The real cost is quieter, and worth saying: nobody is told when a level's
u came from a prior instead of from their data. For most levels the default is
a considered position on the ladder. For an `exact` level it can be far off,
because the true u of an equality is the corpus's own collision probability.

So `profile_advisories` now names the `exact` levels this corpus cannot supply,
bounded from the profile alone. Over d distinct non-null values with counts n_v
summing to M out of N rows, agreeing pairs are A/2 for A = Σ n_v(n_v−1), and
A ≤ M(n_max − 1) via the mode count. It fires only when that UPPER bound times
the pairs examined falls short of the sampler's own 100-observation target — so
a level that merely might go unmeasured stays silent, and chunking or early
stopping, which can only reduce pairs examined, keeps it an upper bound in
practice too.

`n_v(n_v−1)` and not `n_v²`: a value appearing once contributes no agreeing
pair, which is exactly the case this exists for. The first draft used the
square and predicted ten agreements on a perfectly unique column that cannot
produce one. The closed form was then checked against
`fixtures/golden/fake_1000/model_after_u_simple.json` — unchunked, early
stopping off, so it examines every pair — and reproduces all five `exact`
u-probabilities to zero relative error, with both bounds holding on every
column.

Scoped to `exact` deliberately. Every other token compares a derived or fuzzy
key whose agreement rate column statistics cannot bound.

Also: four of the five `training.u_*` config fields have no reader outside
`er-config`. `dedupe_core::linker` builds
`UOptions { max_pairs, ..Default::default() }`, so `u_seed`,
`u_sampling_method`, `u_min_count_per_level` and `u_num_chunks` never reach the
sampler. `u_seed`'s doc comment claimed a defaulted seed would make the
determinism test unreproducible, which asserts a causal role it does not have —
determinism comes from `hash(<uid>) % 1e9`, with or without a salt. The
comments now say so, and the advisory reads `UOptions::default()` rather than
the inert config field. Wiring them is a behaviour change that would move every
committed golden, so it is left for a deliberate decision rather than done
quietly here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 17db1dd into main Nov 5, 2026
39 checks passed
@athvin
athvin deleted the bm/profile-u-measurability branch November 5, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants