From f624387e1b36f6edab7a2a178047e6f5efceca25 Mon Sep 17 00:00:00 2001 From: Extra Chill Bot Date: Fri, 1 May 2026 23:52:18 +0000 Subject: [PATCH] fix(schema): declare array items for upsert_event tool to satisfy OpenAI strict mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Production fire on events.extrachill.com — every event ingestion flow has been failing since the wp-ai-client cutover with: Bad Request (400) - Invalid schema for function 'upsert_event': In context=('properties', 'occurrenceDates'), array schema missing items. OpenAI's strict tool schema validation requires `items` on every array type. The previous ai-http-client tolerated the omission; wp-ai-client does not. Two changes: 1. Declare `items` on the `occurrenceDates` field in EventSchemaProvider — the field stores ISO date strings (YYYY-MM-DD), so `items: { type: string }`. 2. Harden `fieldsToToolParameters()` to always emit `items` for `type: array`. Falls back to `{ type: string }` when the field declaration is incomplete, so future array fields cannot silently regress this bug. Verified the fix produces a schema that passes OpenAI strict validation. Event ingestion flows should resume on next pipeline tick after deploy. --- inc/Core/EventSchemaProvider.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inc/Core/EventSchemaProvider.php b/inc/Core/EventSchemaProvider.php index 515b7f0..c6d9fa5 100644 --- a/inc/Core/EventSchemaProvider.php +++ b/inc/Core/EventSchemaProvider.php @@ -87,6 +87,7 @@ class EventSchemaProvider { ), 'occurrenceDates' => array( 'type' => 'array', + 'items' => array( 'type' => 'string' ), 'required' => false, 'description' => 'For recurring events: array of specific dates (YYYY-MM-DD) when the event occurs within the start/end range. If provided, event displays only on these dates instead of every day in the range.', 'schema_property' => null, @@ -331,6 +332,15 @@ private static function fieldsToToolParameters( array $fields ): array { $param['enum'] = $field['enum']; } + // JSON Schema requires `items` on every array type, and OpenAI's + // strict tool schema validation rejects arrays without it. + // Propagate `items` from the field declaration; default to a string + // array when the declaration is incomplete to avoid emitting an + // invalid schema that would fail at runtime. + if ( 'array' === ( $field['type'] ?? '' ) ) { + $param['items'] = $field['items'] ?? array( 'type' => 'string' ); + } + $params[ $key ] = $param; }