diff --git a/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestWorkflowMutableStateImpl.java b/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestWorkflowMutableStateImpl.java index b99753b96d..19c7376ee7 100644 --- a/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestWorkflowMutableStateImpl.java +++ b/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestWorkflowMutableStateImpl.java @@ -3172,13 +3172,16 @@ public UpdateWorkflowExecutionLifecycleStage waitForStage( } public UpdateWorkflowExecutionLifecycleStage getStage() { - if (!accepted.isDone()) { - return UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED; - } else if (!outcome.isDone()) { + // A resolved outcome is terminal (a success result or a rejection/failure), so it always + // means COMPLETED. Checking it first keeps stage derivation independent of the order in + // which the `accepted` and `outcome` futures complete. The `accepted` future only + // distinguishes ADMITTED from ACCEPTED. + if (outcome.isDone()) { + return UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED; + } else if (accepted.isDone()) { return UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED; } - return UpdateWorkflowExecutionLifecycleStage - .UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED; + return UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED; } public String getId() {