Skip to content

fix: bucket analytics by lastActivityAt instead of startedAt (closes #58)#59

Open
GalDayan wants to merge 1 commit intomainfrom
fix/timeline-bucketing-58
Open

fix: bucket analytics by lastActivityAt instead of startedAt (closes #58)#59
GalDayan wants to merge 1 commit intomainfrom
fix/timeline-bucketing-58

Conversation

@GalDayan
Copy link
Contributor

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

  • Bucketing: Use lastActivityAt (falling back to startedAt) to place sessions in the time slot when they were last active
  • Filtering: Date range filter now uses lastActivityAt too, so sessions active within the window are included even if they started before it

Impact

  • Timeline charts now accurately reflect when work happened
  • No schema changes, no new deps
  • Backward compatible: falls back to startedAt if lastActivityAt is missing

Closes #58

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.
Copilot AI review requested due to automatic review settings March 12, 2026 11:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 to startedAt) instead of startedAt.
  • Keep the default “last 3 days” window for hourly analytics when from is 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.

Comment on lines +808 to +811
// 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);
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

Timeline data does not accurately reflect actual usage patterns

2 participants