From 01df19b0296b3833207a5f459f07cf7599ce9c16 Mon Sep 17 00:00:00 2001 From: huang yutong <3565724239@qq.com> Date: Mon, 4 May 2026 22:41:04 +0800 Subject: [PATCH] fix(a2a): always restore task.output_pydantic in finally block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In `_execute_task_with_a2a` and its async variant, the try body sets `task.output_pydantic = None` before returning an A2A response. The finally block then checks `if task.output_pydantic is not None` before restoring the original value — but since it was just set to None, the condition is always False and the original value is never restored. This permanently mutates the Task object. Remove the guard so `output_pydantic` is unconditionally restored, matching the unconditional restoration of `description` and `response_model` in the same block. Co-authored-by: Greyson LaLonde --- lib/crewai/src/crewai/a2a/wrapper.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/crewai/src/crewai/a2a/wrapper.py b/lib/crewai/src/crewai/a2a/wrapper.py index 7f54d60db..0ec7fc6ae 100644 --- a/lib/crewai/src/crewai/a2a/wrapper.py +++ b/lib/crewai/src/crewai/a2a/wrapper.py @@ -386,8 +386,7 @@ def _execute_task_with_a2a( return raw_result finally: task.description = original_description - if task.output_pydantic is not None: - task.output_pydantic = original_output_pydantic + task.output_pydantic = original_output_pydantic task.response_model = original_response_model @@ -1534,8 +1533,7 @@ async def _aexecute_task_with_a2a( return raw_result finally: task.description = original_description - if task.output_pydantic is not None: - task.output_pydantic = original_output_pydantic + task.output_pydantic = original_output_pydantic task.response_model = original_response_model