fix(analytics): half-open trend buckets to stop boundary double-count - #520
Merged
JSONbored merged 3 commits intoJun 10, 2026
Merged
Conversation
trendBuckets used an inclusive end (timestamp <= endMs) for every contiguous bucket, so an outcome exactly on an internal boundary was counted in two adjacent trend buckets -- inflating trends so their sum could exceed totals.total and disagree with qualityRollups. Use the same half-open [start, end) rule (final bucket inclusive) that qualityRollups already uses.
|
Note Gittensory Gate skippedPR closed before full evaluation. No late first comment was created.
Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers. |
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
JSONbored
approved these changes
Jun 10, 2026
JSONbored
left a comment
Owner
There was a problem hiding this comment.
@philluiz2323 this is good to land.
A few notes:
- The half-open bucket change fixes the actual boundary double-count in
trendBuckets. - The regression test covers the exact internal-boundary case and checks both trend totals and rollup alignment.
- The missing formal Summary/Safety template sections are nonblocking here because the body explains the bug, change, and validation clearly enough.
No code changes requested.
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.
Closes #519.
buildRecommendationQualityReportFromOutcomesbuilds two time-bucketed views over the same outcomes using the same contiguoustrendPeriodsboundaries (endMs[i] == startMs[i+1]), but with inconsistent interval semantics:trendBuckets:timestamp >= startMs && timestamp <= endMs— inclusive on both ends, every bucket.qualityRollups(same feat(analytics): add role-aware recommendation quality rollups #470 PR):>= startMs && (last ? <= endMs : < endMs)— half-open, correct.So an outcome exactly on an internal boundary was counted in two adjacent trend buckets but one rollup, inflating
trendsso their sum could exceedtotals.totaland disagree with the rollup table on the operator dashboard.Example (
generatedAt = 2026-06-01,windowDays = 14-> split at2026-05-25): one outcome at2026-05-25T00:00:00.000Zgavetrends = [1, 1](sum 2) whiletotals.total = 1androllupscount = 1.Change
[start, end)rule (final bucket inclusive) intrendBucketsthatqualityRollupsalready uses.trends = [0, 1],sum(trends) == totals.total, and the rollup is in the later bucket).Verification
recommendation-quality-report.test.ts10/10 (the new test fails on the old inclusive-end code). Full unit suite green; changed file 100% stmts/lines, branch coverage holds.