infiniflow/ragflow · error · listOpPanic
ListOperations: tail requires n to be within the valid range
Error message
ListOperations: tail requires n to be within the valid range in strict mode, got %d
What it means
opTail panics in strict mode when n < 1 or n > len(items). The tail operation returns the last n items and strict mode enforces 1 <= n <= len(items); anything outside that range panics via strictRangePanic instead of returning empty or clamping.
Source
Thrown at internal/agent/component/list_operations.go:432
panic(strictRangePanic("head", n))
}
return append([]any{}, items[:n]...)
}
if n < 1 {
return []any{}
}
if n > len(items) {
n = len(items)
}
return append([]any{}, items[:n]...)
}
// opTail: last n items. n < 1 → empty. Strict: 1 ≤ n ≤ len(items).
func (l *ListOperationsComponent) opTail(items []any) []any {
n := l.param.N
if l.param.Strict {
if n < 1 || n > len(items) {
panic(strictRangePanic("tail", n))
}
return append([]any{}, items[len(items)-n:]...)
}
if n < 1 {
return []any{}
}
if n > len(items) {
n = len(items)
}
return append([]any{}, items[len(items)-n:]...)
}
// opFilter: keep items whose _norm(v) matches the filter rule.
func (l *ListOperationsComponent) opFilter(items []any) []any {
op, _ := l.param.Filter["operator"].(string)
val, _ := l.param.Filter["value"].(string)
out := make([]any, 0, len(items))
for _, item := range items {View on GitHub (pinned to 554fb1133a)
Solutions
- Set N within 1..len(items) — e.g. n: 1 to take only the last item
- Guard dynamic N values and empty upstream lists before tail executes
- Disable strict mode if clamped/empty results are acceptable for edge cases
Example fix
# before operation: tail strict: true n: 10 # list has 4 items -> panic # after operation: tail strict: true n: 4 # whole list; n:1 for last item only
Defensive patterns
Strategy: validation
Validate before calling
if op == "tail" && strict && (n < 1 || n > len(items)) {
return fmt.Errorf("tail requires 1 <= n <= %d, got %d", len(items), n)
} Prevention
- Apply the same 1..len(items) bound check to tail as to head
- Handle empty-list inputs upstream; strict tail can never succeed on them
- Keep n parameterized from a checked source instead of hardcoded
When it happens
Trigger: ListOperations with operation tail, Strict: true, and N set to 0, a negative number, or a value larger than the input list length.
Common situations: Unset N defaulting to 0; dynamic counts that hit 0 on short upstream lists; fixed tail sizes assumed to fit any list but applied to filtered or split data.
Related errors
- ListOperations: head requires n to be within the valid range
- ListOperations: nth requires n to be within the valid range
- should be a numeric number between 0 and 1 exclusively
- {operation} requires n to be within the valid range in stric
- failed to initialize logger: {err}
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/0f922411b1690900.
Report an issue: GitHub.