AiAutomatorRule::execute() does not set field_name in $automatorConfig, causing fatal error when using AI Automator Trigger action in ECA
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3581216. --> Reported by: [bkenro](https://www.drupal.org/user/48982) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When using the AI Automator Trigger action (eca_ai_automator) in an ECA model, a fatal error occurs at RuleBase.php line 663:</p> <blockquote><p>Warning: Undefined array key "field_name"</p></blockquote> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <ol> <li>Create an AI Automator with worker_type = eca. </li> <li>Set up an ECA model that uses the "AI Automator Trigger" action referencing that automator.</li> <li>Trigger the ECA model on an entity that matches the automator's entity type and bundle. </li> <li>Observe the fatal error. </li> </ol> <h4 id="root-cause">Root cause:</h4> <p>In AiAutomatorEntityModifier::processEntity(), $automatorConfig is built with field_name explicitly set:</p> <pre>&nbsp; $automatorConfig = [&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'field_name' =&gt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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; }</pre><p>However, in AiAutomatorRule::execute() (the ECA integration), $automatorConfig is built only from plugin_config and field_name is never added:</p> <pre>&nbsp; $automatorConfig = [];<br>&nbsp; foreach ($automator-&gt;get('plugin_config') as $key =&gt; $setting) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $automatorConfig[substr($key, 10)] = $setting;<br>&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; // field_name is never set here</pre><p>When this $automatorConfig is passed down to RuleBase::runRawChatMessage(), line 663 accesses $automatorConfig['field_name'] without checking for its existence, resulting in the error.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Add the following line after the foreach loop in AiAutomatorRule::execute(): </p> <pre>$automatorConfig['field_name'] = $automator-&gt;get('field_name');</pre><p>Patch: (attached &mdash; ai_integration_eca_automators-field_name.patch)</p> <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>[ ] 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>[x] 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>
issue