Skip to content

Commit 2009df0

Browse files
Document callback registry lifecycle risk and add stream() override
T9: Add javadoc to LocalActivityToolCallbackWrapper explaining the leak risk when workflows are evicted from worker cache mid-execution. T11: Override stream() in ActivityChatModel to throw UnsupportedOperationException with a clear message, since streaming through Temporal activities is not supported. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8918fd commit 2009df0

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

temporal-spring-ai/src/main/java/io/temporal/springai/model/ActivityChatModel.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.core.io.ByteArrayResource;
2424
import org.springframework.util.CollectionUtils;
2525
import org.springframework.util.MimeType;
26+
import reactor.core.publisher.Flux;
2627

2728
/**
2829
* A {@link ChatModel} implementation that delegates to a Temporal activity.
@@ -169,6 +170,19 @@ public String getModelName() {
169170
return modelName;
170171
}
171172

173+
/**
174+
* Streaming is not supported through Temporal activities.
175+
*
176+
* @throws UnsupportedOperationException always
177+
*/
178+
@Override
179+
public Flux<ChatResponse> stream(Prompt prompt) {
180+
throw new UnsupportedOperationException(
181+
"Streaming is not supported in ActivityChatModel. "
182+
+ "Temporal activities are request/response based and cannot stream partial results. "
183+
+ "Use call() instead.");
184+
}
185+
172186
@Override
173187
public ChatOptions getDefaultOptions() {
174188
return ToolCallingChatOptions.builder().build();

temporal-spring-ai/src/main/java/io/temporal/springai/tool/LocalActivityToolCallbackWrapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
* and executes it.
2424
*
2525
* <p><b>Memory Management:</b> Callbacks are automatically removed from the map after execution to
26-
* prevent memory leaks.
26+
* prevent memory leaks. However, if a workflow is evicted from the worker's cache mid-execution
27+
* (between registering a callback and the {@code finally} block that removes it), the callback
28+
* reference will leak until the worker is restarted. This is bounded by the number of concurrent
29+
* in-flight tool calls and is unlikely to be a practical issue, but callers should be aware that
30+
* the registry size ({@link #getRegisteredCallbackCount()}) may drift above zero under heavy
31+
* eviction pressure.
2732
*
2833
* <p>This class is primarily used by {@code SandboxingAdvisor} to wrap unsafe tools.
2934
*

0 commit comments

Comments
 (0)