Skip to content

fix: rely on autoloader for wp-ai-client cache classes to avoid redeclare fatals during deploy swaps (#4043) - #4044

Merged
chubes4 merged 2 commits into
mainfrom
fix/issue-4043-data-machine
Nov 24, 2026
Merged

chubes4 merged 2 commits into
mainfrom
fix/issue-4043-data-machine

Conversation

@chubes4

@chubes4 chubes4 commented Nov 24, 2026

Copy link
Copy Markdown
Member

Summary

WpAiClientCache no longer hand-includes its cache classes, which are covered by composer.json PSR-4 (DataMachine\Engine\ => inc/Engine/), and cache_class() only returns a class that class_exists() can autoload. The previous regression test ran its scenarios in child PHP processes, which can't see the plugin files in WP Codebox, so the gate failed. The test now runs in-process and covers the case where the cache classes are already declared from another path. The bare require_once of WpAiClientCache.php in RequestBuilder and WpAiClientProviderAdmin is now guarded with class_exists(..., false). PHPUnit is not installed in the workspace, so the rewritten test has not been run under PHPUnit yet; it is left for the Homeboy gates.

What changed

  • Rewrote tests/Unit/Engine/AI/WpAiClientCacheRedeclareTest.php to run in-process instead of exec'ing child PHP processes, which failed in WP Codebox
  • Added an in-process test of the deploy case: cache classes already declared, then a renamed copy of the installer loaded from a temp release folder that also holds copies of the cache files resolves the same class and installs without a redeclare error
  • Added tests that cache_class() returns the same answer every time and that calling install() twice is safe, alongside the existing source and composer.json coverage checks
  • Wrapped the require_once of WpAiClientCache.php in RequestBuilder.php and WpAiClientProviderAdmin.php in a class_exists(..., false) check

Verification

  • 2-verify-9a405de3e927d2d3047d73d7afb829b874ff3bb61d18d3e4d73645c7fed15653.txt (homeboy review test data-machine): passed on 44c6c42. Base main@740d87d unchanged. 404522 ms; retained gate metadata.

  • ( if git diff --quiet --no-renames 740d87d -- ' (( if git diff --quiet --no-renames 740d87d5a75440f025b53ae22f5bba87f84861e5 -- ':(literal)plugins/data-machine'; then :…): passed on 44c6c42. Base main@740d87d unchanged. 67260 ms; retained gate metadata.

  • repro: none (no repro gate was declared, so these gates do not prove the issue).

  • CI: pending

Cook run
  • Gate 1: tree 9cf17861eb387025b88b711a29062d58e17a6ae0
  • Gate 2: tree 9cf17861eb387025b88b711a29062d58e17a6ae0

Out-of-scope changes

A remediation attempt changed files outside the original candidate and the paths it was asked to fix:

  • plugins/data-machine/inc/Engine/AI/RequestBuilder.php
  • plugins/data-machine/inc/Engine/AI/WpAiClientProviderAdmin.php

Delivery

  • Delivered: Committed fix with tests (5073c20a4)

Evidence

  • A standalone script running the deploy case (cache classes declared from the original folder, renamed installer copy loaded from a temp release folder with copies of the cache files) resolved PsrWpAiClientTransientCache from both copies, and install() did not fatal
  • PHPUnit and the lint gate were not run locally (no PHPUnit or phpcs config in the workspace)
  • php -l passes on all changed files; tests/wp-ai-client-persistent-cache-smoke.php still passes

AI disclosure

Tool: Homeboy Cook. Agent: Homeboy (Implementation 1: Homeboy (roadie); Implementation 2: Homeboy (roadie)). Model: Implementation 1: roadie · route cook-heavy · served claude-opus-5-5; Implementation 2: roadie · route cook-heavy · served claude-opus-5-5. Cook time: 1h58m.

Implementation and reviewer documentation were written by the AI, under the direction of the Cook requester. Gates were run by Homeboy. A human reviews before merge.

Closes #4043

@chubes4
chubes4 marked this pull request as ready for review November 24, 2026 02:17
@chubes4
chubes4 merged commit d345d09 into main Nov 24, 2026
38 checks passed
@chubes4
chubes4 deleted the fix/issue-4043-data-machine branch November 24, 2026 02:17
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.

fix: WpAiClientCache require_once of classmapped cache classes fatals with 'Cannot redeclare' across deploy path swap

1 participant