Skip to content

fix: guard against None converter results in RemoteA2aAgent - #5199

Closed
enjoykumawat wants to merge 2 commits into
google:mainfrom
enjoykumawat:fix/remote-a2a-agent-none-check
Closed

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

Conversation

@enjoykumawat

Copy link
Copy Markdown
Contributor

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
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @enjoykumawat , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

@rohityan

Copy link
Copy Markdown
Collaborator

Hi @DeanChensj , can you please review this.

@rohityan rohityan added the needs review [Status] The PR/issue is awaiting review from the maintainer label Apr 13, 2026
@haranrk haranrk assigned haranrk and unassigned rohityan Jun 17, 2026
copybara-service Bot pushed a commit that referenced this pull request Jun 17, 2026
Merge #5199

## 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

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

Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=#5199 from enjoykumawat:fix/remote-a2a-agent-none-check 8550233
PiperOrigin-RevId: 933978968
@adk-bot

adk-bot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Thank you @enjoykumawat for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit 23ff66e.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jun 17, 2026
@adk-bot adk-bot closed this Jun 17, 2026
FrigaZzz pushed a commit to FrigaZzz/adk-python that referenced this pull request Aug 11, 2026
Merge google#5199

## Summary

Fixes google#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

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

Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=google#5199 from enjoykumawat:fix/remote-a2a-agent-none-check 8550233
PiperOrigin-RevId: 933978968
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 merged [Status] This PR is merged needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoteA2aAgent handlers crash on None converter results (AttributeError)

4 participants