temporalio/temporal · error

Unable to merge queue slice having scope %v with slice havin

Error message

Unable to merge queue slice having scope %v with slice having scope %v

What it means

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.

Source

Thrown at service/history/queues/slice.go:171

	s.destroy()

	return s.newSlice(passScope, passIterators, passTaskTracker),
		s.newSlice(failScope, failIterators, failTaskTracker)
}

func (s *SliceImpl) CanMergeWithSlice(slice Slice) bool {
	s.stateSanityCheck()

	return s != slice && s.scope.Range.CanMerge(slice.Scope().Range)
}

func (s *SliceImpl) MergeWithSlice(slice Slice) []Slice {
	if s.scope.Range.InclusiveMin.CompareTo(slice.Scope().Range.InclusiveMin) > 0 {
		return slice.MergeWithSlice(s)
	}

	if !s.CanMergeWithSlice(slice) {
		panic(fmt.Sprintf("Unable to merge queue slice having scope %v with slice having scope %v", s.scope, slice.Scope()))
	}

	incomingSlice, ok := slice.(*SliceImpl)
	if !ok {
		panic(fmt.Sprintf("Unable to merge queue slice of type %T with type %T", s, slice))
	}

	if s.scope.CanMergeByRange(incomingSlice.scope) {
		return []Slice{s.mergeByRange(incomingSlice)}
	}

	mergedSlices := make([]Slice, 0, 3)
	currentLeftSlice, currentRightSlice := s.splitByRange(incomingSlice.Scope().Range.InclusiveMin)
	mergedSlices = appendMergedSlice(mergedSlices, currentLeftSlice)

	if currentRightMax := currentRightSlice.Scope().Range.ExclusiveMax; incomingSlice.CanSplitByRange(currentRightMax) {
		leftIncomingSlice, rightIncomingSlice := incomingSlice.splitByRange(currentRightMax)
		mergedMidSlice := currentRightSlice.mergeByPredicate(leftIncomingSlice)

View on GitHub (pinned to bde624efd1)

Solutions

  1. Check s.CanMergeWithSlice(other) before calling MergeWithSlice and keep slices separate when false
  2. Ensure slices being merged are range-contiguous; merge intermediate slices or split/re-range first
  3. Do not pass the same slice instance to itself (guard s != slice)

Example fix

// before
merged := s.MergeWithSlice(other) // panics: non-adjacent ranges

// after
var merged []Slice
if s.CanMergeWithSlice(other) {
  merged = s.MergeWithSlice(other)
} else {
  merged = []Slice{s, other}
}
Defensive patterns

Strategy: validation

Validate before calling

var merged []queues.Slice
if s.CanMergeWithSlice(other) && s != other {
  merged = s.MergeWithSlice(other)
} else {
  merged = []queues.Slice{s, other}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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