Skip to content

fix(analytics): store bounded product-usage rollup dimensions complete#384

Merged
JSONbored merged 2 commits into
JSONbored:mainfrom
galuis116:fix/usage-rollup-bounded-dimensions
Jun 4, 2026
Merged

fix(analytics): store bounded product-usage rollup dimensions complete#384
JSONbored merged 2 commits into
JSONbored:mainfrom
galuis116:fix/usage-rollup-bounded-dimensions

Conversation

@galuis116
Copy link
Copy Markdown
Contributor

Closes #383.

Summary

buildProductUsageDailyRollupRecord stored every dimension via countProductUsageDimensions, which keeps only the top 20 by frequency. That is correct for the unbounded byRepo / byCommand / byTool / byRouteClass dimensions (shown as display top-N), but byEvent is a bounded event-name enum (~22 distinct names) that the weekly value report consumes by exact-name lookup (sumEvent -> byEvent.find(eventName)). On a day with more than 20 distinct event types, the lowest-frequency events drop off the cut — and the report's flagship signals (agent_pr_packet_completed, agent_preflight_branch_completed, agent_command_replied/skipped) are exactly the low-frequency ones, so the public weekly value report under-counts them (reads 0 for that day).

Scope

  • src/db/repositories.ts — store the bounded enum dimensions (bySurface / byOutcome / byEvent) complete via a FULL_DIMENSION_LIMIT, while the genuinely-unbounded byRepo / byCommand / byTool / byRouteClass keep their display top-N. A comment marks the bounded-vs-unbounded distinction so the two classes can't be conflated again.
  • test/unit/product-usage.test.ts — high-diversity-day test.

No schema, API, or public-surface changes (the rollup record shape is unchanged; only the bounded dimensions are no longer truncated).

Validation

npx vitest run test/unit/product-usage.test.ts test/unit/weekly-value-report.test.ts \
  test/unit/operator-dashboard.test.ts test/unit/product-usage-mcp-adoption.test.ts   # 29/29
npx vitest run test/integration/api.test.ts test/unit/queue.test.ts                   # 58/58
npx tsc --noEmit                                                                      # clean
git diff --check                                                                      # clean (no whitespace errors)

Branch coverage stays >= 97%. CI validate is green.

Safety

  • Privacy-safe: byEvent holds bounded, sanitized event names (already redacted/normalized at record time) and small per-day counts — storing the complete bounded enum adds no actor/repo PII and only marginally more rows (bounded by the enum size).
  • The unbounded repo/command/tool/route dimensions are unchanged, so there is no unbounded growth in the stored rollup.

Notes

  • The weekly value report is a public + operator trust artifact persisted to an audit event, so the undercount directly understated miner-utility / maintainer-value headline metrics on the busiest days.
  • Reachable when a single UTC day has > 20 distinct event types (active days mixing agent/auth/mcp/github events).

@galuis116 galuis116 requested a review from JSONbored as a code owner June 4, 2026 12:09
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 4, 2026
@github-actions github-actions Bot added the bug Something isn't working label Jun 4, 2026
Copy link
Copy Markdown
Owner

@JSONbored JSONbored left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galuis116 this looks good.

A few notes:

  • The bounded dimension handling is now complete without turning the top-N behavior into an unbounded storage path.
  • The high-diversity coverage is the right regression shape here.
  • No code changes requested.

Validation expected:

  • Keep the current green CI run.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 4, 2026
@JSONbored JSONbored merged commit 12dd884 into JSONbored:main Jun 4, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Done

2 participants