@@ -808,14 +808,22 @@ func (wtp *workflowTaskPoller) poll(ctx context.Context) (interface{}, error) {
808808func (wtp * workflowTaskPoller ) toWorkflowTask (response * s.PollForDecisionTaskResponse ) * workflowTask {
809809 startEventID := response .GetStartedEventId ()
810810 nextEventID := response .GetNextEventId ()
811- if nextEventID != 0 &&
812- startEventID != 0 &&
813- nextEventID - 1 != startEventID {
814- wtp .logger .Warn ("Invalid PollForDecisionTaskResponse, nextEventID doesn't match startedEventID" ,
815- zap .Int64 ("StartedEventID" , startEventID ),
816- zap .Int64 ("NextEventID" , nextEventID ),
817- )
818- wtp .metricsScope .Counter (metrics .DecisionPollInvalidCounter ).Inc (1 )
811+ if nextEventID != 0 && startEventID != 0 {
812+ // first case is for normal decision, the second is for transient decision
813+ if nextEventID - 1 != startEventID && nextEventID + 1 != startEventID {
814+ wtp .logger .Warn ("Invalid PollForDecisionTaskResponse, nextEventID doesn't match startedEventID" ,
815+ zap .Int64 ("StartedEventID" , startEventID ),
816+ zap .Int64 ("NextEventID" , nextEventID ),
817+ )
818+ wtp .metricsScope .Counter (metrics .DecisionPollInvalidCounter ).Inc (1 )
819+ } else {
820+ // in transient decision case, set nextEventID to be one more than startEventID in case
821+ // we can need to use the field to truncate history for decision task (check comments in newGetHistoryPageFunc)
822+ // this is safe as
823+ // - currently we are not using nextEventID for decision task
824+ // - for query task, startEventID is not assigned, so we won't reach here.
825+ nextEventID = startEventID + 1
826+ }
819827 }
820828 historyIterator := & historyIteratorImpl {
821829 nextPageToken : response .NextPageToken ,
0 commit comments