Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions backend/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,10 @@ router.get("/analytics", async (req: Request, res: Response) => {
effectiveFrom = threeDaysAgo.toISOString();
}

// Filter by date range using startedAt
if (effectiveFrom) sessions = sessions.filter((s) => s.startedAt >= effectiveFrom!);
if (to) sessions = sessions.filter((s) => s.startedAt <= to);
// 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);
Comment on lines +808 to +811
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.

// Get project tags for all sessions
const sessionIds = sessions.map((s) => s.id);
Expand Down
Loading