temporalio/temporal · error

failed to get workflow execution history

Error message

failed to get workflow execution history

What it means

getLastWorkflowTaskEventID pages backwards through a workflow's history via the frontend's GetWorkflowExecutionHistoryReverse RPC to find the most recent WorkflowTaskCompleted event (used as a reset point for batch reset operations). If any page of that RPC fails, the raw cause is logged and this generic wrapper error is returned. It deliberately discards the underlying error from the returned value, so the real reason (persistence outage, permission denied, namespace not found, etc.) is only visible in the batcher worker's log.

Source

Thrown at service/worker/batcher/activities.go:1090

func getLastWorkflowTaskEventID(
	ctx context.Context,
	namespaceStr string,
	workflowExecution *commonpb.WorkflowExecution,
	frontendClient workflowservice.WorkflowServiceClient,
	logger log.Logger,
) (workflowTaskEventID int64, err error) {
	req := &workflowservice.GetWorkflowExecutionHistoryReverseRequest{
		Namespace:       namespaceStr,
		Execution:       workflowExecution,
		MaximumPageSize: 1000,
		NextPageToken:   nil,
	}
	for {
		resp, err := frontendClient.GetWorkflowExecutionHistoryReverse(ctx, req)
		if err != nil {
			logger.Error("failed to run GetWorkflowExecutionHistoryReverse", tag.Error(err))
			return 0, errors.New("failed to get workflow execution history")
		}
		for _, e := range resp.GetHistory().GetEvents() {
			switch e.GetEventType() {
			case enumspb.EVENT_TYPE_WORKFLOW_TASK_COMPLETED:
				workflowTaskEventID = e.GetEventId()
				return workflowTaskEventID, nil
			case enumspb.EVENT_TYPE_WORKFLOW_TASK_SCHEDULED:
				// if there is no task completed event, set it to first scheduled event + 1
				workflowTaskEventID = e.GetEventId() + 1
			}
		}
		if len(resp.NextPageToken) == 0 {
			break
		}
		req.NextPageToken = resp.NextPageToken
	}
	if workflowTaskEventID == 0 {
		return 0, temporal.NewNonRetryableApplicationError("unable to find any scheduled or completed task", "NoWorkflowTaskFound", nil)

View on GitHub (pinned to bde624efd1)

Solutions

  1. Check the batcher worker logs for 'failed to run GetWorkflowExecutionHistoryReverse' immediately preceding this error; the wrapped cause names the real failure.
  2. Verify the target workflow execution exists and is readable (namespace, workflow ID, run ID) via temporal workflow show.
  3. Confirm frontend/history services and the persistence store are healthy (temporal operator cluster describe, DB connectivity).
  4. Retry the batch operation once the transient outage resolves; the batch workflow retries activities but this workflow-level lookup fails fast.

Example fix

// before
resp, err := frontendClient.GetWorkflowExecutionHistoryReverse(ctx, req)
if err != nil {
	logger.Error("failed to run GetWorkflowExecutionHistoryReverse", tag.Error(err))
	return 0, errors.New("failed to get workflow execution history")
}
// after
resp, err := frontendClient.GetWorkflowExecutionHistoryReverse(ctx, req)
if err != nil {
	logger.Error("failed to run GetWorkflowExecutionHistoryReverse", tag.Error(err))
	return 0, fmt.Errorf("failed to get workflow execution history: %w", err)
}
Defensive patterns

Strategy: retry

Try / catch

// The error wraps no cause; inspect worker logs for 'failed to run GetWorkflowExecutionHistoryReverse'.
if _, err := batcher.GetLastWorkflowTaskEventID(...); err != nil {
	if strings.Contains(err.Error(), "failed to get workflow execution history") {
		// transient history RPC failure: back off and retry the batch op
	}
}

Prevention

When it happens

Trigger: Calling the batch reset workflow (ResetByType/ResetByOptions paths) while GetWorkflowExecutionHistoryReverse fails: history service unavailable, persistence store down, invalid namespace/workflow run, or the caller lacks read permission on the namespace.

Common situations: Batch operation started while the history service or database is degraded; reset targeting a closed/deleted workflow whose history rows were purged; misconfigured frontend address in the batcher worker's client config; cluster failover mid-pagination.

Related errors


AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01). Data as JSON: /api/errors/9880af72b1fed036. Report an issue: GitHub.