Skip to content

Fix /activity date matching so daily stats aren't silently zeroed - #1

Open
ufkesba wants to merge 1 commit into
Azonnali:feat/openrouter-usage-collectorfrom
ufkesba:fix/openrouter-activity-date-format
Open

ufkesba wants to merge 1 commit into
Azonnali:feat/openrouter-usage-collectorfrom
ufkesba:fix/openrouter-activity-date-format

Conversation

@ufkesba

@ufkesba ufkesba commented Sep 18, 2026

Copy link
Copy Markdown

Summary

Found this while testing omacom#10824 locally against a live account with a management key.

/api/v1/activity returns date as "YYYY-MM-DD HH:MM:SS", not a bare date. summarize_activity() compares this string directly against today_date/recent_dates keys built from strftime("%Y-%m-%d"), so the comparison never matches:

  • recentDays (the "Tokens by day" bar chart) comes back all-zero even with real activity in the window.
  • todayTotalTokens / todayTokensByModel stay empty for every management-key (tier-2) user — the tier this PR's headline feature targets.
  • activeDates ends up holding "2026-09-15 00:00:00" instead of "2026-09-15", which likely also affects the cross-device sync merge that unions active dates (per the agents README).

modelUsage (all-time totals) is unaffected since it doesn't bucket by day.

Fix

Slice to the date portion before comparing/storing:

day = str(raw.get("date") or "")[:10]

Tests

The existing scanner test's fixture used a bare %Y-%m-%d date, which is why it didn't catch this — that shape doesn't match what the live endpoint actually returns. Updated the fixture to use the real "YYYY-MM-DD HH:MM:SS" shape so a regression here fails loudly:

  • Confirmed the strengthened test fails against the unfixed collector (activityToday returns 0, wants 85).
  • Confirmed it passes with the fix (14/14 assertions green).
  • Verified live: ran the collector against a real OpenRouter account/management key before and after — recentDays went from all-zero to reflecting real per-day token counts.

OpenRouter's /activity endpoint returns "date" as "YYYY-MM-DD HH:MM:SS",
not a bare date. summarize_activity() compared this directly against
today_date/recent_dates keys formatted as "YYYY-MM-DD", so the comparison
never matched: recentDays (the Tokens-by-day chart) came back all-zero
and todayTotalTokens/todayTokensByModel stayed empty for every
management-key (tier-2) user, even with real activity in the window.

Confirmed against a live account and management key before and after
the fix. Slicing to the date portion fixes the comparison; the existing
scanner test's fixture used a bare date and didn't reflect the real
API shape, so it passed despite the bug -- updated it to use the
"YYYY-MM-DD HH:MM:SS" shape the live endpoint actually returns.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016SepVLazUi3s7cegrzwJ8K
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.

1 participant