Skip to content

fix: guard against None converter results in RemoteA2aAgent#5199

Open
enjoykumawat wants to merge 2 commits intogoogle:mainfrom
enjoykumawat:fix/remote-a2a-agent-none-check
Open

fix: guard against None converter results in RemoteA2aAgent#5199
enjoykumawat wants to merge 2 commits intogoogle:mainfrom
enjoykumawat:fix/remote-a2a-agent-none-check

Conversation

@enjoykumawat
Copy link
Copy Markdown

Summary

Fixes #5187

  • Problem: RemoteA2aAgent._handle_a2a_response and _handle_a2a_response_v2 crash with AttributeError when converter functions (convert_a2a_task_to_event, convert_a2a_message_to_event, or config-based converters) return None. The code immediately accesses .custom_metadata on the result without checking for None.
  • Fix: Added None-checks after every converter call in both handler methods. When a converter returns None, the handler now gracefully returns None (skip the event) instead of crashing.
  • Tests: Added TestHandleNoneConverterResults with three test cases covering the None return path for message converters and task converters in both v1 and v2 handlers.

Test plan

  • python -m pytest tests/unittests/agents/test_remote_a2a_agent.py -v -- all 98 tests pass
  • New tests specifically verify that _handle_a2a_response returns None when convert_a2a_message_to_event returns None
  • New tests verify that _handle_a2a_response returns None when convert_a2a_task_to_event returns None
  • New tests verify that _handle_a2a_response_v2 returns None when a2a_message_converter returns None

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Apr 7, 2026
@enjoykumawat enjoykumawat force-pushed the fix/remote-a2a-agent-none-check branch from 2d6d1ba to abd66a3 Compare April 7, 2026 20:21
@rohityan rohityan self-assigned this Apr 9, 2026
Converter functions (convert_a2a_message_to_event, convert_a2a_task_to_event)
return Optional[Event], but several handler paths in RemoteA2aAgent access
attributes on the result without checking for None first. This causes
AttributeError when a converter returns None (e.g., for empty messages
or metadata-only events).

Add `if not event: return None` guards at all four call sites in both
the legacy and new-style response handlers.

Github-Issue: google#5187
@enjoykumawat enjoykumawat force-pushed the fix/remote-a2a-agent-none-check branch from abd66a3 to 2d26d1d Compare April 9, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoteA2aAgent handlers crash on None converter results (AttributeError)

3 participants