Repository navigation
Closed
Labels
bugSomething isn't working
Description
Description
When using the JSON-RPC streaming client with a2a-java-sdk version 0.3.3.Final, the error callback is invoked with:
Request cancelled
after the client has already received a valid terminal TaskStatusUpdateEvent with final=true.
The remote A2A task completes successfully, but the client reports the normal end of the stream as an error.
## Environment
- a2a-java-sdk: 0.3.3.Final
- Transport: JSON-RPC over SSE
- HTTP client: JdkA2AHttpClient
- Java: 21
- A2A method: message/stream
- Protocol version: A2A 0.3.x
Relevant dependencies:
<dependency>
<groupId>io.github.a2asdk</groupId>
<artifactId>a2a-java-sdk-client</artifactId>
<version>0.3.3.Final</version>
</dependency>
<dependency>
<groupId>io.github.a2asdk</groupId>
<artifactId>a2a-java-sdk-client-transport-jsonrpc</artifactId>
<version>0.3.3.Final</version>
</dependency>
<dependency>
<groupId>io.github.a2asdk</groupId>
<artifactId>a2a-java-sdk-http-client</artifactId>
<version>0.3.3.Final</version>
</dependency>
## Steps to reproduce
Create an A2A client with JSON-RPC streaming enabled:
ClientConfig config = ClientConfig.builder()
.setStreaming(true)
.setPolling(false)
.build();
Client client = Client.builder(agentCard)
.withTransport(
JSONRPCTransport.class,
new JSONRPCTransportConfig(new JdkA2AHttpClient()))
.clientConfig(config)
.build();
Send a streaming message:
client.sendMessage(
message,
List.of((event, card) -> {
System.out.println("EVENT: " + event);
}),
error -> {
System.out.println("ERROR: " + error);
},
null);
The server returns normal A2A SSE events and eventually sends:
{
"jsonrpc": "2.0",
"id": "request-id",
"result": {
"taskId": "task-id",
"status": {
"state": "completed",
"timestamp": "2026-09-01T06:19:29.2982548Z"
},
"contextId": "context-id",
"final": true,
"kind": "status-update"
}
}
The server logs confirm that the task completed successfully:
Agent execution completed successfully
Task completed: signal=onComplete
However, immediately after the final event, the client error callback receives:
Request cancelled
## Actual behavior
The callback sequence is effectively:
TaskStatusUpdateEvent(final=true)
errorHandler(Request cancelled)
The application therefore sees a successfully completed A2A task as a failed streaming request.
The issue does not occur when the same endpoint is called with curl -N. curl receives the terminal event and exits normally.
## Expected behavior
After receiving:
{
"kind": "status-update",
"final": true,
"status": {
"state": "completed"
}
}
the client should complete normally.
Expected callback behavior:
TaskStatusUpdateEvent(final=true)
completion callback
The error callback should not receive Request cancelled for an internally initiated stream shutdown after a valid final event.
## Suspected root cause
SSEEventListener.handleMessage() appears to cancel the HTTP future after delivering a final status event:
eventHandler.accept(streamingEvent);
if (streamingEvent instanceof TaskStatusUpdateEvent statusUpdate
&& statusUpdate.isFinal()) {
future.cancel(true);
}
Cancelling the JDK HTTP client's future causes the HTTP layer to report:
Request cancelled
The resulting exception is then forwarded by SSEEventListener.onError():
public void onError(Throwable error, Future<Void> future) {
if (errorHandler != null) {
errorHandler.accept(error);
}
future.cancel(true);
}
The client therefore does not distinguish between:
1. an internal cancellation after receiving final=true;
2. a user-initiated cancellation;
3. an actual network or transport failure.
The completed flag also appears to be set only from onComplete(), not when a final TaskStatusUpdateEvent is received.
## Suggested fix
Mark the listener as successfully completed before cancelling the HTTP future, and suppress the cancellation exception caused by this internal
cleanup.
For example:
private volatile boolean completed;
private void handleMessage(JsonNode message, Future<Void> future) {
StreamingEventKind event = parseEvent(message);
eventHandler.accept(event);
if (event instanceof TaskStatusUpdateEvent statusUpdate
&& statusUpdate.isFinal()) {
completed = true;
future.cancel(true);
signalSuccessfulCompletion();
}
}
public void onError(Throwable error, Future<Void> future) {
if (completed && isCancellation(error)) {
return;
}
if (errorHandler != null) {
errorHandler.accept(error);
}
}
Alternatively, the client could wait for the server to close the SSE connection naturally instead of cancelling the future after receiving
final=true.
## Workaround
At the application layer, we currently ignore Request cancelled only when:
- a final event has already been received; or
- valid response artifacts have already been received.
A cancellation received before any valid response is still treated as a real error.
This workaround prevents successful A2A streaming tasks from being reported as failures, but the behavior would be better fixed inside the SDK.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
wmh123wmh1 commentedon Sep 2, 2026
Hi, I’d like to investigate this issue.
AgentScope Java currently uses
a2a-java-sdk 0.3.3.Final. I’ll first reproduce the spuriousCancellationExceptionafter a finalTaskStatusUpdateEvent, then add a regression test and determine whether the fix should be made in AgentScope Java or upstream in the A2A SDK.If no one is currently working on it, I’d be happy to submit a PR.
wmh123wmh1 commentedon Sep 2, 2026
I traced the current AgentScope path further. Once a terminal A2A event is handled,
ClientEventContext.complete(...)already completes the AgentScope call successfully; a later SDK cancellation therefore does not reach the caller as a second failure, although the currentA2aAgentimplementation still logs it as a cancellation warning.The reported error-callback behavior itself is in
a2a-java-sdk 0.3.3.Final(JdkA2AHttpClient), and a corresponding fix has already landed upstream in a2a-java#951. I’m checking whether a compatible dependency update is possible before proposing an AgentScope change, so I’ll avoid opening a PR here that cannot meaningfully reproduce the reported callback behavior.skyXJJ commentedon Sep 2, 2026
Thanks for the detailed investigation.
One additional constraint on our side is that our current A2A integration is still based on A2A Protocol v0.3, so we need to remain compatible with the v0.3 protocol for now.
I noticed that the fix in a2a-java#951 is available in a newer A2A Java SDK release, while AgentScope Java currently depends on a2a-java-sdk 0.3.3.Final.
Given this constraint, would it be possible to either:
upgrade to a newer SDK while still keeping compatibility with A2A Protocol v0.3, or
backport the #951 fix to the v0.3-compatible SDK/AgentScope integration?
Since we are still seeing the CancellationException with the current 0.3.3.Final dependency, we'd prefer a solution that does not require migrating our A2A protocol from v0.3 to v1.0 yet.
Thanks again for looking into this.
wmh123wmh1 commentedon Sep 2, 2026
Thanks for the clarification.
I opened PR #2940 with an AgentScope-side compatibility fix. It keeps the current
a2a-java-sdk 0.3.3.Finaland A2A Protocol v0.3, without migrating to Protocol v1.0.The fix wraps the default JSON-RPC HTTP client and suppresses only the internal
CancellationExceptionreceived after a terminalTaskStatusUpdateEvent. Cancellations before the final event and real transport errors are still propagated.Regression tests were added for these cases.
oss-maintainer commentedon Sep 13, 2026
Issue Evaluation
Category:
bug| Status: ConfirmedVerified against
main@39cd304a.Root cause: the "Request cancelled" text is not produced by this repo — it comes from the pinned upstream
a2a-java-sdk0.3.3.Final(agentscope-dependencies-bom/pom.xml:99-101), which fires the error callback with aCancellationExceptionwhen it tears down the SSE stream right after a valid terminalTaskStatusUpdateEvent. Our wrapper does not guard that callback:.../A2aAgent.java:218-239— theerr == nullsuccess branch is guarded byisTerminalDelivered()(:220), but theCancellationExceptionbranch (:232-234) and the generic error branch (:236-238) callcompleteExceptionally(err)unconditionally.ClientEventContext.java:100-117—complete()andcompleteExceptionally()contend on the sameterminalDelivered.compareAndSet(false, true), so when the error callback wins the race againstTaskUpdateEventHandler.java:119-121(context.complete(msg)after post-reasoning hooks), the Mono terminates with an error even though the task finished successfully.A2aAgentTest.javahas noCancellationException/ terminal-then-error case, so CI cannot catch the regression.Impact: every
A2aAgentuser with streaming (message/stream, JSON-RPC transport) gets a spurious failure on a successful remote task. Non-deterministic: the window widens with slow post-reasoning hooks or artifact conversion. Severity: medium (wrong result surfaced to the caller, no data loss).Suggested fix: apply the existing guard to both error branches —
if (!eventContext.isTerminalDelivered()) { eventContext.completeExceptionally(err); }(and the same inside theCancellationExceptionbranch after the warn log) atA2aAgent.java:232-238, keeping the CAS inClientEventContextas the second safety net. Add a regression test that delivers a terminal event and then invokes the error callback withCancellationException, asserting the Mono resolves with the successful result.No open PR touches
A2aAgent.java, so this is not a duplicate. An automated fix proposal will be generated on request — reply/approveto proceed with PR generation.Automated evaluation by github-manager-bot
oss-maintainer commentedon Sep 13, 2026
Correction to the comment above — an open PR already covers this; no automated proposal will be generated
The last line of the previous comment ("No open PR touches
A2aAgent.java") was wrong: the file-level duplicate scan had not finished when it was posted. Corrected state againstmain@39cd304a:fix(a2a): suppress cancellation after final event(@wmh123wmh1, OPEN, non-draft,MERGEABLE) explicitly statesFixes #2927, touchesA2aAgent.java, and adds regression tests for the callback behavior. It suppresses the internalCancellationExceptionat the client-wrapper level while still forwarding pre-final cancellations and real transport errors.A2aAgent.javabut for unrelated features (reasoning-event middleware routing / A2A 1.0 adaptation) — no conflict of purpose with fix(a2a): suppress cancellation after final event #2940.So the root-cause analysis above stands, but PR generation is skipped to avoid a competing duplicate. One input that would help the #2940 review rather than a new PR: the evaluation above locates the guard at
A2aAgent.java:232-238(isTerminalDelivered()short-circuit, reusing the pattern already applied on theerr == nullbranch at :220), whereas #2940 resolves it one layer lower by wrapping the JSON-RPC HTTP client. Both close the race; theA2aAgent-side guard additionally covers error paths the client wrapper does not see, and the client-wrapper side needs no change to our callback ordering. Reviewers can pick the seam.Automated by github-manager-bot