alibaba/spring-ai-alibaba · warning · UnsupportedOperationException
cancel is not implemented yet!
Error message
cancel is not implemented yet!
What it means
GeneratorPublisher wraps a Generator as a reactive Publisher, but cancellation of the underlying async operation is not yet supported in this library. Calling cancel() unconditionally throws UnsupportedOperationException. It is a placeholder API indicating an unfinished feature.
Source
Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/async/internal/reactive/GeneratorPublisher.java:69
/**
* Requests more elements from the upstream Publisher.
*
* <p>
* The Publisher calls this method to indicate that it wants more items. The
* parameter {@code n} specifies the number of additional items requested.
* @param n the number of items to request, a count greater than zero
*/
@Override
public void request(long n) {
}
/**
* Cancels the operation.
* @throws UnsupportedOperationException if the method is not yet implemented.
*/
@Override
public void cancel() {
throw new UnsupportedOperationException("cancel is not implemented yet!");
}
});
delegate.forEachAsync(subscriber::onNext).thenAccept(value -> {
subscriber.onComplete();
}).exceptionally(ex -> {
subscriber.onError(ex);
return null;
}).join();
}
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Do not call cancel(); let the generator run to completion or close the subscription instead
- Stop consuming the stream (dispose the subscription) and rely on downstream cancellation of forEachAsync
- Upgrade the library version in case cancellation support has been added
- Wrap cancel() usage behind a capability check and degrade gracefully when unsupported
Example fix
// before
publisher.cancel();
// after
if (publisher.supportsCancel()) { publisher.cancel(); } else { subscription.dispose(); } Defensive patterns
Strategy: try-catch
Validate before calling
boolean cancelable = !(publisher instanceof GeneratorPublisher);
Type guard
boolean supportsCancel(Object p) { return !(p instanceof com.alibaba.cloud.ai.graph.async.internal.reactive.GeneratorPublisher); } Try / catch
try { publisher.cancel(); } catch (UnsupportedOperationException e) { subscription.dispose(); } Prevention
- Avoid depending on cancel() for generator-backed streams
- Dispose subscriptions instead of cancelling
- Check library release notes for cancellation support
When it happens
Trigger: Obtaining the Subscribable/publishable wrapper around a Generator-based async graph stream and invoking its cancel() method (e.g. aborting a streaming run mid-flight).
Common situations: Developers building reactive streaming UIs who try to abort a long-running generator-driven graph execution on user disconnect or timeout.
Related errors
- Currently Spring AI ToolResponseMessage only supports text t
- A2aRemoteAgent has not support schedule.
- LoopAgent must have only one subAgent, please use subAgent()
- Async tool execution failed
- Tool execution was cancelled
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/006838d60f0a357a.
Report an issue: GitHub.