fix: #3621935 Fix agent process crash on a guessed, wrong display ID

Summary

ai_agents_views:update_view_plugins called ViewsAgentHelper:: getViewDisplayOptionsConfig() a second time, unguarded, once display_id, display_option, and config were all provided - unlike the three branches above it that catch this same method's exception when an argument is missing instead. A wrong-but-plausible display ID (for example, an agent guessing "page" instead of the real "page_1") threw an uncaught \Exception out of execute() entirely, which - combined with catch_errors being disabled for this tool - killed the whole agent process rather than becoming a tool result the agent could read and retry against.

Changes

  • src/Plugin/AiFunctionCall/UpdateViewPlugins.php: wraps the second, previously-unguarded getViewDisplayOptionsConfig() call in the same try/catch pattern already used by the other three call sites.
  • config/install/ai_agents.ai_agent.views_agent.yml: adds a "Display IDs" section to the system prompt - don't guess a display ID, confirm it, and recover by re-listing displays after a "does not exist" error. Tested alone first, before the code fix existed: it did not change the crash behavior by itself, confirming this needed a real code fix.
  • tests/src/Kernel/Plugin/AiFunctionCall/UpdateViewPluginsTest.php: added testInvalidDisplayIdWithFullArgumentsReturnsMessage().

Test plan

  • New regression test testInvalidDisplayIdWithFullArgumentsReturnsMessage confirmed failing before the fix (uncaught exception) and passing after.
  • Full test file passes on this branch in isolation: 15/15 tests, 123 assertions, no failures.
  • phpcs --standard=Drupal,DrupalPractice and phpstan analyse (module config, level 1) clean on both changed PHP files.

Closes #3621935

AI-Generated: Yes (Used Claude Code to identify the bug while testing the shipped Views Agent against a live LLM, diagnose the root cause, verify a prompt-only mitigation was insufficient, implement the code fix, and write the regression test.)

Edited by Jibran Ijaz

Merge request reports

Loading