Skip to content

Deprecate the AI_Service layer - #905

Merged
dkotter merged 14 commits into
WordPress:developfrom
theaminulai:Remove-unused-AI_Service-class
Aug 11, 2026
Merged

dkotter merged 14 commits into
WordPress:developfrom
theaminulai:Remove-unused-AI_Service-class

Conversation

@theaminulai

@theaminulai theaminulai commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

What?

See #233

Deprecates the AI_Service class (includes/Services/AI_Service.php) and the get_ai_service() helper, rather than removing them outright.

Why?

This started as an outright removal, since AI_Service (introduced in #101 / 0.2.1) isn't used anywhere in the plugin and a follow-up attempt to adopt it (#898) was closed as not wanted. @dkotter pointed out that both the class and the helper are public — third-party code could be relying on them — so removing them immediately would cause fatal errors for anyone using them. Deprecating first and removing in the next major release is the safer path, consistent with how this plugin already deprecates hooks in includes/Deprecated.php.

How?

  • AI_Service::__construct() now calls _deprecated_class( self::class, 'x.x.x', 'wp_ai_client_prompt()' ), matching how WordPress core signals class deprecation. The notice fires once per request via the singleton constructor rather than on every get_instance() call.
  • get_ai_service() now calls _deprecated_function( __FUNCTION__, 'x.x.x', 'wp_ai_client_prompt()' ) before returning the instance.
  • Both carry @deprecated x.x.x docblock tags and updated descriptions pointing callers at wp_ai_client_prompt() directly, with a short snippet showing the one bit of behavior the helper added (applying get_preferred_models_for_text_generation() by default).
  • docs/ARCHITECTURE_OVERVIEW.md now notes AI_Service as deprecated in the Services/ folder description.
  • tests/Integration/Includes/Services/AI_ServiceTest.php uses setExpectedDeprecated() around every call into the deprecated surface, so the suite fails if the deprecation notice goes missing or if an unexpected notice fires. The singleton is reset between tests via reflection so the notice (which the constructor only emits once per process) stays deterministic.
  • Added a changelog entry under Unreleased/Deprecated; left the historical 0.2.1 "Added" entry untouched.

Testing Instructions

  1. Run the PHPUnit integration suite; tests/Integration/Includes/Services/AI_ServiceTest.php should pass and confirm deprecation notices fire correctly:
    • composer test
  2. With WP_DEBUG enabled, manually call WordPress\AI\get_ai_service() or AI_Service::get_instance() from a test snippet and confirm a deprecation notice is logged, while the returned instance still works (create_textgen_prompt() still returns a usable prompt builder).
  3. Confirm no other code in the plugin still calls AI_Service or get_ai_service() outside the deprecated files themselves.

Changelog Entry

Deprecated - The AI_Service class and the get_ai_service() helper introduced in 0.2.1 will be removed in the next major release. Neither is used anywhere in the plugin; experiments and abilities call wp_ai_client_prompt() directly.

Open WordPress Playground Preview

AI_Service was introduced in WordPress#101 (0.2.1) as a proposed centralized
layer for AI provider access. It was never adopted by any experiment
or ability, and a follow-up PR (WordPress#898) to wire it in was closed as not
wanted. Removing the dead code rather than carrying it forward.

Refs WordPress#233
Companion removal to the AI_Service class deletion. No other test
depends on this file.

Refs WordPress#233
Drops the get_ai_service() function and its AI_Service use-import.
No longer needed now that AI_Service itself is gone; experiments and
abilities call wp_ai_client_prompt() directly.

Refs WordPress#233
The Services/ folder description referenced AI_Service; updated to
reflect that it now only contains Guidelines.

Refs WordPress#233
Drops the includes/Services/AI_Service.php entry from the Related
Files list since the file no longer exists.

Refs WordPress#233
Documents the removal under Unreleased. The historical 0.2.1 entry
describing AI_Service's original introduction is left untouched.

Refs WordPress#233
@theaminulai
theaminulai requested a review from a team July 29, 2026 03:48
@theaminulai
theaminulai requested a review from jeffpaul as a code owner July 29, 2026 03:48
@github-actions

github-actions Bot commented Jul 29, 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: theaminulai <theaminuldev@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.

@codecov

codecov Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.42%. Comparing base (a8897e7) to head (b05347c).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #905   +/-   ##
==========================================
  Coverage      80.41%   80.42%           
- Complexity      2565     2566    +1     
==========================================
  Files            110      110           
  Lines          10437    10440    +3     
==========================================
+ Hits            8393     8396    +3     
  Misses          2044     2044           
Flag Coverage Δ
unit 80.42% <100.00%> (+<0.01%) ⬆️

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 added this to the 1.3.0 milestone Jul 29, 2026

@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.

@theaminulai Thanks for the PR! In thinking about it a bit more, since the class is public and the helper function is also public, better to deprecate those and remove later than just remove entirely. Otherwise anyone that is relying on those will hit fatal errors.

I've pushed changes to handle that deprecation process but let me know if all of that looks good to you. In addition, would be great to get the PR title and description updated since we're not removing anything in this release, just deprecating

@jeffpaul

jeffpaul commented Aug 5, 2026

Copy link
Copy Markdown
Member

@theaminulai checking in to see if you're able to make those changes that Darin referenced above?

@jeffpaul jeffpaul linked an issue Aug 5, 2026 that may be closed by this pull request
6 tasks
@theaminulai theaminulai changed the title Remove unused ai service class Deprecate the AI_Service layer Aug 9, 2026
Mark AI_Service class and get_ai_service() helper as deprecated in the CHANGELOG. These were introduced in 0.2.1 but are not used anywhere in the plugin, as experiments and abilities call wp_ai_client_prompt() directly. Both will be removed in the next major release (ref: WordPress#233).
@theaminulai

Copy link
Copy Markdown
Member Author

Thanks for the nudge, @jeffpaul — and thanks for pushing those changes, @dkotter. Deprecating rather than removing outright makes sense given both are public.

I've reviewed the deprecation approach and it looks good to me — _deprecated_class() / _deprecated_function() calls, @deprecated x.x.x tags, and the rewritten test suite with setExpectedDeprecated() all match the conventions already used elsewhere in the plugin (includes/Deprecated.php, etc.).

One thing I noticed was missing: no changelog entry for the deprecation. Just pushed one under Unreleased/Deprecated. I've also updated the PR title and description to reflect that this deprecates AI_Service and get_ai_service() rather than removing them, since we're not shipping a removal in this release.

Ready for another look whenever you get a chance.

@jeffpaul jeffpaul mentioned this pull request Aug 10, 2026
48 tasks done
@dkotter

dkotter commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

One thing I noticed was missing: no changelog entry for the deprecation

We don't add changelog entries to that file on an individual PR basis; those should be added to the PR description and we pull those out when generating a release. I've updated the PR description with that changelog and pushed a commit to remove that from the file

@dkotter
dkotter merged commit bdd8f72 into WordPress:develop Aug 11, 2026
25 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.

Refactor experiments to leverage AI_Service layer

3 participants