Async drain signal & Unhandled Command

Hi, currently we have code that does something like this

    res := &response{}
	selector := workflow.NewSelector(ctx)
	selector.AddFuture(
		statusFuture,
		func(f workflow.Future) {
			if err := f.Get(ctx, &res); err != nil {
				
			}
		},
	)
	paymentCh := workflow.GetSignalChannel(ctx, "Payment")
	selector.AddReceive(
		paymentCh,
		func(c workflow.ReceiveChannel, more bool) {
			var s PaymentPayload
			c.Receive(ctx, &s)
            // do some processing
            res.Status = s.Status
		},
	)
	selector.Select(ctx)

	// Drain signals, we don't care about the subsequent signal
	for {
		var s PaymentPayload
		ok := paymentCh.ReceiveAsync(&s)
		if !ok {
			break
		}
	}

       return res, nil

from my understanding we need to do async drain to avoid missing signal and to avoid this error

Unhandled Command
The Workflow Task failed because there are new available events since the last Workflow Task started. A retry Workflow Task has been scheduled and the Workflow will have a chance to handle those new events.

However it seems like even with the async drain, our workflow still got the errors warning, even though the workflow is able to complete successfully afterwards.

May I know if there is a way to completely get rid of this errors? Thanks in advance!

There is no way to eliminate UnhandledCommand as it is not an error but an indication of the race condition between workflow completion and new signals. As you are correctly draining the channel, you can ignore the UnhandledCommand.

thanks maxim