Skip to content

Limit comment moderation bulk analysis queue size - #972

Merged
dkotter merged 2 commits into
WordPress:developfrom
ekamran:sftq/limit-comment-moderation-bulk-queue
Aug 25, 2026
Merged

dkotter merged 2 commits into
WordPress:developfrom
ekamran:sftq/limit-comment-moderation-bulk-queue

Conversation

@ekamran

@ekamran ekamran commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

The plugin bounds AI bulk actions with get_bulk_action_max_items(), a filterable, feature-keyed limit that defaults to 100. Alt text generation and summarization both use it. Comment moderation registers a bulk action but does not, so it marks every selected comment as pending regardless of how many were selected.

Each pending comment becomes a model call once it is analyzed, which is the same reason the other two bulk actions are bounded.

Changes

  • Comment moderation now applies get_bulk_action_max_items() to its bulk action.
  • Selected comments are validated before the limit is applied, so IDs for comments that no longer exist cannot consume slots and push out valid ones.
  • Comment IDs are deduplicated, so the same comment selected twice counts once.
  • Comments left out are reported in the admin notice, which switches to a warning when anything was left out.
  • wpai_analysis_truncated is registered as a removable query arg and scrubbed from the request URI, matching the existing notice args.

Testing

  • npm run test:php -- --filter Comment_ModerationTest passes with 31 tests and 130 assertions. Three new tests cover the limit, deduplication, and invalid IDs not consuming slots, plus one covering the notice when comments were left out but none were queued.
  • Full PHP test suite passes.
  • PHPCS passes on both changed files.
  • PHPStan passes on both changed files.

Manual wp-admin verification was performed with a temporary local filter that set the Comment Moderation bulk limit to 2 and satisfied the credential gate. Selecting 5 comments and running the real bulk action queued 2 comments, left 3 untouched, showed a warning notice for the truncated count, and scrubbed the notice query args after load.

Open WordPress Playground Preview

The plugin bounds AI bulk actions with get_bulk_action_max_items(), which
alt text generation and summarization both use. Comment moderation
registered a bulk action but queued every selected comment, so a large
selection could queue far more analyses than that shared limit allows.

Validate the selected comments first so stale IDs cannot consume slots,
then apply the limit, and report any comments left out through the
existing admin notice.
@ekamran
ekamran requested a review from a team August 25, 2026 06:00
@github-actions

github-actions Bot commented Aug 25, 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: ekamran <ekamran@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.

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.57%. Comparing base (2e28193) to head (ef49eea).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #972      +/-   ##
=============================================
+ Coverage      74.52%   74.57%   +0.04%     
- Complexity      3124     3132       +8     
=============================================
  Files            132      132              
  Lines          12193    12213      +20     
=============================================
+ Hits            9087     9108      +21     
+ Misses          3106     3105       -1     
Flag Coverage Δ
unit 74.57% <100.00%> (+0.04%) ⬆️

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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Overall this looks good and works as expected just have two things that I think we should add here:

  1. We strip query args on the client-side (see clearQueuedAnalysisQueryArg) and we should likely extend that to remove the new wpai_analysis_truncated query arg. That query arg could end up being left in the URL otherwise
  2. We should look to update our docs around this experiment to mention this new limit and how to change the limit

`clearQueuedAnalysisQueryArg()` removed only `wpai_analysis_queued`, so
`wpai_analysis_truncated` could be left behind in the URL. It now removes
both, and the early return checks for either arg so a URL carrying only
the truncated arg is cleaned as well.

Document the cap in the Comment Moderation experiment docs, covering the
default of 100 and the `wpai_bulk_action_max_items` filter with the
`comment-moderation` feature id. The Alt Text docs already described the
shared filter, so that sentence now mentions Comment Moderation too.
@ekamran
ekamran requested a review from jeffpaul as a code owner August 25, 2026 15:32
@ekamran

ekamran commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I pushed a follow-up commit addressing both points.

clearQueuedAnalysisQueryArg() now removes wpai_analysis_truncated alongside wpai_analysis_queued. I also updated the guard so the URL is cleaned if either notice arg is present.

I added an "Adjusting the Bulk Batch Cap" section to the Comment Moderation docs, including the default limit, the wpai_bulk_action_max_items filter, and the comment-moderation feature id. I also updated the existing Alt Text docs note so the shared filter wording stays accurate now that it also applies to Comment Moderation.

@dkotter dkotter added this to the 1.4.0 milestone Aug 25, 2026
@dkotter
dkotter merged commit 8016220 into WordPress:develop Aug 25, 2026
33 checks passed
@ekamran
ekamran deleted the sftq/limit-comment-moderation-bulk-queue branch October 6, 2026 15:46
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.

2 participants