Skip to content

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

Open
galuis116 wants to merge 1 commit into
JSONbored:mainfrom
galuis116:fix/usage-rollup-bounded-dimensions
Open

fix(analytics): store bounded product-usage rollup dimensions complete#384
galuis116 wants to merge 1 commit 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Todo

1 participant