Resolve "Global LLM-based guardrails cause infinite recursive LLM calls (no re-entrancy guard)"

Resolves #3586466

A constant OPT_OUT_TAG = 'ai_guardrail_opt_out' was added to AiGuardrailHelper, and both guardrail subscribers GlobalGuardrailsEventSubscriber, GuardrailsEventSubscriber in its pre- and post-generate handlers) now early-return when the event carries that tag.

RestrictToTopic's internal classification call now passes the tag (chat($input, $model, ['ai', AiGuardrailHelper::OPT_OUT_TAG])), so the guardrail's own LLM request is no longer re-attached a global set or re-evaluated, which breaks the recursion.

A new kernel test testOptOutTagSkipsGuardrails() covers it; the suite passes (12 tests, 60 assertions), php -l is clean, and phpcs --standard=Drupal,DrupalPractice exits 0.

Edited by Marcus Johansson

Merge request reports

Loading