[wp-trac] [WordPress Trac] #65094: AI: Prompt construction fails with fatal error when wp_ai_client_default_request_timeout filter returns negative number
WordPress Trac
noreply at wordpress.org
Sat Apr 18 09:50:14 UTC 2026
#65094: AI: Prompt construction fails with fatal error when
wp_ai_client_default_request_timeout filter returns negative number
--------------------------------------+--------------------------
Reporter: westonruter | Owner: westonruter
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 7.0
Component: AI | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+--------------------------
Comment (by darshitrajyaguru97):
== Patch Testing & Review ==
I tested the latest patch locally and reviewed the changes in detail.
=== **Environment ===
* WordPress: 7.0 RC2
* PHP: 8.3.x
* Server: Nginx
* Browser: Chrome
* OS: Windows
=== **Summary ===
The patch successfully prevents a fatal error when invalid values are
returned via the
`wp_ai_client_default_request_timeout` filter.
Previously, returning a negative value or invalid type would propagate
into
`RequestOptions::validateTimeout()` and throw an uncaught exception,
resulting in a fatal error.
With this patch, the value is validated earlier and handled gracefully.
=== **Testing Performed ===
I tested multiple scenarios:
* Returning `-1`
→ Falls back to default `30.0`
→ `_doing_it_wrong()` triggered
→ No fatal error ✅
* Returning `45.5`
→ Value applied correctly ✅
* Returning `null`
→ Timeout disabled (`null`) as expected ✅
* Returning invalid type (e.g., array)
→ Falls back to default
→ `_doing_it_wrong()` triggered ✅
All cases behaved as expected and no regressions were observed.
=== **Code Review Notes ===
* Validation logic in `WP_AI_Client_Prompt_Builder::__construct()` is
solid:
* Accepts non-negative numeric values
* Explicitly supports `null`
* Safely falls back for invalid input
* Use of `_doing_it_wrong()` aligns well with WordPress core practices
and avoids hard failures inside filters
* Switching to `float` improves flexibility and resolves PHPStan level 10
issues
* Additional improvements:
* Proper return type declarations
* Missing imports added
* Native property typing applied
=== **Unit Tests ===
New PHPUnit tests provide good coverage:
* Valid float override
* `null` handling
* Negative value rejection
* Invalid type rejection
All tests pass locally.
=== **Feedback ===
This is a well-rounded fix that:
* Improves resilience of the AI client
* Prevents fatal errors in edge cases
* Enhances developer experience with clear feedback
The approach is consistent with core standards.
=== **Conclusion ===
**Patch tested successfully — works as expected.**
No issues found during testing in this environment; needs to be tested
across different environments as well for better clarity.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65094#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list