Skip to content

fix(comparison): avoid first-sample lock in matchRatio calibration#6063

Open
ebrasha wants to merge 1 commit into
sqlmapproject:masterfrom
ebrasha:bugfix/matchratio-median-calibration
Open

fix(comparison): avoid first-sample lock in matchRatio calibration#6063
ebrasha wants to merge 1 commit into
sqlmapproject:masterfrom
ebrasha:bugfix/matchratio-median-calibration

Conversation

@ebrasha
Copy link
Copy Markdown

@ebrasha ebrasha commented May 30, 2026

What changed

kb.matchRatio used to get locked on the very first valid ratio it saw.
That was fragile — if the first response happened to be noisy (CSRF token, ad slot, timestamp widget, A/B fragment), the whole baseline for that parameter ended up biased from the start.

To fix this, I switched the calibration from single-shot to multi-sample:

  • valid ratios are now collected into a small buffer instead of locking immediately
  • once we hit a minimum sample count, kb.matchRatio gets set from the median of that buffer
  • there's a hard cap on the buffer so it can't grow forever
  • on context change (different page template / textOnly / titles mode), the buffer resets so old samples don't bleed into a new baseline

Why this is better

The real problem was outliers. One bad first response could throw the whole detection logic off for that parameter. Median makes those single-sample spikes basically harmless.

In practice:

  • the baseline takes a few more samples to settle, but it settles cleaner
  • false positives that came from early-response noise drop a lot
  • nothing else in the comparison flow gets touched — only the calibration step itself was rewritten

Scope

Only lib/request/comparison.py is touched.
The behavioral change is limited to how kb.matchRatio is determined.
Detection paths, ratio bounds, and decision logic stay as-is.

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.

1 participant