⚡ Sangsakala Proxy 🏠 Home
Skip to content

fix(admin): stop counting workflow runs on dashboard list pages - #9630

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/admin-dashboard-ledger-reads
Nov 3, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/admin-dashboard-ledger-reads

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The admin organizations and users lists counted each entity's distinct workflow executions next to its spend. Neither entity index on usage_log carries execution_id, so that count heap-fetches every workflow ledger row in each entity's period, one statement for a whole page of entities. As the ledger grew the list went from seconds to past the 60s statement timeout.
  • Lists and the reporting-period preview now read spend only (index-only on the existing cost indexes) and return workflowRuns: null.
  • Organization detail counts runs once: total plus every actor's share in one GROUPING SETS scan, run alongside the page reads, under a 5s budget via readLedgerBounded (new optional budgetMs). Past the budget the count is null and the page still loads. Former actors' runs come from the same scan instead of a second heap pass.
  • Contract: workflowRuns is nullable. The deployed admin app already renders null as —; a companion admin PR drops the list columns.
  • No new index: widening both entity indexes with execution_id would grow the hot billing sums' working set for a staff-only number (left as a follow-up if staff need exact counts for the largest payers).

Type of Change

  • Bug fix

Testing

  • lib/admin/dashboard-usage.integration.ts against real Postgres: spend per entity/user, runs total + per actor (shared run counts for each actor), empty entity, former-actor spend, and a run count blocked past its budget returns null (verified red with the guard removed)
  • lib/admin/dashboard-organizations.test.ts, lib/api/contracts/v1/admin/dashboard.test.ts, lib/billing/** unit tests, lib/billing/core/ledger-read.integration.ts
  • bun run lint, type-check (pre-push)
  • Plain EXPLAIN of the new runs statement: presorted GroupAggregate over the period cost index, no extra sort

Checklist

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

The organizations and users lists counted each entity's distinct workflow
executions alongside its spend. No entity index carries execution_id, so the
count heap-fetched every workflow ledger row in each entity's period and the
list grew past the statement timeout as the ledger grew.

- Lists and the reporting-period preview read spend only (index-only) and
  return workflowRuns: null.
- Organization detail counts runs once, total plus every actor's share in one
  GROUPING SETS scan, under a 5s budget via readLedgerBounded; past it the
  count is null and the page still loads. Former actors' runs come from the
  same scan.
- The contract makes workflowRuns nullable.
@vercel

vercel Bot commented Nov 3, 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 Ignored Ignored Preview Nov 3, 2026 8:41pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues remain.

Summary

Stops counting workflow runs on admin list pages and reporting-period previews. Organization details count runs within a five-second budget.

  • Admin lists and reporting previews show spend without counting workflow runs.
  • Organization details count runs in one bounded scan.

Reviews (2) · Last reviewed commit: "fix(admin): count former actors' runs on..." · Reviewed by Greptile

Comment thread apps/sim/lib/admin/dashboard.ts Resolved

@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 6 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/admin/dashboard-usage.ts Resolved
Former actors' workflow runs were the sum of their per-user counts, so a run
shared by two former actors counted twice. Group the same scan by a
former-actor flag as well and read the distinct count from it. The flag
tests membership against two uncorrelated lists, so each is hashed once.

Also drop the last non-null assertion in the organizations list and shrink
the explicit-any baseline.
@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 Nov 3, 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 7 files

Confidence score: 5/5

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

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 36e1735 into staging Nov 3, 2026
81 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/admin-dashboard-ledger-reads branch November 3, 2026 22:11
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