{"record":{"id":"2974dcb42e232371","repo":"temporalio/temporal","slug":"enqueue-task-request-task-is-nil","errorCode":null,"errorMessage":"enqueue task request task is nil","messagePattern":"enqueue task request task is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/history_task_queue_manager.go","lineNumber":43,"sourceCode":"\t// is returned when this whole top-level proto cannot be deserialized.\n\t//  Raw Task (a proto): <-- when this cannot be deserialized\n\t//\t- ShardID\n\t//\t- Blob (a serialized task)\n\tErrMsgDeserializeRawHistoryTask = \"failed to deserialize raw history task from task queue\"\n\t// ErrMsgDeserializeHistoryTask is returned when the history task cannot be deserialized from the task queue. This\n\t// error is returned when the blob inside the raw task cannot be deserialized.\n\t//  Raw Task (a proto):\n\t//\t- ShardID\n\t//\t- Blob (a serialized task) <-- when this cannot be deserialized\n\tErrMsgDeserializeHistoryTask = \"failed to deserialize history task blob\"\n\t// ErrMsgFailedToParseCategoryID is returned when category id cannot be parsed as an integer value.\n\tErrMsgFailedToParseCategoryID = \"failed to parse category id from queue name\"\n)\n\nvar (\n\tErrReadTasksNonPositivePageSize = errors.New(\"page size to read history tasks must be positive\")\n\tErrHistoryTaskBlobIsNil         = errors.New(\"history task from queue has nil blob\")\n\tErrEnqueueTaskRequestTaskIsNil  = errors.New(\"enqueue task request task is nil\")\n\tErrQueueAlreadyExists           = errors.New(\"queue already exists\")\n\tErrShardIDInvalid               = errors.New(\"shard ID must be greater than 0\")\n\tErrInvalidQueueName             = errors.New(\"invalid queue name, expected 4 fields\")\n)\n\nfunc NewHistoryTaskQueueManager(\n\tqueue QueueV2,\n\tserializer serialization.Serializer,\n) *HistoryTaskQueueManagerImpl {\n\treturn &HistoryTaskQueueManagerImpl{\n\t\tqueue:      queue,\n\t\tserializer: serializer,\n\t}\n}\n\nfunc (m *HistoryTaskQueueManagerImpl) EnqueueTask(\n\tctx context.Context,\n\trequest *EnqueueTaskRequest,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/history_task_queue_manager.go#L25-L61","documentation":"ErrEnqueueTaskRequestTaskIsNil (common/persistence/history_task_queue_manager.go:43) is returned by EnqueueTask when the request carries a nil Task pointer. The manager cannot serialize a nil task into a queue blob, so the enqueue is rejected up front as an invalid argument. It is a programmer-error guard preventing nil records from ever entering the task queue (which would later trip ErrHistoryTaskBlobIsNil on reads).","triggerScenarios":"Calling HistoryTaskQueueManagerImpl.EnqueueTask with &persistence.EnqueueTaskRequest{Task: nil} or a zero-value request struct.","commonSituations":"Constructing the request without populating Task; a nil task flowing from an upstream producer after a failed task build; test scaffolding forgetting to set the field.","solutions":["Ensure the Task field is populated before calling EnqueueTask","Add an upstream nil check so nil tasks are rejected/logged at the producer","Fix the task-construction code path that produced a nil task"],"exampleFix":"// before\nmgr.EnqueueTask(ctx, &persistence.EnqueueTaskRequest{QueueType: category, ShardID: shardID}) // Task missing\n// after\ntask := buildHistoryTask(...)\nif task == nil {\n    return errors.New(\"cannot enqueue nil history task\")\n}\nmgr.EnqueueTask(ctx, &persistence.EnqueueTaskRequest{ShardID: shardID, Task: task})","handlingStrategy":"validation","validationCode":"if req == nil || req.Task == nil {\n    return errors.New(\"EnqueueTaskRequest.Task must be non-nil\")\n}\n// safe to call EnqueueTask","typeGuard":"func taskIsEnqueueable(req *persistence.EnqueueTaskRequest) bool {\n    return req != nil && req.Task != nil && req.ShardID > 0\n}","tryCatchPattern":"err := mgr.EnqueueTask(ctx, req)\nif err != nil {\n    if strings.Contains(err.Error(), \"enqueue task request task is nil\") {\n        logger.Error(\"nil task refused by queue manager\", tag.Error(err))\n        return err // programmer error: do not retry\n    }\n    return err\n}","preventionTips":["Build enqueue requests through a constructor that requires a task","Add nil-task unit tests on the producer path","Fail fast at task-build time instead of letting nil flow downstream"],"tags":["go","persistence","task-queue","invalid-argument","nil-check"],"backgroundTag":"nil-task-request","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}