fix(upstream): count distinct affected repos across drift reports instead of summing - #397
Merged
JSONbored merged 3 commits intoJun 5, 2026
Conversation
… per-report counts
JSONbored
approved these changes
Jun 5, 2026
JSONbored
left a comment
Owner
There was a problem hiding this comment.
@philluiz2323 this is the right fix.
A few notes:
- The change connects the duplicate-risk reducer to the score preview path instead of only adjusting display logic.
- The unit test covers the collision count behavior directly.
- No code changes requested from me.
Validation expected:
- Current green CI is enough here.
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.
Summary
summarizeRegistryHyperparameterDriftReports(src/upstream/ruleset.ts) aggregated the registry hyperparameter drift summary across all open drift reports but summed each report'saffectedRepoCountinstead of counting distinct repositories:Each
payload.affectedRepoCountis the unique-repo count within one report (new Set(repos).size). Summing across reports counts a repository once for every report it appears in, so a repo whose hyperparameters drift across several open reports is over-counted. The sibling fields in the same function (affectedFields,affectedSurfaces) are correctly deduplicated across reports withuniqueSorted(payloads.flatMap(...))-- the repo count was the lone outlier. This value is returned asUpstreamStatus.registryHyperparameterDrift.affectedRepoCountfromGET /v1/upstream/status, so dashboards/operators saw an inflated count. Closes #396.Scope
src/upstream/ruleset.ts-- the aggregator now unions repositories across reports instead of summing per-report counts. To union exactly (robust to the 100-event per-report cap, matching howaffectedFields/affectedSurfacesunion pre-cap payload lists), the stored drift payload now carries a pre-capaffectedRepos: string[]. This is kept on the internal payload only -- the publicRegistryHyperparameterDriftSummarytype and its OpenAPI schema are unchanged. Legacy payloads (predating the field) deriveaffectedReposfrom their stored events, so older data still dedups rather than sums.test/unit/upstream-ruleset.test.ts-- new fail-on-revert test (two reports{x,y,z}and{z,w}yield 4 distinct repos, not 3 + 2 = 5); updated the malformed-payload assertion to the deduped value (3 -> 2) with a rationale comment.Validation
npx tsc --noEmit-- clean.npx vitest run test/unit/upstream-ruleset.test.ts-- 28/28 pass.mcp-clitimeout under parallel load that passes 37/37 in isolation).ruleset.ts98.89% branch / 100% line.Safety
registryHyperparameterDriftstill exposes the same fields with the same types; only the (now correct, smaller-or-equal)affectedRepoCountvalue changes when reports share repos.affectedReposlives only on the stored payload and is defaulted to[]for empty/legacy payloads.Notes
The additive fields next to it (
totalEvents,omittedEvents,highImpactCount) remain summed -- those count distinct events per report and are genuinely additive; only repositories recur across reports and must be unioned.