AI Chatbot block crashes entire site when placed without configured AI Assistant entity
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3577813. --> Reported by: [jjchinquist](https://www.drupal.org/user/286806) Related to !1296 >>> <p>[Tracker]<br> <strong>Update Summary: </strong>AI Chatbot block crashes entire site when placed without configured AI Assistant entity<br> <strong>Short Description: </strong>DeepChatFormBlock fatal error with NULL assistant ID takes down the whole site<br> <strong>Check-in Date: </strong>03/08/2026<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>Placing the <code>ai_deepchat_block</code> (AI Chatbot block) for a theme without a configured AI Assistant entity reference causes a fatal error that crashes the entire site &mdash; not just the page where the block is rendered.</p> <p>The error is:</p> <p><code>AssertionError: Cannot load the "ai_assistant" entity with NULL ID</code></p> <p>This occurs in <code>DeepChatFormBlock</code> when the block is placed but no assistant has been selected or configured yet. The block does not gracefully handle a missing or NULL assistant reference.</p> <p>The impact is critical because it takes down the entire site, requiring manual cleanup via drush to delete the broken block configurations.</p> <h4 id="summary-steps-reproduce">Steps to reproduce:</h4> <ol> <li>Enable <code>ai_chatbot</code> module</li> <li>Go to <code>/admin/structure/block</code> and place the "AI Chatbot" block in a theme region</li> <li>Do not configure an AI Assistant entity reference in the block settings (or place it before any AI Assistant entities exist)</li> <li>Visit any page rendered by that theme</li> <li>Site crashes with AssertionError</li> </ol> <p>AI modules enabled: ai, ai_chatbot, ai_assistant_api, ai_agents<br> AI provider: any (not provider-specific)<br> Browser: any (server-side error)</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>The block should gracefully handle a missing or unconfigured assistant reference. Options:</p> <ul> <li>Check for NULL/empty assistant ID in <code>blockAccess()</code> and return <code>AccessResult::forbidden()</code> when no assistant is configured</li> <li>Add a NULL check in <code>build()</code> before attempting to load the ai_assistant entity, returning an empty render array if not configured</li> <li>Show an admin-only warning message instead of crashing</li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks suggested by AI</h3> <ul> <li>Add NULL check for assistant ID before entity load</li> <li>Add test coverage for block rendering without configured assistant</li> <li>Review and commit</li> </ul> <h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3> <p>Workaround: delete the broken block configurations via drush:<br> <code>drush php-eval "\Drupal::entityTypeManager()-&gt;getStorage('block')-&gt;load('BLOCK_ID')-&gt;delete();"</code></p> <p>Discovered while creating demo content for the Drupal AI 1.3.0 blog post. Affected version: 1.3.0-rc2.</p> <h3 id="summary-ai-usage">AI usage</h3> <p>[x] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
issue