Skip to content

fix: return TaskNotFoundError when SendMessage references non-existent taskId#788

Open
yyy9942 wants to merge 1 commit intoa2aproject:mainfrom
yyy9942:issue-766
Open

fix: return TaskNotFoundError when SendMessage references non-existent taskId#788
yyy9942 wants to merge 1 commit intoa2aproject:mainfrom
yyy9942:issue-766

Conversation

@yyy9942
Copy link
Copy Markdown

@yyy9942 yyy9942 commented Apr 10, 2026

Per A2A spec section 3.4.2, when a client includes a taskId in a Message, it MUST reference an existing task. The SDK was creating a new task with that id instead.

Added a guard in DefaultRequestHandler.initMessageSend() that throws TaskNotFoundError when the provided taskId does not reference an existing task.

This fixes the issue on all three transports (JSON-RPC, gRPC, HTTP+JSON) since they all use the same DefaultRequestHandler code path.

Also fixes a related contextId bug: when a follow-up message had a taskId but no contextId, RequestContext.Builder.build() was generating a fresh UUID, so the agent executor saw the wrong contextId. The rebuild now seeds contextId from the stored task.

Existing tests that relied on the old taskId behavior have been updated.

Fixes #766

…t taskId

Per A2A spec section 3.4.2, when a client includes a taskId in a Message,
it MUST reference an existing task. Previously, the SDK silently created a
new task using the client-provided taskId, which the spec explicitly
forbids.

Applies to all three transports (JSON-RPC, gRPC, HTTP+JSON) via the common
DefaultRequestHandler.initMessageSend() code path.

Existing tests that relied on the buggy behaviour have been updated to
either pre-populate the task store (when testing follow-up messages) or
omit the client-provided taskId on the initial message (letting the
server generate it, matching the spec-correct flow).

This fixes a2aproject#766
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enforces A2A spec section 3.4.2 by prohibiting client-provided taskId values for new task creation. The DefaultRequestHandler now validates that any provided taskId references an existing task, throwing a TaskNotFoundError otherwise. It also ensures that follow-up messages maintain the original contextId of a task. Correspondingly, integration and unit tests across multiple modules have been updated to rely on server-generated IDs and content-based routing for test scenarios. I have no feedback to provide.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SendMessage with unknown taskId creates a new task instead of returning TaskNotFoundError

1 participant