Skip to content

AI Request Logs: summary counters show zero for “Last Hour” when requests are recent #666

@alexWinterjuice

Description

@alexWinterjuice

Description

On AI Request Logs (/wp-admin/admin.php?page=ai-request-logs or equivalent), the header time-period dropdown correctly filters the log table for short windows, but the summary cards at the top (total requests, tokens, duration, success rate) show 0 when “Last Hour” (or “Last Minute”) is selected—even when requests were made within the last hour.

Switching back to “Last 24 Hours” restores the expected non-zero counters for the same recent requests.

Expected behavior

Summary statistics for “Last Hour” include all logs whose timestamps fall within the last hour (same as the table filter for that period).

Actual behavior

Summary statistics are zero for short periods on sites where the MySQL/server timezone is not UTC, while longer periods (e.g. 24 hours) still show data.

Root cause

Log rows store timestamp in GMT via current_time( 'mysql', true ) in AI_Request_Log_Repository::insert(), but get_date_condition() used MySQL NOW() (server-local time) for summary queries. For short intervals, that mismatch can exclude recent GMT timestamps from the summary WHERE clause. The logs list is less affected because the UI sends date_from in UTC from periodToDateFrom() in src/admin/ai-request-logs/index.tsx.

Affected code

includes/Logging/AI_Request_Log_Repository.php — get_date_condition() (summary path via get_summary()).

Suggested fix

Use UTC_TIMESTAMP() instead of NOW() in get_date_condition() so period filters align with GMT-stored timestamps.

Step-by-step reproduction instructions

  1. Use a WordPress install where the server/MySQL timezone is not UTC (e.g. US/New York, Europe/Berlin) - this makes the bug easiest to see.
  2. Ensure the AI plugin is active and AI request logging is enabled.
  3. Trigger at least one AI request (e.g. use an AI feature in the plugin) and confirm a new row appears in AI Request Logs within the last hour.
  4. Open AI Request Logs in wp-admin.
  5. Confirm summary cards show non-zero values with the default “Last 24 Hours” period.
  6. Change the header dropdown to “Last Hour”.
  7. Observe the summary cards drop to 0 (or otherwise incorrect totals).
  8. Confirm the log table may still list recent entries (depending on filters), or switch period and note the inconsistency between cards and table.
  9. Switch back to “Last 24 Hours” and observe summary cards show the correct counts again.

Screenshots, screen recording, code snippet

Image

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except the AI plugin.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions