Skip to content

UN-4515 [FIX] Dashboard Overview: repair window, local-day date range, Prompt Studio-only orgs - #2387

Merged
athul-rs merged 5 commits into
mainfrom
UN-4515-dashboard-daily-metrics-fix
Oct 27, 2026
Merged

athul-rs merged 5 commits into
mainfrom
UN-4515-dashboard-daily-metrics-fix

Conversation

@athul-rs

@athul-rs athul-rs commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

  • backfill_metrics takes --start-date / --end-date (UTC days, end inclusive), so a past window can be repaired. --days only counts back from now.
  • The metrics dashboard sends the Overview date range with the user's UTC offset (format()) instead of toISOString().
  • The aggregation cron's org shortlist (_active_org_ids) now includes orgs with page_usage in the lookback, as well as orgs with workflow executions.

Why

Three defects make the Overview page disagree with actual page usage:

  • Damaged daily rows, 12 Mar to 8 Apr 2026. Before UN-3322 [FIX] Optimize dashboard metrics aggregation task #1837, the daily aggregation started its window at now - 7d without truncating to midnight. Each run rewrote the oldest day with only the pages from that time of day onward. UN-3322 [FIX] Optimize dashboard metrics aggregation task #1837 fixed the window but the damaged days were never rebuilt. On US prod, 78 orgs are missing 1,355,497 pages in that window. The monthly tier is correct.
  • Date shift for users ahead of UTC. toISOString() converts the picked local midnight to UTC, and the overview endpoint takes .date() on it. A UTC+8 user picking 1 to 30 Apr queries 31 Mar to 29 Apr.
  • Prompt Studio-only orgs. Prompt Studio records page_usage without a workflow execution, so these orgs were never shortlisted and have no daily rows. On US prod: 149 orgs, 8,465 pages, 212 org-days since 9 Apr. Every daily row that does exist since 9 Apr matches live usage exactly.

How

  • _resolve_window builds the start/end instants. With --end-date, the end stops 1 µs before the next midnight: the source queries use created_at__lte, so ending on midnight would rewrite the following day with only its 00:00 rows.
  • A --start-date range that covers only part of a month needs --skip-monthly. Otherwise the monthly row would be replaced with only those days, and months outside the task's current-and-previous window are never rederived. Whole-month ranges still rebuild the monthly row.
  • /metrics/overview/ parses dates with datetime.fromisoformat, which keeps the offset, so .date() yields the user's calendar day. The Usage by Deployment tab still sends toISOString(). It compares instants, which is already correct.
  • _active_org_ids unions orgs from PageUsage (string organization_id, mapped to the PK). The lookup is served by idx_page_usage_created_org (created_at, organization_id).

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • backfill_metrics behaves as before unless --start-date is passed.
  • Overview totals change for users ahead of or behind UTC: the range now follows their calendar days. That is the intended fix. Daily rows are still UTC days, so the daily tier cannot represent a local day exactly.
  • The cron processes more orgs per run (the Prompt Studio-only ones). On US that's at most a handful per 15-minute window; the extra query is an index-only scan.

Database Migrations

  • None.

Env Config

  • None.

Relevant Docs

Related Issues or PRs

Dependencies Versions

  • None.

Notes on Testing

  • New tests:
    • an explicit range writes whole days and leaves the following day untouched
    • --end-date without --start-date is refused
    • a partial first or last month without --skip-monthly is refused and keeps the stored monthly total; a whole-month range rebuilds it
    • an org with only page_usage is shortlisted
  • Mutation checks: removing the 1 µs end guard fails the range test, dropping the page_usage union fails the shortlist test, and disabling the month-end check fails the partial-last-month case.
  • dashboard_metrics suite: 237 passed. Frontend build passes.
  • Verified the date strings for TZ=Asia/Manila: the old value 2026-04-29T16:00:00.000Z resolves to 29 Apr; the new value 2026-04-30T00:00:00+08:00 resolves to 30 Apr.

Post-release repair (one-time, per environment, dry-run first):

python manage.py backfill_metrics --start-date=2026-01-01 --skip-hourly --skip-monthly

This rebuilds the 2026 daily tier for all orgs. It covers the damaged window, the Prompt Studio-only days and the days before the dashboard's history began. Rows that are already correct are rewritten with the same values.

Screenshots

Checklist

I have read and understood the Contribution Guidelines.

🤖 Generated with Claude Code

athul-rs and others added 2 commits October 27, 2026 12:40
…ange

- backfill_metrics: add --start-date/--end-date (UTC days, end inclusive) so
  the daily rows damaged between 12 Mar and 8 Apr 2026 can be rewritten.
  --days only reaches back from now. The range stops just before the next
  midnight because the source queries are end-inclusive.
- Metrics dashboard: send the overview range with its UTC offset (format())
  instead of toISOString(). The backend takes .date() on it, so users ahead
  of UTC were querying one day earlier than they picked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_active_org_ids shortlisted orgs by WorkflowExecution only. Prompt Studio
records page_usage without a workflow execution, so orgs using only Prompt
Studio never got daily rows. Union in orgs with page_usage in the lookback,
served by idx_page_usage_created_org.

test_tasks.py also carries a ruff-format pass: the file was unformatted on
main since #2276 and the pre-commit hook formats the whole file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

via Greptile

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Adds explicit UTC date ranges to backfill_metrics, preserves local calendar dates in Overview requests, and includes organizations with only page usage in scheduled aggregation.

  • Operators can rebuild metrics for selected UTC date ranges.
  • The metrics cron includes organizations with recent page usage.
  • Overview date filters follow the user's calendar days.

Reviews (4) · Last reviewed commit: "Merge branch 'main' into UN-4515-dashboa..." · Reviewed by Greptile

Comment thread backend/dashboard_metrics/management/commands/backfill_metrics.py
athul-rs and others added 2 commits October 27, 2026 14:51
…e monthly totals

A --start-date/--end-date range covering part of a month summed only those
days into the monthly row and replaced the stored total. A month outside the
aggregation task's current-and-previous window is never rederived, so it
stayed undercounted. Such a range now needs --skip-monthly; whole-month
ranges still rebuild the monthly row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Frontend Lint Report (Biome)

✅ All checks passed! No linting or formatting issues found.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Unstract test results

Per-group results

Status Group Tier Passed Failed Errors Skipped Duration (s)
⚪ e2e-agent-kv e2e 0 0 0 1 0.1
✅ e2e-api-deployment e2e 3 0 0 0 11.9
✅ e2e-coowners e2e 1 0 0 0 1.0
✅ e2e-etl e2e 1 0 0 0 15.8
✅ e2e-login e2e 2 0 0 0 1.2
✅ e2e-prompt-studio e2e 1 0 0 0 9.1
✅ e2e-smoke e2e 2 0 0 0 0.8
✅ e2e-workflow e2e 1 0 0 0 13.7
✅ frontend unit 629 0 0 0 11.4
✅ integration-backend integration 1448 0 0 26 82.9
✅ integration-connectors integration 1 0 0 7 9.1
✅ integration-workers integration 181 0 0 1 53.4
❌ ui e2e 0 1 0 0 0.0
✅ unit-agent-kv-schema unit 143 0 0 0 1.0
✅ unit-backend unit 2052 0 0 1 36.0
✅ unit-connectors unit 82 0 0 0 7.2
✅ unit-core unit 281 0 0 0 1.9
✅ unit-filesystem unit 1 0 0 0 2.7
✅ unit-platform-service unit 18 0 0 0 1.7
✅ unit-rig unit 120 0 0 0 2.9
✅ unit-runner unit 12 0 0 0 1.9
✅ unit-sdk1 unit 878 0 0 0 29.8
✅ unit-tool-sidecar unit 8 0 0 0 1.1
✅ unit-workers unit 1534 0 0 2 105.7
TOTAL 7399 1 0 38 402.3

Critical paths

⚠️ Critical paths not yet covered

  • workflow-execution-fan-out — Multi-file workflow execution fans out to file-processing workers and rejoins. (declared coverage: no groups declared)
✅ Covered critical paths
  • auth-login — covered by e2e-login
  • adapter-register-llm — covered by integration-backend
  • workflow-author — covered by integration-backend
  • co-owner-manage — covered by integration-backend, e2e-coowners
  • workflow-create-execute — covered by e2e-workflow
  • api-deployment-provision — covered by integration-backend
  • api-deployment-auth — covered by integration-backend
  • api-deployment-run — covered by e2e-api-deployment
  • mcp-server-auth — covered by integration-backend
  • mcp-platform-auth — covered by integration-backend
  • platform-key-whoami — covered by integration-backend
  • prompt-studio-author — covered by integration-backend
  • prompt-studio-fetch-response — covered by e2e-prompt-studio
  • connector-register-test — covered by integration-backend
  • pipeline-etl-execute — covered by e2e-etl
  • usage-aggregate-read — covered by integration-backend
  • usage-token-tracking — covered by e2e-api-deployment
  • callback-result-delivery — covered by e2e-api-deployment

@athul-rs
athul-rs merged commit 2f833e1 into main Oct 27, 2026
19 checks passed
@athul-rs
athul-rs deleted the UN-4515-dashboard-daily-metrics-fix branch October 27, 2026 12:34
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.

2 participants