Skip to content

[BUG] Streak tracker silently breaks for streaks longer than 90 days — hardcoded look-back window truncates history #695

@MehtabSandhu11

Description

@MehtabSandhu11

Summary

The streak calculation has a hardcoded 90-day look-back window. Any user whose current or longest streak exceeds 90 days will see a wrong (truncated) streak value with no warning. This also means the "Longest Streak" stat is unreliable for any dedicated contributor.

Root Cause

In src/app/api/metrics/streak/route.ts, fetchActiveDates hardcodes the search window to 90 days:

const since = new Date();
since.setDate(since.getDate() - 90);

This is also duplicated in the GET handler itself:

const since = new Date();
since.setDate(since.getDate() - 90);
const sinceStr = since.toISOString().slice(0, 10);

calculateStreakFromDates then operates only on the dates returned within this window. If a user has been committing every day for 120 days:

  • The actual streak is 120 days
  • The returned activeDates only covers the last 90 days
  • current is reported as 90 (or less if today/yesterday falls outside)
  • longest is capped at whatever run exists within the 90-day slice

The same 90-day cap exists in the public profile API (src/app/api/public/[username]/route.ts, fetchStreak function), meaning public-facing profiles also display wrong streaks.

The leaderboard (src/app/api/leaderboard/route.ts) uses streakStart = toDateStr(new Date(Date.now() - 90 * 86400000)) for the same reason — leaderboard streak rankings are therefore incorrect for top contributors.

Impact

  • Users with long streaks see demoralizing, incorrect numbers
  • Leaderboard streak rankings are wrong for the most active users (the ones most likely to have streaks >90 days)
  • No error or caveat is shown to the user — the number looks authoritative

Expected Behaviour

The look-back window for streak calculation should extend far enough to capture any realistic streak. A sensible approach: fetch up to 365 days of history (the GitHub Search API supports date ranges up to a year), or use a configurable STREAK_LOOKBACK_DAYS constant. The current/longest streak values should always reflect real history.

Proposed Fix

  1. Introduce a constant STREAK_LOOKBACK_DAYS = 365 in src/app/api/metrics/streak/route.ts
  2. Replace all hardcoded 90 references in the streak route, the public profile route, and the leaderboard route with this constant
  3. Adjust the cache TTL if needed since a larger window will return more data

Labels

bug advanced ~3h

Please assign this to me under GSSoC

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions