Skip to content

fix(a2a): set final=True for error TaskStatusUpdateEvent in event_converter#5389

Open
kuishou68 wants to merge 4 commits into
google:mainfrom
kuishou68:fix/event-converter-error-final-flag
Open

fix(a2a): set final=True for error TaskStatusUpdateEvent in event_converter#5389
kuishou68 wants to merge 4 commits into
google:mainfrom
kuishou68:fix/event-converter-error-final-flag

Conversation

@kuishou68
Copy link
Copy Markdown

Closes #5388

Problem

In _create_error_status_event inside src/google/adk/a2a/converters/event_converter.py, the TaskStatusUpdateEvent for a failed task is incorrectly created with final=False:

return TaskStatusUpdateEvent(
    ...
    status=TaskStatus(state=TaskState.failed, ...),
    final=False,  # BUG: should be True
)

A failed state is terminal — no further events will follow, so final must be True. Consumers that check this flag will otherwise wait indefinitely or mishandle the error.

Fix

Change final=Falsefinal=True in _create_error_status_event.

The equivalent code in from_adk_event.py already uses final=True correctly (line 154), so this change makes event_converter.py consistent.

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

…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>
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 19, 2026

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 pytest results to verify the fix? This will help speed up the review process.

Thanks!

@adk-bot adk-bot added the mcp [Component] Issues about MCP support label Apr 19, 2026
@rohityan rohityan self-assigned this Apr 20, 2026
@rohityan rohityan added a2a [Component] This issue is related a2a support inside ADK. needs review [Status] The PR/issue is awaiting review from the maintainer and removed mcp [Component] Issues about MCP support labels Apr 27, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

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.

@rohityan
Copy link
Copy Markdown
Collaborator

Hi @sasha-gitg , can you please review this.

@rohityan rohityan requested a review from sasha-gitg May 12, 2026 03:24
Copy link
Copy Markdown
Collaborator

@sasha-gitg sasha-gitg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a2a [Component] This issue is related a2a support inside ADK. 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.

bug: error TaskStatusUpdateEvent has final=False in event_converter.py

4 participants