{"record":{"id":"c5cd3bf0ed2fa242","repo":"temporalio/temporal","slug":"unable-to-merge-queue-slice-having-scope-v-with-s","errorCode":null,"errorMessage":"Unable to merge queue slice having scope %v with slice having scope %v","messagePattern":"Unable to merge queue slice having scope (.+?) with slice having scope (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/history/queues/slice.go","lineNumber":171,"sourceCode":"\ts.destroy()\n\n\treturn s.newSlice(passScope, passIterators, passTaskTracker),\n\t\ts.newSlice(failScope, failIterators, failTaskTracker)\n}\n\nfunc (s *SliceImpl) CanMergeWithSlice(slice Slice) bool {\n\ts.stateSanityCheck()\n\n\treturn s != slice && s.scope.Range.CanMerge(slice.Scope().Range)\n}\n\nfunc (s *SliceImpl) MergeWithSlice(slice Slice) []Slice {\n\tif s.scope.Range.InclusiveMin.CompareTo(slice.Scope().Range.InclusiveMin) > 0 {\n\t\treturn slice.MergeWithSlice(s)\n\t}\n\n\tif !s.CanMergeWithSlice(slice) {\n\t\tpanic(fmt.Sprintf(\"Unable to merge queue slice having scope %v with slice having scope %v\", s.scope, slice.Scope()))\n\t}\n\n\tincomingSlice, ok := slice.(*SliceImpl)\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"Unable to merge queue slice of type %T with type %T\", s, slice))\n\t}\n\n\tif s.scope.CanMergeByRange(incomingSlice.scope) {\n\t\treturn []Slice{s.mergeByRange(incomingSlice)}\n\t}\n\n\tmergedSlices := make([]Slice, 0, 3)\n\tcurrentLeftSlice, currentRightSlice := s.splitByRange(incomingSlice.Scope().Range.InclusiveMin)\n\tmergedSlices = appendMergedSlice(mergedSlices, currentLeftSlice)\n\n\tif currentRightMax := currentRightSlice.Scope().Range.ExclusiveMax; incomingSlice.CanSplitByRange(currentRightMax) {\n\t\tleftIncomingSlice, rightIncomingSlice := incomingSlice.splitByRange(currentRightMax)\n\t\tmergedMidSlice := currentRightSlice.mergeByPredicate(leftIncomingSlice)","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/service/history/queues/slice.go#L153-L189","documentation":"SliceImpl.MergeWithSlice panics when CanMergeWithSlice(slice) is false, meaning the two slices' ranges cannot be merged (not contiguous/compatible, or the same slice object). Note the method first swaps arguments if the receiver's InclusiveMin is greater, so the panic reflects genuinely unmergeable ranges. Merge operations require range adjacency to combine trackers and iterators correctly.","triggerScenarios":"Calling s.MergeWithSlice(other) where the ranges have a gap or overlap that CanMerge rejects, or passing the same slice instance; calling on a slice whose range was shrunk so adjacency no longer holds.","commonSituations":"Compaction code merging non-adjacent slices collected from different readers; merging slices whose ranges were mutated by shrink; passing the same slice by mistake in aggregation loops.","solutions":["Check s.CanMergeWithSlice(other) before calling MergeWithSlice and keep slices separate when false","Ensure slices being merged are range-contiguous; merge intermediate slices or split/re-range first","Do not pass the same slice instance to itself (guard s != slice)"],"exampleFix":"// before\nmerged := s.MergeWithSlice(other) // panics: non-adjacent ranges\n\n// after\nvar merged []Slice\nif s.CanMergeWithSlice(other) {\n  merged = s.MergeWithSlice(other)\n} else {\n  merged = []Slice{s, other}\n}","handlingStrategy":"validation","validationCode":"var merged []queues.Slice\nif s.CanMergeWithSlice(other) && s != other {\n  merged = s.MergeWithSlice(other)\n} else {\n  merged = []queues.Slice{s, other}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate MergeWithSlice behind CanMergeWithSlice","Only merge slices whose ranges are contiguous","Never pass the same slice instance to itself"],"tags":["go","history-service","task-queue","slice-merge","panic"],"backgroundTag":"non-contiguous-range-merge","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}