Add Test and Java doc for WorkflowInstance.output#1359
Open
mdproctor wants to merge 2 commits intoserverlessworkflow:mainfrom
Open
Add Test and Java doc for WorkflowInstance.output#1359mdproctor wants to merge 2 commits intoserverlessworkflow:mainfrom
mdproctor wants to merge 2 commits intoserverlessworkflow:mainfrom
Conversation
…verlessworkflow#1357) output() and outputAs() are blocking operations (they join the workflow future) intended for callers outside the event chain — e.g. after instance.start().join(). Exposing them on WorkflowInstanceData, which is what WorkflowExecutionListener implementations see via event.workflowContext().instanceData(), misleads implementors into calling a blocking join from inside a callback. The correct API for accessing output inside onWorkflowCompleted is event.output(), which is populated directly from the task result before the event is published. Removes output() and outputAs() from WorkflowInstanceData. Declares them explicitly on WorkflowInstance, which extends WorkflowInstanceData and is the right type for post-completion callers. Adds WorkflowExecutionListenerOutputTest asserting that event.output() carries the correct value inside onWorkflowCompleted. Closes serverlessworkflow#1357 Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the workflow API surface to discourage blocking output retrieval from lifecycle listener callbacks by moving output()/outputAs() off WorkflowInstanceData and onto WorkflowInstance, and adds a regression test ensuring WorkflowCompletedEvent.output() is available within onWorkflowCompleted.
Changes:
- Removed
output()andoutputAs()fromWorkflowInstanceData - Added
output()andoutputAs()toWorkflowInstance - Added a listener-focused test asserting
event.output()is populated duringonWorkflowCompleted
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| impl/test/src/test/java/io/serverlessworkflow/impl/test/WorkflowExecutionListenerOutputTest.java | Adds test coverage that WorkflowCompletedEvent.output() is usable inside the completion hook. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstanceData.java | Removes blocking output accessors from the instance-data view exposed via workflow context in listeners. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstance.java | Reintroduces output accessors on the WorkflowInstance API (the post-start handle). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
Already done with #1357, but the javadoc and the test are nice additions. Need to be properly rebased though |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1357
Summary
output()andoutputAs()are blocking operations — they join the workflowCompletableFutureand are intended for callers who hold aWorkflowInstancereference afterstart()completes. Placing them onWorkflowInstanceData, which is whatWorkflowExecutionListenerimplementations see viaevent.workflowContext().instanceData(), misleads implementors into calling a blocking join from inside an event callback.The correct API inside
onWorkflowCompletedisevent.output(), which is populated directly from the task result before the event fires.Changes
output()andoutputAs()fromWorkflowInstanceDataWorkflowInstance(which extendsWorkflowInstanceData)WorkflowExecutionListenerOutputTestassertingevent.output()carries the correct value inside the hookNo callers broken
WorkflowMutableInstanceimplementsWorkflowInstanceand keeps both method implementations unchanged. The persistence layer (BytesMapInstanceTransaction) only readsstartedAt()andinput()fromWorkflowInstanceData— unaffected.🤖 Generated with Claude Code