Skip to content

AI Request Logs: use a fixed 30-day window for the "Last 30 Days" summary period#753

Merged
dkotter merged 2 commits into
WordPress:developfrom
i-anubhav-anand:fix/summary-month-window-30-days
Jun 22, 2026
Merged

AI Request Logs: use a fixed 30-day window for the "Last 30 Days" summary period#753
dkotter merged 2 commits into
WordPress:developfrom
i-anubhav-anand:fix/summary-month-window-30-days

Conversation

@i-anubhav-anand

@i-anubhav-anand i-anubhav-anand commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #752

Make the "Last 30 Days" summary period (period=month) use a fixed 30-day window instead of a calendar INTERVAL 1 MONTH, so the summary cards and the logs table cover the same span for that selection.

Why?

On the AI Request Logs screen the header dropdown labels this period "Last 30 Days", and the logs table already filters it as a fixed 30 days (computed in the browser). The summary cards, however, build their cutoff server-side with DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 MONTH), which spans 28–31 days depending on the date.

Because both views are driven by the same dropdown selection, they should cover the same window. With a calendar month they don't: in a 31-day look-back the summary card counts an extra day the table omits; in a February look-back it counts fewer. The fix aligns the summary with the "Last 30 Days" label and the table's window. The other periods already use matching fixed offsets on both sides and are unaffected.

This is the same get_date_condition() method recently corrected for a UTC mismatch in #671.

How?

In AI_Request_Log_Repository::get_date_condition(), change the month case from INTERVAL 1 MONTH to INTERVAL 30 DAY. One line; no change to the front end, which already uses 30 days.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8 / Sonnet 4.6
Used for: Locating the discrepancy across the PHP/JS boundary and drafting the regression test. I reviewed, ran, and take responsibility for the final change.

Testing Instructions

Automated:

npm run test:php -- --filter test_get_summary_month_period_uses_30_day_window

The new test inserts two logs — one 29 days 23 hours old (inside 30 days) and one 30 days 1 hour old (outside) — and asserts get_summary( 'month' ) counts exactly one. It passes with the fix; with the previous INTERVAL 1 MONTH it fails on months whose calendar look-back is not exactly 30 days.

Manual:

  1. Enable AI request logging and accumulate logs spanning the last ~31 days.
  2. Open AI Request Logs and select "Last 30 Days".
  3. Confirm the Total Requests summary card matches the table total (X-WP-Total) — both now cover the last 30 days.

Changelog Entry

Fixed - AI Request Logs: the "Last 30 Days" summary period now uses a fixed 30-day window so the summary cards and logs table cover the same span.

Open WordPress Playground Preview

The header period labelled "Last 30 Days" filtered the summary cards with a
calendar INTERVAL 1 MONTH (28-31 days) while the logs table used a fixed 30-day
window, so the two views could report different totals for the same selection.

Use INTERVAL 30 DAY in get_date_condition() so the summary matches the label and
the table. Adds a regression test asserting the 'month' period spans 30 days.
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: i-anubhav-anand <anubhav24@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment thread tests/Integration/Includes/Logging/AI_Request_Log_RepositoryTest.php Outdated
@dkotter dkotter added this to the 1.1.0 milestone Jun 22, 2026
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.24%. Comparing base (77f116e) to head (c370dd1).
⚠️ Report is 56 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #753      +/-   ##
=============================================
+ Coverage      74.45%   76.24%   +1.78%     
- Complexity      1740     1764      +24     
=============================================
  Files             85       85              
  Lines           7521     7589      +68     
=============================================
+ Hits            5600     5786     +186     
+ Misses          1921     1803     -118     
Flag Coverage Δ
unit 76.24% <100.00%> (+1.78%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter dkotter merged commit 8961592 into WordPress:develop Jun 22, 2026
24 checks passed
jorgefilipecosta pushed a commit that referenced this pull request Jun 29, 2026
…mary period (#753)

Fixed - The "Last 30 Days" summary period in the AI Requests Logs page now uses a fixed 30-day window so the summary cards and logs table cover the same span.

Co-authored-by: i-anubhav-anand <anubhav24@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
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.

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

2 participants