Repository navigation
Conversation
The coding-activity view offers a Today range, and the stats handler allowlists today and yesterday, but WakaTime's stats endpoint answers 400 for both. The handler then reports a 502 upstream_unavailable, so the Today button always shows "WakaTime is unreachable or the API key was rejected" even with a valid key. fetch_stats now asks the summaries endpoint for those two ranges and folds the day into the stats fields the view reads, keeping the stats split between total_seconds (without Other) and the *_including_other_language totals.
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] dd3b0ce Description read[DESCRIPTION-READ] 3101ace13ce0d01365ffe1d3803e85137a7c502ac25e77ce3bd464bac9b05a7b That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The two Not justified as shipped
What this change shipsInventory (5 items) — 2 justifiedIntent: a WakaTime user clicks Today and sees today's coding stats instead of a false "unreachable / key rejected" error. FIX.
[FIRST-PRINCIPLES-REVIEWED] dd3b0ce Description read[DESCRIPTION-READ] ea64226ca45964f6d0bb5d2539c0d0f543094b6f0d095af5fbccacd24c1e5d90 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
The today/yesterday stats path repeated the export handler's per-name summaries sum and fetch_summaries' "no data list -> raise" check. Both now go through one helper each: sum_seconds_by_name in the client, used by the stats fold and _rows_by_project, and _fetch_summary_days, used by fetch_summaries and the single-day stats path.
|
Replying to the First Principles review on
|
|
Thank you @Inthuson for finding this bug and writing the fix and tests. To get it past the main-side CI reds on this fork branch, we carried your two commits unchanged (your authorship kept) onto a fresh base in same-repo PR #20969, which is now green and ready for review. It also links the new tracking issue #20967. Closing this one in favour of #20969; your branch is left as is. Thanks again! |
Problem / Motivation
Goal: The WakaTime view's Today range shows today's coding stats instead of an "unreachable or API key rejected" error.
Clicking Today in the WakaTime coding-activity view always shows "WakaTime is unreachable or the API key was rejected", even with a valid key.
The gateway log shows
WakaTime API GET /users/current/stats/today failed: http=400.Why it matters
Every WakaTime user who clicks Today sees an error.
The error message points them at their API key or network, so they go looking for a problem that does not exist.
Not a goal
What changed (motivation → approach → change)
/api/wakatime/stats?range=todayreturns 502upstream_unavailable.todayandyesterday, but WakaTime's/users/current/stats/:rangeendpoint answers 400 for both. It only accepts ranges likelast_7_days.fetch_statsturns the 400 intoWakaTimeUnavailableError, which the handler reports as a 502.todayandyesterday,WakaTimeClient.fetch_statsnow calls/users/current/summaries?range=Today|Yesterdayand converts the day into the stats fields the view reads (total_seconds,daily_average,languages,projects, and the*_including_other_languagetotals). Keeping this in the client means the handler and the frontend do not change. It also mirrors the stats endpoint's split, wheretotal_secondsleaves out the "Other" language and the*_including_other_languagefields include it. An upstream failure still raises, so an outage is never shown as a false zero.sum_seconds_by_namein the client is now the only per-name summaries fold, used by both the stats fold and the export handler's_rows_by_project._fetch_summary_daysis the only strict summaries fetch, used by bothfetch_summariesand the single-day stats path.Backwards compatibility
Compatible: the endpoint accepts the same ranges, and for every range that worked before it returns the same response. Only the two ranges that always failed now succeed.
Removes nothing: no path, key, validator or public function is removed or narrowed.
Tests
test_fetch_stats_today_uses_summaries_not_stats:todaycalls the summaries endpoint withrange=Today, and the result has the correct totals with and without "Other", plus ranked languages and projects.test_fetch_stats_yesterday_maps_to_summaries_range:yesterdaymaps torange=Yesterday, and an empty day gives zero totals.test_fetch_stats_today_raises_on_server_error: an upstream 500 still raisesWakaTimeUnavailableError.The first two tests fail on
mainand pass with this change.All 65 tests in
test/test_wakatime_*.pypass.black, isort, flake8 and mypy are clean on the changed files.
Manual verification
Run against the live WakaTime API with a real key:
main:stats/todayandstats/yesterdayreturn 400, whilelast_7_daysandlast_30_daysreturn 200.fetch_stats("today"),fetch_stats("yesterday")andfetch_stats("last_7_days")all succeed.Related Issues
N/A - no existing issue found for this bug.
Pattern harvest
Rule candidate: review-prompt
Pattern: an allowlist of upstream API parameters that was never checked against the upstream endpoint's documented values.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.