Skip to content

fix(spring-ai): preserve generation finish reason across the activity boundary - #538

Merged
brianstrauch merged 1 commit into
temporalio:mainfrom
pcbeingused333:fix/spring-ai-finish-reason
Nov 14, 2026
Merged

brianstrauch merged 1 commit into
temporalio:mainfrom
pcbeingused333:fix/spring-ai-finish-reason

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

No separate issue: sibling of #445, which keeps finish metadata for streaming in the Vercel integration.

Cause. ChatModelActivityImpl.toOutput maps each Spring AI Generation to the activity's Generation(message) record and drops getMetadata().getFinishReason(). On the workflow side ActivityChatModel.toResponse rebuilds Generations without ChatGenerationMetadata, so response.getResult().getMetadata().getFinishReason() is always null in workflow code. Callers cannot tell a length truncation or content_filter from a normal stop.

Fix. Add an optional finish_reason field to ChatModelActivityOutput.Generation (the one-argument constructor is kept; the field is omitted when null and ignored when absent, so previously recorded histories still deserialize). toOutput fills it from the generation metadata and toResponse restores it as ChatGenerationMetadata.

Test. FinishReasonTest runs a workflow against a stub model returning finishReason("length") and asserts the workflow sees length: fails on main (null) and passes with this change; ChatModelActivityImplTest still passes.

Recorded histories. New chat activity results carry an extra finish_reason field. This does not affect the replay of in-flight runs: results recorded before the change deserialize with a null finish reason, and workers without the change ignore the unknown field (@JsonIgnoreProperties(ignoreUnknown = true) on Generation). No workflow commands change.

This change was prepared with the help of an AI assistant (Claude) and submitted by the account owner.

… boundary

ChatModelActivityImpl.toOutput dropped each Generation's finish reason and ActivityChatModel rebuilt Generations without ChatGenerationMetadata, so workflow code always saw a null finish reason (e.g. could not tell a length truncation from a normal stop). Carry it as an optional finish_reason field on the Generation record; the one-argument constructor and older serialized histories keep working.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 14, 2026 01:49

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@brianstrauch
brianstrauch enabled auto-merge (squash) November 14, 2026 05:18
@brianstrauch
brianstrauch merged commit 3527510 into temporalio:main Nov 14, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants