Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

fix: Task.filteredrun crashes/corrupts output for single-action tasks with merge disabled (#1138)

Andrew Chenee0d1a0214fa
diff --git a/src/python/txtai/workflow/task/base.py b/src/python/txtai/workflow/task/base.py
index 4fc80a77..aadc85de 100644
--- a/src/python/txtai/workflow/task/base.py
+++ b/src/python/txtai/workflow/task/base.py
@@ -120,7 +120,9 @@ class Task:
results = self.execute([self.prepare(element) for _, element in data], executor)
# Pack results back into elements
- if self.merge:
+ # Single-action tasks are always flattened by postprocess (regardless of merge),
+ # so results is already a single per-element list - same condition as postprocess.
+ if self.merge or len(self.action) <= 1:
elements = self.filteredpack(results, indexed, ids)
else:
elements = [self.filteredpack(r, indexed, ids) for r in results]
diff --git a/test/python/testworkflow.py b/test/python/testworkflow.py
index b84a4c76..dd8fdb40 100644
--- a/test/python/testworkflow.py
+++ b/test/python/testworkflow.py
@@ -278,6 +278,14 @@ class TestWorkflow(unittest.TestCase):
results = list(workflow([(1, "text", "tags")]))
self.assertEqual(results[0], (0, "text", None))
+ # Test no merge with a single-action task - postprocess already flattens single-action
+ # results regardless of merge, so filteredrun's merge branch must match that (not
+ # iterate over already-flat per-element results as if they were per-action lists)
+ task = Task(lambda x: [pow(y, 2) for y in x], merge=None)
+ workflow = Workflow([task])
+ results = list(workflow([2, 4, 6]))
+ self.assertEqual(results, [4, 16, 36])
+
def testMergeUnbalancedWorkflow(self):
"""
Test merge tasks with unbalanced outputs (i.e. one action produce more output than another for same input).