Skip to content

[Fix #1211] Support filters againts workflow data in listen task#1221

Merged
fjtirado merged 2 commits intoserverlessworkflow:mainfrom
fjtirado:Fix_#1211
Mar 10, 2026
Merged

[Fix #1211] Support filters againts workflow data in listen task#1221
fjtirado merged 2 commits intoserverlessworkflow:mainfrom
fjtirado:Fix_#1211

Conversation

@fjtirado
Copy link
Collaborator

Fix #1211

Copilot AI review requested due to automatic review settings March 10, 2026 13:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes #1211 by enabling listen task event filters to evaluate expressions against workflow/task data (e.g., $input.threshold) in addition to the incoming event payload.

Changes:

  • Thread WorkflowContext and TaskContext through event registration and predicate evaluation so filter expressions can access workflow data.
  • Update ListenExecutor to pass the workflow/task context into event registrations (including until registrations).
  • Update the sample workflow and tests to exercise $input access in an event filter.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
impl/test/src/test/resources/workflows-samples/listen-to-any-filter.yaml Updates sample event filter to use $input.threshold.
impl/test/src/test/java/io/serverlessworkflow/impl/test/EventDefinitionTest.java Provides workflow input (threshold) to support the updated filter.
impl/core/src/main/java/io/serverlessworkflow/impl/executors/ListenExecutor.java Passes workflow/task context into event registration building.
impl/core/src/main/java/io/serverlessworkflow/impl/events/TypeEventRegistration.java Stores workflow/task context on registrations for later predicate evaluation.
impl/core/src/main/java/io/serverlessworkflow/impl/events/EventRegistrationInfo.java Propagates workflow/task context into EventConsumer.register(...).
impl/core/src/main/java/io/serverlessworkflow/impl/events/EventRegistration.java Adds workflow() / task() accessors to registrations.
impl/core/src/main/java/io/serverlessworkflow/impl/events/EventConsumer.java Extends register API to accept workflow/task context (keeps a default overload).
impl/core/src/main/java/io/serverlessworkflow/impl/events/DefaultCloudEventPredicate.java Evaluates event-property predicates using the provided workflow/task context.
impl/core/src/main/java/io/serverlessworkflow/impl/events/CloudEventPredicate.java Updates predicate signature to accept workflow/task context.
impl/core/src/main/java/io/serverlessworkflow/impl/events/CloudEventAttrPredicate.java Updates attribute predicate signature to accept workflow/task context.
impl/core/src/main/java/io/serverlessworkflow/impl/events/AbstractTypeConsumer.java Passes registration workflow/task context into predicate evaluation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 10, 2026 13:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

impl/core/src/main/java/io/serverlessworkflow/impl/executors/ListenExecutor.java:184

  • internalExecute unregisters event registrations only on successful completion via thenApply. If info.completableFuture() completes exceptionally (e.g., consumer throws, predicate evaluation fails), registrations may remain active and retain WorkflowContext/TaskContext references. Prefer whenComplete/handle to always unregister in both success and failure paths.
    EventRegistrationInfo info =
        buildInfo(
            (BiConsumer<CloudEvent, CompletableFuture<WorkflowModel>>)
                ((ce, future) ->
                    processCe(converter.apply(ce), output, workflow, taskContext, future)),
            workflow,
            taskContext);
    return info.completableFuture()
        .thenApply(
            v -> {
              info.registrations().forEach(eventConsumer::unregister);
              return output;
            });

impl/test/src/test/java/io/serverlessworkflow/impl/test/EventDefinitionTest.java:66

  • The updated filter sample now depends on $input.threshold, but the parameterized test always starts all listen workflows with threshold=38 (including listen-to-any.yaml, which doesn’t exercise this feature). Consider passing the listen input as a separate parameter per test case and adding a negative assertion (e.g., threshold higher than emitted temperature keeps the instance WAITING) to verify the $input-based filter actually affects matching.
  void testEventListened(String listen, String emit, JsonNode expectedResult, Object emitInput)
      throws IOException {
    WorkflowDefinition listenDefinition =
        appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath(listen));
    WorkflowDefinition emitDefinition =
        appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath(emit));
    WorkflowInstance waitingInstance = listenDefinition.instance(Map.of("threshold", 38));
    CompletableFuture<WorkflowModel> future = waitingInstance.start();
    assertThat(waitingInstance.status()).isEqualTo(WorkflowStatus.WAITING);
    emitDefinition.instance(emitInput).start().join();
    assertThat(future).isCompleted();
    assertThat(waitingInstance.status()).isEqualTo(WorkflowStatus.COMPLETED);
    assertThat(waitingInstance.outputAs(JsonNode.class)).isEqualTo(expectedResult);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 10, 2026 14:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 10, 2026 15:42
@fjtirado fjtirado force-pushed the Fix_#1211 branch 3 times, most recently from 687b263 to 97dc8fe Compare March 10, 2026 15:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fjtirado fjtirado marked this pull request as draft March 10, 2026 16:05
…n listen task

Signed-off-by: fjtirado <ftirados@redhat.com>
@fjtirado fjtirado marked this pull request as ready for review March 10, 2026 17:50
Copilot AI review requested due to automatic review settings March 10, 2026 17:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 10, 2026 18:00
@fjtirado fjtirado force-pushed the Fix_#1211 branch 2 times, most recently from 717fe1d to d31d90e Compare March 10, 2026 18:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 10, 2026 18:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: fjtirado <ftirados@redhat.com>
@fjtirado fjtirado merged commit 745ed52 into serverlessworkflow:main Mar 10, 2026
3 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.

Support filters against workflow data in listen task

3 participants