{"record":{"id":"b641be49c7ee4cae","repo":"temporalio/temporal","slug":"page-size-to-read-history-tasks-must-be-positive","errorCode":null,"errorMessage":"page size to read history tasks must be positive","messagePattern":"page size to read history tasks must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/history_task_queue_manager.go","lineNumber":41,"sourceCode":"\tErrMsgSerializeTaskToEnqueue = \"failed to serialize history task for task queue\"\n\t// ErrMsgDeserializeRawHistoryTask is returned when the raw task cannot be deserialized from the task queue. This error\n\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(","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/history_task_queue_manager.go#L23-L59","documentation":"ErrReadTasksNonPositivePageSize (common/persistence/history_task_queue_manager.go:41) is a public sentinel guarding ReadRawTasks on HistoryTaskQueueManagerImpl. Reading history tasks from a task queue requires a strictly positive page size; a zero or negative value is an invalid request and is rejected immediately. A matching unit test (TestHistoryTaskQueueManager_ReadTasks_NonPositivePageSize) and the queue Invoke path assert this behavior.","triggerScenarios":"Calling ReadRawTasks (or the queue ReadTasks path via Invoke) with a request whose PageSize is 0 or negative.","commonSituations":"Uninitialized request struct defaulting PageSize to 0; caller code copying a page size from a config that failed to load; loop logic computing a remaining-page size that hits 0 or below before the terminal page.","solutions":["Set PageSize to a positive value (e.g. the configured task fetch batch size) before calling ReadRawTasks","Clamp/validate the page size at the caller: if ps <= 0 { ps = defaultPageSize }","Fix the config/struct initialization that left PageSize unset"],"exampleFix":"// before\nresp, err := mgr.ReadRawTasks(ctx, &persistence.ReadHistoryTasksRequest{PageSize: 0})\n// after\npageSize := cfg.PageSize\nif pageSize <= 0 {\n    pageSize = 100\n}\nresp, err := mgr.ReadRawTasks(ctx, &persistence.ReadHistoryTasksRequest{PageSize: pageSize})","handlingStrategy":"validation","validationCode":"if req.PageSize <= 0 {\n    return fmt.Errorf(\"ReadRawTasks requires positive page size, got %d\", req.PageSize)\n}\n// safe to call ReadRawTasks","typeGuard":null,"tryCatchPattern":"resp, err := mgr.ReadRawTasks(ctx, req)\nif err != nil {\n    if strings.Contains(err.Error(), \"page size to read history tasks must be positive\") {\n        req.PageSize = defaultHistoryTaskPageSize\n        resp, err = mgr.ReadRawTasks(ctx, req)\n    }\n    if err != nil { return err }\n}","preventionTips":["Always initialize PageSize explicitly in ReadHistoryTasksRequest structs","Centralize page-size defaults in one config constant","Never derive page size from arithmetic that can reach <= 0 without clamping"],"tags":["go","persistence","task-queue","invalid-argument"],"backgroundTag":"invalid-argument","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}