Skip to content

Bug: ListOperations _head/_tail return single item instead of a slice #14278

@kuishou68

Description

@kuishou68

Bug Report

File: agent/component/list_operations.py

Description

The _head(n) and _tail(n) methods in ListOperations have an off-by-one / wrong-indexing bug: they return a single-element list instead of a slice of n elements.

Current (buggy) code

def _head(self):
    n = self._coerce_n()
    if 1 <= n <= len(self.inputs):
        outputs = [self.inputs[n - 1]]   # ← returns ONE item at index n-1
    else:
        outputs = []
    self._set_outputs(outputs)

def _tail(self):
    n = self._coerce_n()
    if 1 <= n <= len(self.inputs):
        outputs = [self.inputs[-n]]      # ← returns ONE item at index -n
    else:
        outputs = []
    self._set_outputs(outputs)

Expected behaviour

  • _head(n) should return the first n items: self.inputs[:n]
  • _tail(n) should return the last n items: self.inputs[-n:]

Steps to reproduce

inputs = [1, 2, 3, 4, 5]
# head(3) currently returns [3]  (inputs[3-1])
# head(3) should return   [1, 2, 3]

# tail(2) currently returns [4]  (inputs[-2])
# tail(2) should return   [4, 5]

Fix

# _head
outputs = self.inputs[:n]

# _tail
outputs = self.inputs[-n:]

Signed-off-by: Cocoon-Break [email protected]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions