fix(metrics): token_counter period if/elif does not know 90d/365d — all-time rate-limit numbers under a bounded label

Author: LearningCircuitCreated Sep 27, 2026Updated Sep 27, 2026
Labelsmetricspythonseverity:suggestedfrom-review-extractionfollow-up-work-in-progress

Summary

The metrics period vocabulary has a declared single source of truth (PERIOD_DAYS_MAP, including 90d/365d used by the link-analytics page), but token_counter's rate-limit cutoff hardcodes its own 7d/30d/3m/1y/all ladder - unknown strings fall to else: all.

Field Value
Severity suggested
Origin Review of #6834 (post-merge extraction)
Review section Prose review notes (pre-existing, reviewer-flagged)
Classification main-existing
Verified at main@43061a14ebff
Dedup distinct · 4 hits reviewed

Trigger

A metrics request with period=90d or 365d (the standalone link-analytics page sends exactly these).

Impact

The token window respects the bounded period while the rate-limit numbers in the same response are computed all-time - wrong data presented under a bounded label, with no error.

Pinned evidence

  • 43061a14ebff:src/local_deep_research/metrics/token_counter.py:L1378-L1388 - the hardcoded if period == "7d" ... elif "1y" ... else: all ladder
  • 43061a14ebff:src/local_deep_research/metrics/query_utils.py:L10-L31 - PERIOD_DAYS_MAP documented as "Single source of truth for period to days across all metrics endpoints", with 90d: 90 / 365d: 365 and a comment that the link-analytics page sends them

Fix direction

Derive the cutoff from get_period_cutoff/PERIOD_DAYS_MAP instead of the local ladder, keeping the float-epoch shape RateLimitAttempt.timestamp needs.

Targeted tests

Parametrize the totals test over 90d/365d asserting the rate-limit rows respect the window (fails against the ladder today).

Provenance

Extracted from review of PR #6834 (post-merge extraction).

Source: LearningCircuit/local-deep-research