Skip to content

improvement(insights): serve org usage from settled segments and redesign the overview - #8193

Merged
waleedlatif1 merged 5 commits into
stagingfrom
feat/insights-dashboard-perf
Sep 23, 2026
Merged

waleedlatif1 merged 5 commits into
stagingfrom
feat/insights-dashboard-perf

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Insights read every raw ledger/execution row in the window on every view, so large orgs waited 6–12s per chart on a cold replica. Settled days and hours are now aggregated once and cached (Redis, in-process LRU fallback); a repeat view only reads the last few hours live
  • New usage-segment-cache: window cut at the viewer's midnights, settled days cached whole, recent days cached hour by hour, adjacent misses merged into one scan, cache failures fall back to a ledger read, writes are fire-and-forget
  • Activity never caches an hour holding an unfinished run (in-flight veto), so outcomes can't be frozen mid-run; ledger hours settle after the streaming top-up window; DST days only settle whole
  • New GET /usage/overview replaces the summary + source breakdown + full org billing calls the overview made (the billing call re-summed the whole reporting year per member just to show the allowance)
  • readUsageGroups is the single entry point for rankings; the public v2 API keeps its bounded direct read; overview members reuse the Members tab pipeline; allowance comes from getOrgUsageLimit
  • Rolling windows start on the hour so their first hour is cacheable; rolling/custom windows now show a delta vs the span before them
  • Overview redesign: source-stacked credit chart with a fixed-color, interactive legend; Top models / Top members cards; activity as stacked outcomes (completed/failed/other) + chat runs; workspace drill-down uses the same chart
  • Chart palette anchored to the app's own source colors (Sim green for Chat, the Knowledge block's teal, the agent violet, Enrichment purple), with separate fill-weight steps for light and dark, validated for adjacent-pair and color-vision-deficiency separation in both modes
  • emcn BarChart gains a stacked mode (discriminated props) that draws each column as one bar split by color, date-only tooltips for calendar buckets with exact values, memoized data table; DonutChart removed (no consumers left)
  • Fixes found along the way: allowance now refreshes after a limit change, Top members dims with the page on period change, legend selection resets when its series disappears, chat members parsed as JSON (a text[] arrived unparsed with type fetching off)

Measured on the prod replica for a large org, 30-day window, repeat view: credits 6.6s cold / 1.27s warm → 0.13s, model ranking 11.9s → 0.05s, activity 8.6s → 0.8s. Locally, the overview request goes 565ms cold → 93ms cached.

Type of Change

  • Improvement

Testing

  • 2,658 app tests incl. real-Postgres usage/activity SQL suites, 308 emcn tests, type-check both packages
  • check:audits (47), lint, block registry, docs manifest all pass
  • Verified in the browser (light/dark, narrow) against a seeded org; mutation-checked the cache tests

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 23, 2026 6:32am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable regressions remain, and the previously reported malformed-cache-entry issue was manually resolved after the parsing fallback was added.

Summary

This PR redesigns the organization usage overview and moves usage and activity analytics onto cached, settled time segments to reduce repeated ledger scans.

  • Adds a consolidated usage overview endpoint with credit history, allowance, source composition, and top-member data.
  • Introduces Redis-backed usage-segment caching with an in-process fallback, live reads for unsettled segments, and an in-flight veto for mutable activity.
  • Reworks usage rankings around a shared grouped-read pipeline while retaining bounded direct reads for the public API.
  • Redesigns the overview with stacked credit and activity charts, interactive legends, and top-model/member cards.
  • Extends the shared bar chart for stacked series and removes the unused donut chart.
  • The only changes since the previous review refine and correctly scope the chart palette for light and dark modes.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  UI[Insights overview] --> API[GET /usage/overview]
  API --> UC[Authorized overview use case]
  UC --> SEG[Segmented usage reads]
  SEG --> C{Settled segment cached?}
  C -->|Yes| CACHE[Redis or in-process cache]
  C -->|No| DB[Ledger/activity replica scan]
  DB --> FINAL{Segment final?}
  FINAL -->|Yes| WRITE[Asynchronous cache write]
  FINAL -->|No| LIVE[Return live result only]
  CACHE --> AGG[Aggregate series and rankings]
  WRITE --> AGG
  LIVE --> AGG
  AGG --> UI
Loading

Reviews (5) · Last reviewed commit: "improvement(insights): brand-aligned, co..."

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 42 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/billing/core/usage-analytics-queries.ts
Comment thread apps/sim/ee/organization-usage/hooks/use-legend-highlight.ts Outdated
Comment thread apps/sim/ee/organization-usage/components/usage-credits.tsx Outdated
Comment thread apps/sim/lib/billing/core/usage-segment-cache.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 42 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/ee/organization-usage/hooks/use-legend-highlight.ts Outdated
Comment thread apps/sim/lib/billing/core/usage-analytics.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 42 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 42 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 42 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 0c321f7 into staging Sep 23, 2026
28 of 29 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/insights-dashboard-perf branch September 23, 2026 06:37

This branch was previously deployed

1 inactive deployment
Preview — a6304e39 Deployed Sep 23, 2026 by vercel[bot]
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