AiAgentEntityWrapper::$aiConfiguration is not initialized
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3584132. --> Reported by: [joaopauloc.dev](https://www.drupal.org/user/3720064) Related to !256 >>> <p>[Tracker]<br> <strong>Update Summary: </strong>[One-line status update for stakeholders]<br> <strong>Short Description: </strong>[One-line issue summary for stakeholders]<br> <strong>Check-in Date: </strong>MM/DD/YYYY<br> <em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br> [/Tracker]</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Drupal\ai_agents\PluginBase\AiAgentEntityWrapper declares the property $aiConfiguration without an initial value:</p> <pre>/**<br> * The AI configuration.<br> *<br> * @var array<br> */<br>protected $aiConfiguration;</pre><p>For agents that come from the temp store via fromArray() this is harmless, because fromArray() defaults the value to an empty array (line 1426: $this-&gt;aiConfiguration = $data['ai_configuration'] ?? [];).<br> But for agents created directly via createInstance() &mdash; which is exactly what ai_assistant_api's AgentRunner::runAsAgent() does on every fresh turn &mdash; the property stays NULL until something explicitly calls setAiConfiguration().</p> <p>When progress tracking is enabled on such a fresh agent (e.g. by calling setProgressThreadId() before determineSolvability()), the AgentRequestEvent is dispatched and AgentStatusSubscriber::onAgentRequestExecution() runs.<br> That subscriber constructs an AiProviderRequest value object and passes $event-&gt;getAgent()-&gt;getAiConfiguration() directly into the array $config parameter of the constructor. Because the property is still NULL, PHP throws:</p> <p>TypeError: Drupal\ai_agents\Service\AgentStatus\UpdateItems\AiProviderRequest::__construct():<br> Argument #9 ($config) must be of type array, null given,<br> called in .../src/EventSubscriber/AgentStatusSubscriber.php on line 178<br> The site crashes with a 500 the moment the agent runs.</p> <h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <p>1. Have an AI Assistant configured with an AI Agent (so runAsAgent() is the execution path).<br> 2. Make sure setProgressThreadId() is called on the agent before determineSolvability(). (See sibling issue in the ai queue: "AgentRunner::runAsAgent() does not propagate the thread id to the agent".)<br> 3. Trigger the assistant.<br> Expected: Agent runs and dispatches AgentRequestEvent/AgentFinishedExecutionEvent normally. Actual: TypeError on AiProviderRequest::__construct(), full WSOD.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Two complementary one-line fixes:</p> <p>1. Initialize the property to an empty array so a freshly-created agent always exposes a valid array from getAiConfiguration().<br> 2.. Defensively normalize at the call site in AgentStatusSubscriber so any future code path that mutates aiConfiguration to NULL does not crash status tracking.</p> <p>Fix 1 &mdash; initialize the property<br> src/PluginBase/AiAgentEntityWrapper.php line 67:</p> <pre>/**<br> * The AI configuration.<br> *<br> * @var array<br> */<br>protected $aiConfiguration = [];</pre><p>Fix 2 &mdash; normalize at the call site<br> src/EventSubscriber/AgentStatusSubscriber.php around line 187:</p> <pre>if ($this-&gt;checkLogEventType($event, AiAgentStatusItemTypes::Request)) {<br>&nbsp; $this-&gt;statusStorage-&gt;storeStatusUpdateItem($event-&gt;getThreadId(), new AiProviderRequest(<br>&nbsp;&nbsp;&nbsp; time: $combined_ms,<br>&nbsp;&nbsp;&nbsp; agent_id: $event-&gt;getAgentId(),<br>&nbsp;&nbsp;&nbsp; agent_name: $event-&gt;getAgent()-&gt;getAiAgentEntity()-&gt;label(),<br>&nbsp;&nbsp;&nbsp; agent_runner_id: $event-&gt;getAgentRunnerId(),<br>&nbsp;&nbsp;&nbsp; loop_count: $event-&gt;getLoopCount(),<br>&nbsp;&nbsp;&nbsp; request_data: $event-&gt;getChatInput()-&gt;toArray(),<br>&nbsp;&nbsp;&nbsp; provider_name: $event-&gt;getAgent()-&gt;getAiProvider()-&gt;getPluginId(),<br>&nbsp;&nbsp;&nbsp; model_name: $event-&gt;getAgent()-&gt;getModelName(),<br>&nbsp;&nbsp;&nbsp; config: $event-&gt;getAgent()-&gt;getAiConfiguration() ?? [],<br>&nbsp;&nbsp;&nbsp; calling_agent_id: $event-&gt;getCallerId(),<br>&nbsp; ));<br>}</pre><h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>1. Add a unit/kernel test that creates an agent via createInstance(), enables progress tracking, dispatches AgentRequestEvent, and asserts no TypeError is thrown.</p> <h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3> <h3 id="summary-ai-usage">AI usage (if applicable)</h3> <p>[x] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p> <p>[x] AI Assisted Code<br> This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p> <p>[ ] AI Generated Code<br> This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p> <p>[ ] Vibe Coded<br> This code was generated by an AI and has only been functionally tested.</p> > Related issue: [Issue #3582030](https://www.drupal.org/node/3582030)
issue