Skip to content

Gracefully handle missing AI provider configuration#523

Merged
dkotter merged 20 commits into
WordPress:developfrom
Takshil-Kunadia:feat/graceful-degradations-no-provider
May 13, 2026
Merged

Gracefully handle missing AI provider configuration#523
dkotter merged 20 commits into
WordPress:developfrom
Takshil-Kunadia:feat/graceful-degradations-no-provider

Conversation

@Takshil-Kunadia
Copy link
Copy Markdown
Contributor

@Takshil-Kunadia Takshil-Kunadia commented May 7, 2026

What?

Closes #182

Adds graceful degradation across all AI experiments and features when no AI provider/connector is configured. Users now receive clear, actionable guidance instead of failed API calls or silent failures.

Why?

When no AI provider is configured, clicking any AI action button (Generate Title, Generate Alt Text, etc.) triggers a request which generated a Error Notice. Comment Moderation also silently fails on new comment. There is no guidance pointing users toward configuring a provider. This PR ensures users understand why an action is unavailable and know exactly where to go to fix it.

How?

Implemented a centralized provider availability architecture shared across all AI experiments.

  • Added helper fns which expose provider state globally by injecting provider availability in window object, avoiding per-experiment duplication.
  • Added shared frontend guards that prevents requests when no provider is configured and surfaces a consistent notice with a “Manage Connectors” action.
  • Added equivalent PHP-side guards for Comment Moderation flows, including early returns, redirect-based notices, and prevention of queued processing without credentials.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 4.6
Used for: Implementation across multiple files following architectural decisions made collaboratively. All code was reviewed, iterated on, and validated by me.

Testing Instructions

Prerequisites

Ensure no AI connector is configured (remove API keys from Settings > Connectors). Enable all experiments in Settings.

Block Editor (Posts > Add New)

  1. Click Generate in the title toolbar > snackbar notice appears with "Manage Connectors" link
  2. Open Excerpt panel > click Generate > same notice
  3. Click the Summarize button in Post Status > same notice
  4. Open Categories panel > click Suggest > same notice
  5. Open Meta Description panel > click Generate > same notice
  6. Click Generate Review Notes > same notice
  7. Click Refine from Notes (requires existing notes) > same notice
  8. Add an image block > select it > click Generate Alt Text in inspector > same notice
  9. Add an image block > click Generate Image in placeholder > same notice

Media Library

  1. Click an image > attachment details > click Generate button > inline red error text
  2. Select multiple images > Bulk Actions > Generate Alt Text > Apply > admin notice at top

Comments

  1. Select comments > Bulk Actions > Analyze Sentiment and Toxicity > Apply > server-rendered error notice with connectors link
  2. Hover a comment > click Analyze Sentiment and Toxicity > same notice

With provider configured

  1. Configure any AI connector with a valid API key
  2. Repeat steps 1-14 > all features should work normally, no degradation notices

Screenshots or screencast

Experiments:-
image

Comments Mod:-
image

Alt text from Media Library
image

Changelog Entry

Changed - Graceful degradation when no AI provider is configured. All experiments now show actionable guidance directing users to configure an AI Connector, instead of failing silently or showing generic errors.

Open WordPress Playground Preview

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

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: Takshil-Kunadia <takshil@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

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

@jeffpaul jeffpaul added this to the 1.0.0 milestone May 7, 2026
@jeffpaul jeffpaul requested review from dkotter and jeffpaul May 7, 2026 19:30
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.20%. Comparing base (27ac41f) to head (289b02e).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
...iments/Alt_Text_Generation/Alt_Text_Generation.php 0.00% 1 Missing ⚠️
...eriments/Comment_Moderation/Comment_Moderation.php 95.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #523      +/-   ##
=============================================
+ Coverage      70.72%   71.20%   +0.47%     
- Complexity      1144     1150       +6     
=============================================
  Files             67       67              
  Lines           5510     5563      +53     
=============================================
+ Hits            3897     3961      +64     
+ Misses          1613     1602      -11     
Flag Coverage Δ
unit 71.20% <94.28%> (+0.47%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

Comment thread includes/Main.php Outdated
Comment thread includes/Experiments/Comment_Moderation/Comment_Moderation.php Outdated
Comment thread src/utils/provider-status.ts Outdated
Comment thread src/utils/provider-status.ts
@Takshil-Kunadia Takshil-Kunadia requested a review from dkotter May 12, 2026 07:42
@Takshil-Kunadia
Copy link
Copy Markdown
Contributor Author

Thanks for the review @dkotter 🙇 . Addressed the feedbacks, please have a look whenever you get the chance. I'll add tests as well.

dkotter
dkotter previously approved these changes May 12, 2026
Copy link
Copy Markdown
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

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

Tested and looks good to me, thanks for the work here! As mentioned, would be ideal to get E2E tests in place but once that's done this can be merged in

@Takshil-Kunadia
Copy link
Copy Markdown
Contributor Author

@dkotter updated the tests and added tests covering the changes.

@Takshil-Kunadia Takshil-Kunadia requested a review from dkotter May 13, 2026 10:56
* POST /ai-e2e/v1/credentials/seed — sets a dummy provider API key.
* POST /ai-e2e/v1/credentials/clear — removes it.
*/
function ai_e2e_register_credentials_endpoint() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you explain the need for these endpoints? We already have helper functions that clear or set credentials using the UI so just wondering what benefit these provide over using that existing functionality?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The REST endpoints exist because Playwright's afterAll and globalSetup hooks only receive requestUtils.

I tried using the existing clearConnectors in afterAll, but Playwright throws:

"context" and "page" fixtures are not supported in "afterAll" since they are created on a per-test basis.

Specifically we need REST for two cases:

  1. global-setup.ts - seeds credentials before any browser launches (only requestUtils available, no page)
  2. afterAll hooks in settings.spec.js and dashboard.spec.js — these specs clear connectors during their run and need to restore credentials for subsequent specs, but afterAll only receives requestUtils

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Before this PR, tests didn't need credentials since there was no frontend provider check. Now that ensureProvider() blocks AI actions when no provider is configured, every experiment test needs a valid API key. The global-setup seeds it upfront, and specs that clear connectors (settings, dashboard) re-seed in their afterAll via these REST endpoints.

Comment thread tests/e2e-request-mocking/e2e-request-mocking.php Outdated
@dkotter dkotter merged commit 94f5d40 into WordPress:develop May 13, 2026
22 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.

Graceful degradation when no AI provider is configured

3 participants