[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 03:35:28 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 | Keywords:
Focuses: |
--------------------------+-------------------------
Consider this code:
{{{
add_filter(
'wp_ai_client_default_request_timeout',
static function () {
return -1;
}
);
}}}
This causes a fatal error to occur when constructing a prompt with
`wp_ai_client_prompt()`:
{{{
WordPress\AiClient\Common\Exception\InvalidArgumentException: Request
option "timeout" must be greater than or equal to 0.
/var/www/src/wp-includes/php-ai-
client/src/Providers/Http/DTO/RequestOptions.php:201
/var/www/src/wp-includes/php-ai-
client/src/Providers/Http/DTO/RequestOptions.php:52
/var/www/src/wp-includes/php-ai-
client/src/Providers/Http/DTO/RequestOptions.php:169
/var/www/src/wp-includes/ai-client/class-wp-ai-client-prompt-
builder.php:203
/var/www/src/wp-includes/ai-client.php:59
}}}
As exceptions are caught in ability callbacks (#65058) and generally
`WP_Error` objects are returned, it would seem this exception should be
caught in favor of issuing `_doing_it_wrong()`.
Note: I stumbled upon this issue when looking at the AI codebase in
PHPStan with rule level 10 applied. For this line:
{{{#!php
<?php
$default_timeout = (int) apply_filters(
'wp_ai_client_default_request_timeout', 30 );
}}}
PHPStan complains with:
> Cannot cast mixed to int.
I started adding an `is_numeric()` check here and this led me down to
looking at the validation logic in
`\WordPress\AiClient\Providers\Http\DTO\RequestOptions::validateTimeout()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65094>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list