Repository navigation
fix(matching): a 4x-overstated block size, and the u pre-flight re-derived from what the sampler actually does - #596
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_valuesdivides bycount(<col>), so a mode's share is over the column's populated rows. The skew advisory multiplied it byrow_count, which overstates the block by1/filland the comparisons by1/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_urecordsProbEstimate::NotObserved,populate_from_trained_valuesfilters 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
exactlevel it can be far off, because the true u of an equality is the corpus's own collision probability.So
profile_advisoriesnow names theexactlevels this corpus cannot supply:and, when raising the setting cannot help:
The arithmetic, and why it only errs quiet
Over
ddistinct non-null values with countsn_vsumming toMout ofNrows, agreeing pairs areA/2forA = Σ n_v(n_v−1), andA ≤ 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 notn_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:All five
exactu-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 then_v²error.Scoped to
exactdeliberately — 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_levelandu_num_chunkshave no reader outsideer-config.dedupe_core::linkerbuildsUOptions { 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 fromhash(<uid>) % 1e9, with or without a salt; changingu_seedin 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 checkgreen from the repo root: fmt, clippy, doc, entities-check, skills-check, test — 825 tests, 0 failures, goldens unmoved. 29 tests inconfig_check(22 before).The advisory path is wired end to end:
profile_advisories→publish_advisories→ the publish response'sadvisories→config-studio.tsx.🤖 Generated with Claude Code