fix: bucket analytics by lastActivityAt instead of startedAt (closes #58)#59
fix: bucket analytics by lastActivityAt instead of startedAt (closes #58)#59
Conversation
Sessions are now attributed to the time they were last active, not when they were created. This fixes the timeline showing spikes at the wrong hours — e.g. a session started at 05:00 but active until 12:00 now appears in the 12:00 bucket instead of 05:00. Also updates date range filtering to use lastActivityAt so sessions active within the window are included even if started before it.
There was a problem hiding this comment.
Pull request overview
Adjusts the /analytics timeline logic so sessions are selected and (intended to be) bucketed by when they were last active, addressing misleading hourly/daily usage spikes reported in #58.
Changes:
- Update analytics date-range filtering to use
lastActivityAt(fallback tostartedAt) instead ofstartedAt. - Keep the default “last 3 days” window for hourly analytics when
fromis not provided.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // Filter by date range using lastActivityAt so sessions active in the | ||
| // window are included even if they started before it (#58) | ||
| if (effectiveFrom) sessions = sessions.filter((s) => (s.lastActivityAt || s.startedAt) >= effectiveFrom!); | ||
| if (to) sessions = sessions.filter((s) => (s.lastActivityAt || s.startedAt) <= to); |
There was a problem hiding this comment.
The date-range filtering now uses (lastActivityAt || startedAt), but the actual bucketing/aggregation later in this handler still uses getBucketKey(s.startedAt) (see the loop around line 861). That means the timeline will continue attributing all cost/tokens to the session start time even though filtering is based on last activity. Update the bucket key calculation (and any related min/max logic if needed) to use lastActivityAt with a fallback to startedAt so the chart matches the intended fix for #58.
Problem
The analytics timeline attributed all session cost/tokens to the hour the session was created (
startedAt), not when work actually happened. A session started at 05:00 UTC but active until 12:00 UTC showed its entire spend in the 05:00 bucket.Fix
lastActivityAt(falling back tostartedAt) to place sessions in the time slot when they were last activelastActivityAttoo, so sessions active within the window are included even if they started before itImpact
startedAtiflastActivityAtis missingCloses #58