Suggest Reply: Only insert a suggestion into the form of its own comment by maheshbohara · Pull Request #1158 · WordPress/ai · GitHub
Skip to content

Suggest Reply: Only insert a suggestion into the form of its own comment - #1158

Merged
dkotter merged 4 commits into
WordPress:developfrom
maheshbohara:fix/1157-suggest-reply-wrong-comment
Oct 13, 2026
Merged

dkotter merged 4 commits into
WordPress:developfrom
maheshbohara:fix/1157-suggest-reply-wrong-comment

Conversation

@maheshbohara

@maheshbohara maheshbohara commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #1157

Stops Suggest Reply from inserting a suggestion into the reply form of a different comment than the one it was generated for.

Why?

WordPress has a single inline reply form (#replyrow) that moves between comments. While a suggestion was being generated, the Reply, Quick Edit and "Suggest reply" row actions of the other comments still worked, so the form could move before the result arrived. runGeneration() then wrote the result into whatever form was open, and clicking Reply posted it under the wrong comment. The form that had moved also stayed disabled, with the "Generating AI reply…" placeholder, until the first request finished. Steps are in #1157.

How?

All changes are in runGeneration() in src/experiments/suggest-reply/components/SuggestReply.ts:

  • The result, or the error notice, is used only if the inline form is still open for the comment the request was made for. isInlineReplyOpenForComment() already existed and is reused.
  • While the request runs, a short interval checks whether the form is still open for that comment. When it is closed or moved, the form is handed back right away: the placeholder is cleared and the controls are enabled again.
  • Each generation gets an ID. An earlier generation leaves the form alone once a newer one has started, so clicking "Suggest reply" on a second comment while the first is still running gives the second comment its own suggestion.
  • The "Suggest reply" link of the originating comment still shows "Generating…" until its request finishes, as before.

The request for the first comment is not cancelled, only ignored. runAbility() passes an abort signal on its REST fallback path only, so I did not rely on it here.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus
Used for: Investigation, implementation, tests, manual testing, and PR wording. I reviewed the changes and the test results, and I take responsibility for the contribution.

Testing Instructions

  1. Enable the Suggest Reply experiment under Settings > AI, with a provider connected.
  2. Have two comments on a post, for example one by Alice and one by Bob.
  3. Go to Comments, hover Alice's comment and click "Suggest reply".
  4. While the form shows "Generating AI reply…", hover Bob's comment and click "Reply". The form moves under Bob's comment and can be typed in right away. On develop it stays disabled.
  5. Wait for the request to finish. Bob's reply form is still empty. On develop it contains the suggestion generated for Alice's comment.
  6. Repeat step 3, then click "Suggest reply" on Bob's comment while Alice's suggestion is still generating. Bob's form receives the suggestion for Bob's comment.
  7. Click "Suggest reply" on one comment and wait. The suggestion is inserted as before.

I ran these steps in Chrome on WordPress 7.1.3 (wp-env, PHP 8.3). To make the timing easy to hit and the result unambiguous, the provider response was answered locally with a 6 second delay and named the comment author it was generated for. Before the fix, Bob's form contained "Thank you Alice! …". After it, Bob's form stayed empty in step 5 and contained "Thank you Bob! …" in step 6.

Automated:

  • New e2e test in suggest-reply.spec.js. It holds the ability request, moves the reply form to a second comment, and expects that form to be enabled and still empty after the request finishes. It fails on develop.
  • The Suggest Reply e2e spec passes (6 tests). I did not run the rest of the e2e suite or the PHP tests locally. No PHP changed.
  • npm run typecheck and npm run lint:js pass.

Screenshots or screencast

Before After
Bob's reply form contains the suggestion generated for Alice's comment Bob's reply form stays empty and usable

Changelog Entry

Fixed - Suggest Reply: a suggestion is no longer inserted into the reply form of a different comment.

Open WordPress Playground Preview

WordPress has one inline reply form that moves between comments. A suggestion that was still being generated when the form moved was written into the other comment's reply form, and that form stayed disabled until the request finished.

The result is now used only while the form is still open for the comment it was generated for. The form is handed back as soon as it is closed or moved, and an earlier generation no longer touches a form that a newer one has taken over.

See WordPress#1157.
@maheshbohara
maheshbohara requested a review from a team October 11, 2026 09:48
@github-actions

github-actions Bot commented Oct 11, 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: maheshbohara <maheshbohara@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 Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.11%. Comparing base (17f5163) to head (adc968f).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #1158   +/-   ##
==========================================
  Coverage      82.11%   82.11%           
  Complexity      3396     3396           
==========================================
  Files            136      136           
  Lines          13179    13179           
==========================================
  Hits           10822    10822           
  Misses          2357     2357           
Flag Coverage Δ
unit 82.11% <ø> (ø)

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.

Replace the interval and the generation counter with a set of comment IDs
that have a request running, and a MutationObserver on the comment list
that locks or unlocks the inline form whenever it is opened, moved or
closed.

The result is only inserted when the form is open in Reply mode for the
comment it was generated for, so it is not written into the Quick Edit
form of the same comment. Returning to a comment whose request is still
running locks the form again and inserts the suggestion when it arrives,
instead of dropping it.
@maheshbohara
maheshbohara requested a review from dkotter October 13, 2026 08:07
@dkotter dkotter added this to the 1.5.0 milestone Oct 13, 2026
@dkotter
dkotter merged commit 2d0e9f9 into WordPress:develop Oct 13, 2026
36 checks passed
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.

Suggest Reply: a reply generated for one comment can be inserted into another comment's reply form

2 participants