Commit ccaf4a6
temporal-spring-ai: accept ActivityOptions and classify non-retryable AI errors (#2853)
* temporal-spring-ai: plan — activity summaries for debuggability
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: amend plan — limit summaries to chat + MCP
Narrows the activity-summaries scope to cases where the plugin itself owns
activity-stub creation. Activity-backed tool calls, Nexus tool calls, and
@SideEffectTool calls are now explicitly out of scope; the first two would
require per-call option overrides on user-owned stubs (no clean API), and
the third writes MarkerRecorded events which have no Summary field.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: add ActivitySummaryTest (chat path)
Runs a workflow that drives a single chat call through ActivityChatModel,
fetches the resulting history, and asserts the ActivityTaskScheduled event
for callChatModel carries a userMetadata Summary that starts with
"chat: default" and includes the user prompt. Intentionally fails against
unmodified chat code — the implementation follows in a subsequent commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: attach activity summaries for chat and MCP calls
ActivityChatModel.forModel() now stores the ActivityOptions it built and,
on each chat call, rebuilds the stub with a per-call Summary of the form
"chat: <model> · <first 60 chars of user prompt>". When a caller passes a
pre-built stub directly via the public constructors, behavior is unchanged
(no options known → no summary overlay).
ActivityMcpClient.create() does the same and adds a callTool(clientName,
request, summary) overload. McpToolCallback passes "mcp: <client>.<tool>".
Also fixes the activity-type-name casing in ActivitySummaryTest — Temporal
capitalizes the first character of method-name-derived activity types, so
the event carries "CallChatModel", not "callChatModel".
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: drop PLAN.md
Planning scratchpad — not part of the shipped artifact. Removed before merge.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: drop user prompt from chat activity Summary
The Summary now carries only the model label ("chat: <model>") instead
of "chat: <model> · <first 60 chars of user prompt>". Including even a
truncated prompt leaks whatever the prompt contains — PII, secrets,
internal identifiers — into workflow history, server logs, and the
Temporal UI, which is a surprising default for an observability label.
An opt-in API for callers who explicitly want the prompt in the
Summary can be added later if there's demand.
ActivitySummaryTest.chatActivity_carriesModelOnlySummary_neverLeaksUserPrompt
asserts the Summary equals "chat: default" exactly and defensively
checks that no part of the prompt leaked in.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: wrap nullable fields/params in Optional<>
Addresses review feedback (thread on #2852) preferring typesafe
Optional<T> over nullable fields and raw null delegation. Three
sites changed:
- ActivityChatModel: modelName and baseOptions fields + private ctor
params are now Optional<String> / Optional<ActivityOptions>.
getModelName() returns Optional<String>. Public ctors and factories
still accept nullable String modelName at the API boundary (matches
prior javadoc: "null for default"); they normalize via
Optional.ofNullable before storing. Internal readers use .map /
.orElse instead of null checks.
- ActivityMcpClient: the 3-arg callTool's summary parameter is now
Optional<String>. The 2-arg convenience overload passes
Optional.empty(). The rebuild-with-summary branch uses
.isPresent() + .get() instead of null checks.
- McpToolCallback.call(...) wraps its generated summary string in
Optional.of(...) before passing to callTool.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: use @nullable annotations instead of Optional<>
Reverses the previous Optional<> commit in favor of @nullable on the
nullable fields/params. Matches the dominant convention in
temporal-sdk (431+ @nullable usages on public API surface) and avoids
a thicker runtime story for what is fundamentally a documentation /
IDE-hint concern (no NullAway in the build either way).
- ActivityChatModel: modelName and baseOptions fields + private ctor
params are now @nullable String / @nullable ActivityOptions. Public
ctors/factories accept nullable String modelName at the API
boundary directly. getModelName() returns @nullable String.
- ActivityMcpClient: baseOptions field and callTool(..., summary)
param use @nullable instead of Optional<>. 2-arg callTool passes
null; McpToolCallback passes a plain String.
- ChatModelTypes.ChatModelActivityInput record: @nullable on
modelName and modelOptions fields so deserialized readers see the
nullability in the signature (per the reviewer's concern about the
deserialization-side typesafety).
Consistent with org.springframework.lang.Nullable already used
elsewhere in this module (TemporalChatClient, SpringAiPlugin).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: use javax.annotation.Nullable for consistency
Switch the five files in this module that imported
org.springframework.lang.Nullable over to javax.annotation.Nullable
to match the dominant convention in sdk-java (197 usages vs. 7).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: plan — ActivityOptions overloads and non-retryable error classification
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: amend plan — ActivityOptions overloads fix summaries UX wart
The activity-summaries branch only overlays Summaries when the factories
(forModel/create) built the stub. Users who need custom timeouts today fall
back to the public constructor, which silently drops UI Summaries. The
ActivityOptions overloads planned here are the proper fix: they let users
customize the stub and keep Summary labels. Plan now also covers deprecating
the public constructors with javadoc pointing at the factories.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: accept ActivityOptions and classify non-retryable AI errors
- ActivityChatModel.forDefault(ActivityOptions) and forModel(String,
ActivityOptions) overloads added. New public defaultActivityOptions()
returns the plugin's default bundle so callers can tweak one field
without losing the other sensible defaults.
- ActivityMcpClient.create(ActivityOptions) + defaultActivityOptions()
added, mirroring the chat side.
- Default RetryOptions for chat calls now mark
org.springframework.ai.retry.NonTransientAiException and
java.lang.IllegalArgumentException non-retryable. Default options for
MCP calls mark IllegalArgumentException non-retryable. User-supplied
ActivityOptions pass through verbatim — the plugin does not augment
them.
- new ActivityChatModel(...) and new ActivityMcpClient(activity)
constructors are @deprecated with javadoc pointing at the factories —
they still work at runtime but skip the UI Summary labels the
plugin-owned stub path attaches, which is now called out explicitly.
- README: new "Activity options and retry behavior" section documents
the defaults, how to customize, and the Summary/factory connection.
- Tests: two new suites — ActivityOptionsAndRetryTest covers the
non-retryable classification (1 attempt for NonTransientAiException,
3 attempts for transient RuntimeException, custom task queue landing
on the scheduled activity); ActivitySummaryTest gains a regression
test asserting forDefault(customOptions) still emits UI Summaries.
- build.gradle: spring-ai-retry added as a testImplementation so tests
can reference NonTransientAiException directly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: drop PLAN.md
Planning scratchpad — not part of the shipped artifact. Removed before merge.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* temporal-spring-ai: remove (Duration, int) factory overloads
Now that forDefault(ActivityOptions) / forModel(String, ActivityOptions)
/ create(ActivityOptions) exist, the (Duration, int) convenience
overloads are asymmetric dead weight — they expose two of N ActivityOptions
fields as positional parameters, and callers wanting anything else
(heartbeats, task queue, custom retry backoff, ...) have to drop to the
ActivityOptions path anyway. Removed pre-release so the API surface is
consistent: no-arg → plugin defaults; ActivityOptions arg → caller options.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cad6172 commit ccaf4a6
7 files changed
Lines changed: 415 additions & 113 deletions
File tree
- temporal-spring-ai
- src
- main/java/io/temporal/springai
- chat
- mcp
- model
- test/java/io/temporal/springai
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
| 32 | + | |
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
| |||
Lines changed: 58 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 52 | | |
57 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
58 | 56 | | |
59 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 61 | + | |
| 62 | + | |
64 | 63 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
| 76 | + | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
92 | | - | |
93 | | - | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 97 | + | |
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
105 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
106 | 128 | | |
107 | 129 | | |
108 | 130 | | |
| |||
144 | 166 | | |
145 | 167 | | |
146 | 168 | | |
147 | | - | |
148 | | - | |
149 | | - | |
| 169 | + | |
150 | 170 | | |
151 | 171 | | |
152 | 172 | | |
| |||
155 | 175 | | |
156 | 176 | | |
157 | 177 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 178 | + | |
| 179 | + | |
167 | 180 | | |
168 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
169 | 186 | | |
170 | 187 | | |
171 | 188 | | |
| |||
0 commit comments