Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public CompletableFuture<Void> resumed(WorkflowContextData workflowContext) {
return doTransaction(t -> t.clearStatus(workflowContext), workflowContext);
}

@Override
public CompletableFuture<Void> statusChanged(
WorkflowContextData workflowContext, WorkflowStatus status) {
return doTransaction(t -> t.writeStatus(workflowContext, status), workflowContext);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The new statusChanged implementation is a bit harder to read than the surrounding methods due to being on a single long line. Consider wrapping the doTransaction(...) call in the same style as suspended(...)/taskCompleted(...) to keep formatting consistent and improve readability.

Suggested change
return doTransaction(t -> t.writeStatus(workflowContext, status), workflowContext);
return doTransaction(
t -> t.writeStatus(workflowContext, status), workflowContext);

Copilot uses AI. Check for mistakes.
}

@Override
public void close() throws Exception {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.serverlessworkflow.impl.TaskContextData;
import io.serverlessworkflow.impl.WorkflowContextData;
import io.serverlessworkflow.impl.WorkflowStatus;
import java.util.concurrent.CompletableFuture;

public interface PersistenceInstanceWriter extends AutoCloseable {
Expand All @@ -33,6 +34,11 @@ public interface PersistenceInstanceWriter extends AutoCloseable {

CompletableFuture<Void> resumed(WorkflowContextData workflowContext);

default CompletableFuture<Void> statusChanged(
WorkflowContextData workflowContext, WorkflowStatus status) {
return CompletableFuture.completedFuture(null);
}

CompletableFuture<Void> taskRetried(
WorkflowContextData workflowContext, TaskContextData taskContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public CompletableFuture<WorkflowModel> start() {
() -> {
if (info.status() == WorkflowStatus.SUSPENDED) {
internalSuspend();
} else if (info.status() == WorkflowStatus.WAITING) {
status(WorkflowStatus.WAITING);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.serverlessworkflow.impl.persistence;

import io.serverlessworkflow.impl.WorkflowStatus;
import io.serverlessworkflow.impl.lifecycle.TaskCompletedEvent;
import io.serverlessworkflow.impl.lifecycle.TaskRetriedEvent;
import io.serverlessworkflow.impl.lifecycle.TaskStartedEvent;
Expand All @@ -24,6 +25,7 @@
import io.serverlessworkflow.impl.lifecycle.WorkflowFailedEvent;
import io.serverlessworkflow.impl.lifecycle.WorkflowResumedEvent;
import io.serverlessworkflow.impl.lifecycle.WorkflowStartedEvent;
import io.serverlessworkflow.impl.lifecycle.WorkflowStatusEvent;
import io.serverlessworkflow.impl.lifecycle.WorkflowSuspendedEvent;

public class WorkflowPersistenceListener implements WorkflowExecutionListener {
Expand Down Expand Up @@ -78,4 +80,12 @@ public void onTaskCompleted(TaskCompletedEvent ev) {
public void onTaskRetried(TaskRetriedEvent ev) {
persistenceWriter.taskRetried(ev.workflowContext(), ev.taskContext());
}

@Override
public void onWorkflowStatusChanged(WorkflowStatusEvent ev) {
if (ev.status() == WorkflowStatus.WAITING) {
// Only persist WAITING for now
persistenceWriter.statusChanged(ev.workflowContext(), ev.status());
}
}
}
Comment on lines +86 to 91
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

Persisting WAITING on entry without also clearing/updating the persisted status when the workflow leaves WAITING can leave a stale WAITING status in persistence (e.g., when the workflow transitions WAITING -> RUNNING after an event arrives). This can make restored instances and operational queries report incorrect state. Consider also handling status changes away from WAITING (e.g., if previousStatus == WAITING and new status != WAITING then clear the persisted status, or persist all status changes).

Suggested change
if (ev.status() == WorkflowStatus.WAITING) {
// Only persist WAITING for now
persistenceWriter.statusChanged(ev.workflowContext(), ev.status());
}
}
}
// Persist all status changes so a previously persisted WAITING status
// is overwritten when the workflow leaves WAITING.
persistenceWriter.statusChanged(ev.workflowContext(), ev.status());
}
}

Copilot uses AI. Check for mistakes.
Loading