Skip to content

Prevent exception when constructing WP_AI_Client_Prompt_Builder when invalid timeout is provided by filter#11596

Open
westonruter wants to merge 7 commits intoWordPress:trunkfrom
westonruter:fix/request-timeout-exception
Open

Prevent exception when constructing WP_AI_Client_Prompt_Builder when invalid timeout is provided by filter#11596
westonruter wants to merge 7 commits intoWordPress:trunkfrom
westonruter:fix/request-timeout-exception

Conversation

@westonruter
Copy link
Copy Markdown
Member

@westonruter westonruter commented Apr 18, 2026

Trac ticket: https://core.trac.wordpress.org/ticket/65094

The primary change here is in WP_AI_Client_Prompt_Builder::__construct() to check that the return value of the wp_ai_client_default_request_timeout filter is in fact a non-negative float. It also newly allows the value null. Otherwise, the filtered value is discarded in favor of using the original default of 30, and a _doing_it_wrong() is issued. Without this check, a fatal error would ensue due to an exception being thrown by \WordPress\AiClient\Providers\Http\DTO\RequestOptions::validateTimeout().

In addition to this change, static analysis issues were resolved:

  • Use float instead of int for the wp_ai_client_default_request_timeout.
  • Adding missing PHP imports for Message and MessagePart for the PHPDoc for wp_ai_client_prompt().
  • Adding PHP type hints for the return values of wp_ai_client_prompt() and \WP_AI_Client_Cache::getMultiple().
  • Use native property type hints in WP_AI_Client_HTTP_Client.

The following PHPStan level 10 issues are resolved:

  1. src/wp-includes/ai-client.php: Parameter $prompt of function wp_ai_client_prompt() has invalid type Message.
  2. src/wp-includes/ai-client.php: Parameter $prompt of function wp_ai_client_prompt() has invalid type MessagePart.
  3. src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php: Cannot cast mixed to int.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.7
Used for: Research


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

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

Core Committers: Use this line as a base for the props when committing in SVN:

Props westonruter.

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

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.

1 participant