{"record":{"id":"6daefc8fc0ad49bb","repo":"temporalio/temporal","slug":"category-id-v-has-already-been-defined-as-type","errorCode":null,"errorMessage":"category id: %v has already been defined as type %v and name %v","messagePattern":"category id: (.+?) has already been defined as type (.+?) and name (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"service/history/tasks/task_category_registry.go","lineNumber":45,"sourceCode":"// you're in a test.\nfunc NewDefaultTaskCategoryRegistry() *MutableTaskCategoryRegistry {\n\treturn &MutableTaskCategoryRegistry{\n\t\tcategories: map[int]Category{\n\t\t\tCategoryTransfer.ID():    CategoryTransfer,\n\t\t\tCategoryTimer.ID():       CategoryTimer,\n\t\t\tCategoryVisibility.ID():  CategoryVisibility,\n\t\t\tCategoryReplication.ID(): CategoryReplication,\n\t\t\tCategoryMemoryTimer.ID(): CategoryMemoryTimer,\n\t\t\tCategoryOutbound.ID():    CategoryOutbound,\n\t\t},\n\t}\n}\n\n// AddCategory register a Category with the registry or panics if a Category with the same ID has already been\n// registered.\nfunc (r *MutableTaskCategoryRegistry) AddCategory(c Category) {\n\tif category, ok := r.categories[c.id]; ok {\n\t\tpanic(fmt.Sprintf(\n\t\t\t\"category id: %v has already been defined as type %v and name %v\",\n\t\t\tc.id,\n\t\t\tcategory.cType,\n\t\t\tcategory.name,\n\t\t))\n\t}\n\n\tr.categories[c.id] = c\n}\n\n// GetCategoryByID returns a registered Category with the same ID from the registry or false if no such Category exists.\nfunc (r *MutableTaskCategoryRegistry) GetCategoryByID(id int) (Category, bool) {\n\tcategory, ok := r.categories[id]\n\treturn category, ok\n}\n\n// GetCategories returns a deep copy of all registered Category objects from the registry.\nfunc (r *MutableTaskCategoryRegistry) GetCategories() map[int]Category {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/service/history/tasks/task_category_registry.go#L27-L63","documentation":"MutableTaskCategoryRegistry.AddCategory registers a task Category keyed by its numeric ID. It deliberately panics (instead of erroring) when the same ID is registered twice, since category registration happens during package init and a duplicate indicates a compile-time-level configuration bug. The existing registration's type and name are reported to help identify the collision.","triggerScenarios":"Calling AddCategory with a Category whose id collides with one already registered — happens when defining a new task category reusing an existing numeric ID, or registering the same category twice (e.g. duplicated init code).","commonSituations":"Adding a new category in a fork/patch without allocating a fresh ID; merge conflicts leaving two registration blocks; upstream ID reassignment causing collisions with locally added categories.","solutions":["Allocate a new, unused category ID for the new category; check all RegisterTaskCategory calls in the tasks package for taken IDs.","Remove the duplicate AddCategory call (often left by a bad merge).","Search for all categories registered with the reported id and decide which definition is authoritative.","Coordinate ID allocation across teams/forks since IDs are persisted in task rows and must be globally unique."],"exampleFix":"// before\nCategoryTransfer = 1\nCategoryReplication = 1 // collides\n\n// after\nCategoryTransfer = 1\nCategoryReplication = 2","handlingStrategy":"validation","validationCode":"if registry.GetCategory(2) != nil {\n    return errors.New(\"category id 2 already registered\")\n}\nregistry.AddCategory(myCategory)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain a single registry of allocated category IDs and pick unused IDs from it","Grep for RegisterTaskCategory/AddCategory calls when adding a new category","Never reuse persisted category IDs; they are stored in database task rows","Resolve merge conflicts around category registration blocks carefully"],"tags":["task-category","registry","panic","duplicate-id"],"backgroundTag":"duplicate-category-id","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}