Skip to content

AI Request Logs: "Last 30 Days" summary uses a calendar month, not 30 days, so cards and table disagree #752

Closed

Description

@i-anubhav-anand

Description

On the AI Request Logs screen, the header time-period dropdown offers "Last 30 Days" (period=month). When this option is selected, the summary cards at the top and the logs table below are filtered with two different window definitions, so their counts can disagree for the same selection.

  • The summary cards call the REST summary endpoint, which builds the cutoff server-side with a calendar month: DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 MONTH). A calendar month spans 28–31 days depending on the current date.
  • The logs table sends a date_from computed in the browser as a fixed 30 days (30 * 24 * 60 * 60 * 1000 ms).

Because both are driven by the same dropdown selection — labelled "Last 30 Days" — they should cover the same window. They don't: in a month whose look-back is 31 days, the summary cards count an extra day of logs that the table excludes; in a February look-back (28 days), the summary cards count fewer.

I expect the summary cards and the logs table to cover the same 30-day window that the "Last 30 Days" label promises. Instead they use different windows and can show mismatched totals.

The other periods (Last Minute / Hour / 24 Hours / 7 Days) use matching fixed offsets on both sides and are unaffected — only month diverges.

Step-by-step reproduction instructions

  1. Enable AI request logging and accumulate logs spanning the last ~31 days (or insert rows with timestamps 29 and 31 days old).
  2. Open AI Request Logs.
  3. In the header dropdown, select "Last 30 Days".
  4. Compare the Total Requests value on the summary card with the number of rows in the table (X-WP-Total).
  5. In a month preceded by a 31-day month, the summary card counts logs from the last 31 days while the table only counts the last 30 — the two totals differ.

Code snippet

The two divergent definitions, both fed by the same period=month selection:

// includes/Logging/AI_Request_Log_Repository.php — get_date_condition()
case 'month':
    return 'AND timestamp >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 MONTH)'; // 28–31 days
// src/admin/ai-request-logs/index.tsx — PERIOD_OFFSETS_MS
month: 30 * 24 * 60 * 60 * 1000, // exactly 30 days
// src/admin/ai-request-logs/components/HeaderPeriodSelector.tsx
{ label: __( 'Last 30 Days', 'ai' ), value: 'month' },

Environment info

  • AI plugin version: 1.0.2 (also present on develop).
  • Reproducible independent of browser/theme; most visible when the current calendar-month look-back is not exactly 30 days.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions