This repository is a small reproduction project aiming to demonstrate a potential bug linked to multi-subscription on A2A tasks.
It contains one Server project and one Client project.
Run with dotnet run command, it will expose an A2A server that has only one Agent. This agent is only task based and will, after a small delay, send a fixed number of events, all separated with a delay of 100 milliseconds.
Run with dotnet run command, it will connect to the server and resolve the hosted agent. Firstly, it will send a streaming request to this agent and listen to the provided taskId.
After that, it will connect 4 more subscribers to this task.
In the console, we can see 3 things:
- The children subscribers will share all artifact updates, with some updates being lost. (the firsts, the lasts and some in between)
- The main subscriber will, after all children subscriber, receive all artifact update.
- At the end of the program, I must use
await Task.WhenAnyinstead ofawait Task.WhenAllif a want the program to complete.
All children subscribers, like the main subscriber, should receive all artifact updates.
The problem is caused by the usage of an AsyncEnumerable internally by the A2A package. When the main subscriber send its requests, it receives a response in the form of an IAsyncEnumerable. This instance is stored internally. When any other client use the Subscribe endpoint, It receives the same instance of the IAsyncEnumerable. Internally, there are now multiple listener for a same IAsyncEnumerable, which is not a behavior allowed by this data structure.
A solution could be to migrate to another data structure that will allow the broadcast of every IAsyncEnumerable item.
-> For instance, this is the behavior on my computer:
