[Tracker]
Update Summary: [One-line status update for stakeholders]
Short Description: [One-line issue summary for stakeholders]
Check-in Date: MM/DD/YYYY
Metadata is used by the AI Tracker. Docs and additional fields here.
[/Tracker]

Problem/Motivation

Drupal\ai_agents\PluginBase\AiAgentEntityWrapper declares the property $aiConfiguration without an initial value:

/**
 * The AI configuration.
 *
 * @var array
 */
protected $aiConfiguration;

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->aiConfiguration = $data['ai_configuration'] ?? [];).
But for agents created directly via createInstance() — which is exactly what ai_assistant_api's AgentRunner::runAsAgent() does on every fresh turn — the property stays NULL until something explicitly calls setAiConfiguration().

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.
That subscriber constructs an AiProviderRequest value object and passes $event->getAgent()->getAiConfiguration() directly into the array $config parameter of the constructor. Because the property is still NULL, PHP throws:

TypeError: Drupal\ai_agents\Service\AgentStatus\UpdateItems\AiProviderRequest::__construct():
Argument #9 ($config) must be of type array, null given,
called in .../src/EventSubscriber/AgentStatusSubscriber.php on line 178
The site crashes with a 500 the moment the agent runs.

Steps to reproduce (required for bugs, but not feature requests)

Modules enabled: Except the deprecated all of them are enabled.

1. Have an AI Assistant configured with an AI Agent (so runAsAgent() is the execution path).
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".)
3. Trigger the assistant.
Expected: Agent runs and dispatches AgentRequestEvent/AgentFinishedExecutionEvent normally. Actual: TypeError on AiProviderRequest::__construct(), full WSOD.

Proposed resolution

Two complementary one-line fixes:

1. Initialize the property to an empty array so a freshly-created agent always exposes a valid array from getAiConfiguration().
2.. Defensively normalize at the call site in AgentStatusSubscriber so any future code path that mutates aiConfiguration to NULL does not crash status tracking.

Fix 1 — initialize the property
src/PluginBase/AiAgentEntityWrapper.php line 67:

/**
 * The AI configuration.
 *
 * @var array
 */
protected $aiConfiguration = [];

Fix 2 — normalize at the call site
src/EventSubscriber/AgentStatusSubscriber.php around line 187:

if ($this->checkLogEventType($event, AiAgentStatusItemTypes::Request)) {
  $this->statusStorage->storeStatusUpdateItem($event->getThreadId(), new AiProviderRequest(
    time: $combined_ms,
    agent_id: $event->getAgentId(),
    agent_name: $event->getAgent()->getAiAgentEntity()->label(),
    agent_runner_id: $event->getAgentRunnerId(),
    loop_count: $event->getLoopCount(),
    request_data: $event->getChatInput()->toArray(),
    provider_name: $event->getAgent()->getAiProvider()->getPluginId(),
    model_name: $event->getAgent()->getModelName(),
    config: $event->getAgent()->getAiConfiguration() ?? [],
    calling_agent_id: $event->getCallerId(),
  ));
}

Remaining tasks

1. Add a unit/kernel test that creates an agent via createInstance(), enables progress tracking, dispatches AgentRequestEvent, and asserts no TypeError is thrown.

Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)

AI usage (if applicable)

[x] AI Assisted Issue
This issue was generated with AI assistance, but was reviewed and refined by the creator.

[x] AI Assisted Code
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.

[ ] AI Generated Code
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.

[ ] Vibe Coded
This code was generated by an AI and has only been functionally tested.

Issue fork ai-3584129

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joaopauloc.dev created an issue. See original summary.

joaopauloc.dev’s picture

Status: Active » Closed (won't fix)

Wrong module, sorry.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.