Repository navigation
fix(a2a): suppress cancellation after final event - #2940
wmh123wmh1 wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Package-private A2AHttpClient decorator that suppresses the spurious CancellationException the a2a-java-sdk 0.3.3 emits after a final status-update, wired into A2aAgent's default JSON-RPC transport. Direction looks right and the callback matrix is well tested (final vs non-final, malformed JSON, non-cancellation errors, builder delegation, forward of post()).
The three substantive findings below are all the same gap: the decorator filters errorConsumer, but not the two other ways a stream terminates — the returned CompletableFuture and completeRunnable. If the SDK signals the cancellation through either of those instead, a caller either still sees the error or sees a stream that never terminates. CI is green and the CLA is signed, so nothing here blocks the change — I'd just like confirmation on the completion-signal question.
Automated review by github-manager-bot
| messageConsumer.accept(message); | ||
| }, | ||
| error -> { | ||
| if (!completed.get() || !isCancellation(error)) { |
There was a problem hiding this comment.
[Warning] Suppressing the error here drops the only terminal signal the consumer gets: when the SDK reports the post-final cancellation through errorConsumer, completeRunnable is not invoked either, so a caller that closes its stream / releases resources in onComplete will see a stream that never terminates (it just goes quiet). Please confirm the SDK's behaviour for this path and, if it holds, run completeRunnable (or otherwise signal completion) when the error is suppressed, e.g.
error -> {
if (completed.get() && isCancellation(error)) {
completeRunnable.run(); // terminal signal, exactly once
} else {
errorConsumer.accept(error);
}
}If postAsyncSSE can call both callbacks, guard with an AtomicBoolean compare-and-set so the consumer still sees exactly one terminal event.
| Runnable completeRunnable) | ||
| throws IOException, InterruptedException { | ||
| completed.set(false); | ||
| return delegate.postAsyncSSE( |
There was a problem hiding this comment.
[Warning] The decorator only filters the three callbacks; the CompletableFuture returned by the delegate is passed through untouched. If JdkA2AHttpClient completes that future exceptionally with the same CancellationException (rather than / in addition to invoking errorConsumer), any caller that joins or composes on the returned future will still observe the spurious failure, i.e. the fix would be incomplete for those call sites. Could you verify how the 0.3.3 SDK surfaces this cancellation and, if the future is also affected, wrap the return value as well (.exceptionally(t -> completed.get() && isCancellation(t) ? null : rethrow(t)))? A test that inspects the returned future's state in the suppressed case would pin this down — all current tests drive the callbacks directly and use the mock's never-completed future, so this path is untested.
|
|
||
| private static boolean isFinalStatusUpdate(String message) { | ||
| try { | ||
| JsonNode root = Utils.OBJECT_MAPPER.readTree(message); |
There was a problem hiding this comment.
[Warning] This runs a full Jackson tree parse for every SSE chunk, on top of the parse the SDK itself already does, so a long message/stream response pays double deserialization on the hot path (artifact/token chunks can be many and large). A cheap pre-filter keeps the behaviour identical while making the non-matching case nearly free:
if (message == null || message.indexOf('"') < 0
|| !message.contains("status-update")) {
return false;
}Alternative: only try detection while completed is still false, since once a final status update has been seen there is nothing left to record.
| } | ||
|
|
||
| @Override | ||
| public GetBuilder createGet() { |
There was a problem hiding this comment.
[Info] createGet() is delegated unwrapped, so only the POST streaming path gets the fix. If the same SDK bug can surface on the GET-based SSE path (e.g. tasks/resubscribe / polling a running task), that path is still exposed. Worth a one-line comment stating the intended scope ("only message/stream over JSON-RPC POST is affected") so the next reader does not treat the missing GET wrapper as an oversight — or wrap GetBuilder symmetrically if it can also stream.
| return result != null | ||
| && "status-update".equals(result.path("kind").asText()) | ||
| && result.path("final").asBoolean(false); | ||
| } catch (IOException | RuntimeException ignored) { |
There was a problem hiding this comment.
[Info] The parse failure is swallowed silently, which is the right default for non-JSON keep-alives, but it also means a genuinely final event that does not match the expected shape (different envelope, or final nested differently) silently disables the suppression and the user keeps seeing the confusing CancellationException. A one-line debug/trace log here (and one when an error is actually suppressed at line 145) would make field diagnosis of "why is this workaround not working" much cheaper.
| builder.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfig()); | ||
| builder.withTransport( | ||
| JSONRPCTransport.class, | ||
| new JSONRPCTransportConfig(new CancellationSuppressingA2aHttpClient())); |
There was a problem hiding this comment.
[Info] This changes the default client for every A2aAgent built without explicit transports, with no opt-out, and the suppression is a behaviour change (errors disappear) rather than a pure fix. Two small things would make it easier to live with: (1) link the upstream SDK issue/PR in the Javadoc of CancellationSuppressingA2aHttpClient together with the version that fixes it, so the workaround can be deleted mechanically later; (2) consider gating it behind an A2aAgentConfig flag (default on) so users who want to observe cancellations are not stuck.
|
Fixed in: #3590 |
Summary
a2a-java-sdk 0.3.3.Finaland A2A Protocol v0.3 compatibility.CancellationExceptionemitted after a final status update.Testing
mvn -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-a2a/agentscope-extensions-a2a-client -am testFixes #2927