fix(a2a): set final=True for error TaskStatusUpdateEvent in event_converter#5389
fix(a2a): set final=True for error TaskStatusUpdateEvent in event_converter#5389kuishou68 wants to merge 4 commits into
Conversation
…verter When a task transitions to TaskState.failed, the resulting TaskStatusUpdateEvent should have final=True because the error state is terminal — no further events will follow. The existing from_adk_event.py already sets final=True for error events (line 154), but event_converter.py incorrectly uses final=False, which causes consumers to wait indefinitely for additional events after a failure. Closes google#5388 Signed-off-by: Cocoon-Break <54054995+kuishou68@users.noreply.github.com>
|
Response from ADK Triaging Agent Hello @kuishou68, thank you for your contribution! Your PR description is very clear and it's great that you've included an associated issue and a testing plan. As per our contribution guidelines, could you please also include a summary of the passed Thanks! |
|
Hi @kuishou68, 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. |
|
Hi @sasha-gitg , can you please review this. |
sasha-gitg
left a comment
There was a problem hiding this comment.
Thanks for the fix! The change looks correct and aligns with from_adk_event.py.
However, unit tests are missing to verify this change, as noted in the PR description.
I've verified the fix locally by adding a test case in test_event_converter.py to assert final=True for failed tasks. All unit tests passed.
Please add unit tests to this PR to ensure regression prevention. Here is the test case I used for verification:
def test_create_error_status_event(self):
"""Test creation of error status event sets final=True."""
self.mock_event.error_code = "ERROR_001"
self.mock_event.error_message = "Test error"
task_id = "test-task-id"
context_id = "test-context-id"
with patch(
"google.adk.a2a.converters.event_converter.datetime"
) as mock_datetime:
mock_datetime.fromtimestamp.return_value.isoformat.return_value = (
"2023-01-01T00:00:00"
)
result = _create_error_status_event(
self.mock_event,
self.mock_invocation_context,
task_id,
context_id,
)
assert isinstance(result, TaskStatusUpdateEvent)
assert result.task_id == task_id
assert result.context_id == context_id
assert result.status.state == TaskState.failed
assert result.final is True
Closes #5388
Problem
In
_create_error_status_eventinsidesrc/google/adk/a2a/converters/event_converter.py, theTaskStatusUpdateEventfor a failed task is incorrectly created withfinal=False:A
failedstate is terminal — no further events will follow, sofinalmust beTrue. Consumers that check this flag will otherwise wait indefinitely or mishandle the error.Fix
Change
final=False→final=Truein_create_error_status_event.The equivalent code in
from_adk_event.pyalready usesfinal=Truecorrectly (line 154), so this change makesevent_converter.pyconsistent.Testing
Existing unit tests for error event conversion should be updated/added to assert
final=True.Signed-off-by: Cocoon-Break 54054995+kuishou68@users.noreply.github.com