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
2 changes: 2 additions & 0 deletions internal/internal_task_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1822,9 +1822,11 @@ func (wth *workflowTaskHandlerImpl) completeWorkflow(
) interface{} {
// for query task
if task.Query != nil {
cause := errToWorkflowTaskFailedCause(workflowContext.err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: To test you might want to use a gRPC interceptor to verify the cause is sent since it won't be written to history

queryCompletedRequest := &workflowservice.RespondQueryTaskCompletedRequest{
TaskToken: task.TaskToken,
Namespace: wth.namespace,
Cause: cause,
}
var panicErr *PanicError
if errors.As(workflowContext.err, &panicErr) {
Expand Down
32 changes: 20 additions & 12 deletions internal/internal_task_pollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,7 @@ func (wtp *workflowTaskPoller) RespondTaskCompleted(
}

func (wtp *workflowTaskPoller) errorToFailWorkflowTask(taskToken []byte, err error) *workflowservice.RespondWorkflowTaskFailedRequest {
cause := enumspb.WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE
// If it was a panic due to a bad state machine or if it was a history
// mismatch error, mark as non-deterministic
if panicErr, _ := err.(*workflowPanicError); panicErr != nil {
if _, badStateMachine := panicErr.value.(stateMachineIllegalStatePanic); badStateMachine {
cause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR
}
} else if _, mismatch := err.(historyMismatchError); mismatch {
cause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR
} else if _, unknown := err.(unknownSdkFlagError); unknown {
cause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR
}
cause := errToWorkflowTaskFailedCause(err)

builtRequest := &workflowservice.RespondWorkflowTaskFailedRequest{
TaskToken: taskToken,
Expand Down Expand Up @@ -1346,3 +1335,22 @@ func (*eagerWorkflowTask) isEmpty() bool {
func (nt *nexusTask) isEmpty() bool {
return nt.task == nil
}

func errToWorkflowTaskFailedCause(err error) enumspb.WorkflowTaskFailedCause {
if err != nil {
cause := enumspb.WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE
// If it was a panic due to a bad state machine or if it was a history
// mismatch error, mark as non-deterministic
if panicErr, _ := err.(*workflowPanicError); panicErr != nil {
if _, badStateMachine := panicErr.value.(stateMachineIllegalStatePanic); badStateMachine {
cause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR
}
} else if _, mismatch := err.(historyMismatchError); mismatch {
cause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR
} else if _, unknown := err.(unknownSdkFlagError); unknown {
cause = enumspb.WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR
}
return cause
}
return enumspb.WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED
}
Loading