Skip to content

feat: Enforce events ordering#437

Merged
bartek-gralewicz merged 10 commits into
epic/1.0_breaking_changesfrom
bgralewicz/enforce_stream_ordering
May 4, 2026
Merged

feat: Enforce events ordering#437
bartek-gralewicz merged 10 commits into
epic/1.0_breaking_changesfrom
bgralewicz/enforce_stream_ordering

Conversation

@bartek-gralewicz
Copy link
Copy Markdown
Contributor

@bartek-gralewicz bartek-gralewicz commented Apr 29, 2026

Description

This PR introduces a stream ordering enforcement as stated in protocol spec 3.1.2 ("Behavior" section).

The stream should distinguish 2 cases:

  • The Message is the first streamed object.
    • In such case, the stream should not accept any more objects and close right after the initial message. The UnsupportedOperationError is thrown if such case occurs.
  • The Task is the first streamed object.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/server/request_handler/default_request_handler.ts 82.02% 81.88% 🔴 -0.14%
src/server/utils.ts 63.63% 69.23% 🟢 +5.60%
Total 87.81% 87.76% 🔴 -0.05%

Generated by coverage-comment.yml

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 introduces stream ordering enforcement for agent responses, ensuring they follow either a message-only or a task-lifecycle pattern. While the logic correctly filters events in the response stream, two significant issues were identified: invalid events are still being persisted to the TaskStore because validation occurs after processing, and the message-only pattern check is currently unreachable due to the underlying event queue's termination behavior. Additionally, one of the new unit tests needs to be updated to actually simulate the out-of-order events it intends to verify.

Comment thread src/server/request_handler/default_request_handler.ts
Comment thread test/server/default_request_handler.spec.ts
@bartek-gralewicz

This comment was marked as outdated.

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 introduces stream ordering validation within the DefaultRequestHandler to enforce specific patterns for streaming responses, such as 'message-only' or 'task-lifecycle'. It includes a new StreamPattern enum and logic to skip events that violate the expected sequence. The review feedback suggests that protocol violations should result in an explicit UnsupportedOperationError being thrown rather than just logging a warning and skipping the event, ensuring the client is properly notified of the failure.

Comment thread src/server/request_handler/default_request_handler.ts Outdated
Comment thread src/server/request_handler/default_request_handler.ts Outdated
@bartek-gralewicz

This comment was marked as outdated.

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 implements stream ordering enforcement in the DefaultRequestHandler to align with protocol specifications. It introduces a StreamPattern state machine that tracks whether a response follows a message-only or task-lifecycle pattern, throwing errors for invalid event transitions. Feedback focuses on strictly prohibiting subsequent 'task' events within a task-lifecycle stream and refining error messages to correctly identify valid initial event types.

Comment thread src/server/request_handler/default_request_handler.ts
Comment thread src/server/request_handler/default_request_handler.ts Outdated
@bartek-gralewicz

This comment was marked as outdated.

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 implements stream ordering enforcement for agent execution events by introducing a StreamPattern enum and validation logic. The changes ensure streams follow either a message-only or task-lifecycle pattern, throwing errors for invalid sequences. Review feedback correctly identified a bug in the error handling logic that would cause an ordering violation and a potential hang, along with an incomplete test case that failed to properly verify the message-only enforcement.

Comment thread src/server/request_handler/default_request_handler.ts
Comment thread test/server/default_request_handler.spec.ts Outdated
@bartek-gralewicz bartek-gralewicz marked this pull request as ready for review April 30, 2026 08:43
@bartek-gralewicz bartek-gralewicz requested a review from a team as a code owner April 30, 2026 08:43
Comment thread src/server/request_handler/default_request_handler.ts Outdated
Comment thread src/server/request_handler/default_request_handler.ts
Comment thread src/server/request_handler/default_request_handler.ts
@ishymko ishymko changed the title feat: Enforce stream ordering feat: Enforce events ordering Apr 30, 2026
@bartek-gralewicz bartek-gralewicz merged commit 157cf48 into epic/1.0_breaking_changes May 4, 2026
10 checks passed
@bartek-gralewicz bartek-gralewicz deleted the bgralewicz/enforce_stream_ordering branch May 4, 2026 06:22
ishymko added a commit that referenced this pull request May 11, 2026
🤖 I have created a release *beep* *boop*
---

## 1.0.0-alpha.0 (2026-05-11)

See the [v0.3 -> v1.0-alpha.0 migration
guide](https://github.com/a2aproject/a2a-js/blob/v1.0.0-alpha.0/docs/migration-guide.md).

**Note**: Enabling backward compatibility with v0.3 is tracked in
[#452](#452).


### ⚠ BREAKING CHANGES

* Drop support for node 18
([#368](#368))
* Make ServerCallContext parameter mandatory across all places
([#405](#405))
* Remove JSON-RPC client
([#353](#353))
* Remove transport-specific exports
([#404](#404))
* Update codebase to use A2A 1.0.0 data model
([#375](#375))
* Remove A2AExpressApp
([#363](#363))

### Features

* Add A2A Version Header
([#422](#422))
([b5f3db7](b5f3db7))
* Add cache-headers logic to the agent card handler
([#435](#435))
([955b52b](955b52b))
* Add resource scoping
([#450](#450))
([c527086](c527086))
* Add support for custom authentication scheme and credentials in
auth-headers ([#430](#430))
([5a4389b](5a4389b))
* AgentCardSignature support
([#448](#448))
([4a41a8c](4a41a8c))
* Enforce events ordering
([#437](#437))
([157cf48](157cf48))
* Enriched Error Model
([#427](#427))
([c130778](c130778))
* Implement listTasks method
([#383](#383))
([7d4c472](7d4c472))
* Send current task as the first event after subscribing to it
([#418](#418))
([4bfcf5f](4bfcf5f))
* Support multi-tenancy
([#419](#419))
([1877877](1877877))

### Code Refactoring

* remove A2AExpressApp
([#363](#363))
([0b84728](0b84728))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: bartek-gralewicz <bgralewicz@google.com>
Co-authored-by: Ivan Shymko <ishymko@google.com>
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.

2 participants