Skip to content

Fix #541: Track and display per-project agent time in analytics#555

Merged
waleedkadous merged 2 commits intomainfrom
builder/bugfix-541-analytics-track-and-display-pe
Feb 24, 2026
Merged

Fix #541: Track and display per-project agent time in analytics#555
waleedkadous merged 2 commits intomainfrom
builder/bugfix-541-analytics-track-and-display-pe

Conversation

@waleedkadous
Copy link
Contributor

Summary

Adds Phase 1 agent time tracking to the analytics dashboard by summing consultation durations from MetricsDB per project and averaging by protocol.

Fixes #541

Root Cause

The analytics dashboard tracked wall clock time per protocol but had no visibility into how much actual agent compute time each project consumed. MetricsDB already records per-consultation duration_seconds with project_id and protocol fields, but no aggregation existed to surface this data.

Fix

  • MetricsDB (metrics.ts): Added agentTimeByProtocol() method — a subquery groups consultations by (protocol, project_id), sums durations per project, then averages across projects per protocol
  • Analytics server (analytics.ts): Extended ProtocolStats with avgAgentTimeHours, computed from MetricsDB data with graceful fallback if DB is unavailable
  • Dashboard (api.ts, AnalyticsView.tsx): Display agent time alongside wall clock time in the Activity section's Projects by Protocol metrics

Test Plan

  • Regression test: agent time appears in protocol stats when consultation data exists
  • Regression test: null agent time when no consultation data for a protocol
  • Regression test: graceful fallback when MetricsDB.agentTimeByProtocol() throws
  • Build passes
  • All 2055 tests pass (105 test files)
  • Net diff: 112 LOC across 5 files

Add Phase 1 (consultation-based estimate) of agent time tracking:
- MetricsDB.agentTimeByProtocol() aggregates consultation durations by
  project, then averages per protocol
- Analytics server merges agent time into ProtocolStats alongside wall
  clock time, with graceful fallback on failure
- Dashboard shows agent time next to wall clock in Activity section

112 LOC net diff across 5 files.
Address CMAP review feedback: dashboard analytics test fixture was
missing the new avgAgentTimeHours property on ProtocolStats.
@waleedkadous
Copy link
Contributor Author

Architect Review

Low-medium risk. Clean addition of per-project agent time tracking to analytics.

  • SQL query is sound: inner GROUP BY (protocol, project_id) for per-project totals, outer AVG per protocol
  • Graceful degradation via try/catch around MetricsDB — analytics never breaks
  • Dashboard conditionally shows agent time only when data exists
  • 3 new test cases cover the key paths (present, partial, DB failure)
  • CMAP feedback addressed

Approved.


Architect review

@waleedkadous waleedkadous merged commit 456be45 into main Feb 24, 2026
6 checks passed
@waleedkadous waleedkadous deleted the builder/bugfix-541-analytics-track-and-display-pe branch February 24, 2026 19:29
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.

Analytics: track and display per-project agent time

1 participant