fix(a2a-server): preserve canceled streaming task status

HU
6d ago
+195-88

PR Checklist

Bugs / Features

  • Related issue(s) linked — independently reproduced; no issue has been opened.
  • Tests for the changes have been added.
  • Docs have been added / updated — no public API change.
  • Changesets have been added.

What is the current behavior?

After tasks/cancel returns a canceled task, message/stream can overwrite that task with completed if the agent's iterator ends normally on abort. A buffered chunk arriving after cancellation is also appended. Cancellation before the agent call or while awaiting completion metadata can similarly be ignored.

The existing cancellation test covers an iterator that throws on abort, which reaches the cancellation handler. Normal iterator completion bypasses that handler.

What is the new behavior?

Check the AbortSignal before starting the agent, after stream initialization, before accepting chunks, after iteration, and before saving the completed result. An aborted operation uses the existing cancellation handler and cleanup path.

Extend the cancellation test to cover throwing, normal completion, and a late chunk. Add cases for cancellation before the agent call and while awaiting completion metadata. Check both final stream events and persisted task status.

Notes for reviewers

On baseline 72a46c76b4507e1f98b41d5050a92bd30587eb70, the new regression cases produced four failures. With this fix, all 13 A2A package tests pass. Local type checking, CJS/ESM/declaration builds, Biome checks for the two changed TypeScript files, and git diff --check also pass.

Validation used a separate pinned npm toolchain because the workspace's frozen pnpm installation failed with connection resets from the configured npm mirror. Core/internal dependencies were published packages at the same versions as the workspace manifests. The complete workspace dependency installation and CI were not validated. Tests use a stub agent and the in-memory task store; no live provider was exercised.

This patch preserves cancellation at the covered stream boundaries. It does not add transactional concurrency guarantees for custom asynchronous task stores. Preparation and local validation were AI-assisted.


Summary by cubic

Fixes @voltagent/a2a-server overwriting a canceled task with completed when the agent stream ends normally on abort, and prevents a buffered chunk from being appended after cancellation.

  • Checks the AbortSignal before starting the agent, after stream initialization, before accepting chunks, after iteration, and before saving the completed result; an aborted operation reuses the existing cancellation handler and cleanup path.
  • Extends cancellation tests to cover throwing iterators, normal completion, late chunks, cancellation before the agent call, and cancellation while awaiting completion metadata, asserting both final stream events and persisted task status.

Summary by CodeRabbit

  • Bug Fixes
    • Canceled tasks now remain canceled if a stream ends normally or produces a late update.
    • Canceling before streaming begins prevents the stream from starting.
    • Cancellation remains effective while completion details are being retrieved.