Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(pregel): preserve slice types during state reduction (#22014)

Sbaaoui Idriss4f511a5c7fcc
diff --git a/internal/harness/core/multiagent_integration_test.go b/internal/harness/core/multiagent_integration_test.go
index 8b618ce153..76d430418d 100644
--- a/internal/harness/core/multiagent_integration_test.go
+++ b/internal/harness/core/multiagent_integration_test.go
@@ -395,7 +395,7 @@ func TestMultiAgent_ErrorRecovery(t *testing.T) {
case *planExecState:
msgCount = len(s.Messages)
case map[string]interface{}:
- if msgs, ok := s["Messages"].([]interface{}); ok {
+ if msgs, ok := s["Messages"].([]string); ok {
msgCount = len(msgs)
}
}
diff --git a/internal/harness/core/production_stress_test.go b/internal/harness/core/production_stress_test.go
index 48390c4648..3c390332b7 100644
--- a/internal/harness/core/production_stress_test.go
+++ b/internal/harness/core/production_stress_test.go
@@ -501,6 +501,7 @@ func TestProduction_LargeStateGraph(t *testing.T) {
sg.AddNode(name, func(ctx context.Context, state interface{}) (interface{}, error) {
s := state.(*dagState)
s.Step = idx
+ s.Messages = nil // This node adds no messages.
return s, nil
})
if i == 0 {
diff --git a/internal/harness/core/workflow_graph.go b/internal/harness/core/workflow_graph.go
index a16fbabb85..fe9f33a20f 100644
--- a/internal/harness/core/workflow_graph.go
+++ b/internal/harness/core/workflow_graph.go
@@ -101,6 +101,7 @@ func NewSequentialGraph(ctx context.Context, cfg *SequentialConfig, cptr checkpo
// the underlying array with the graph's concurrent goroutines.
msgCopy := append([]*schema.Message(nil), s.Messages...)
iter := ag.Run(ctx, &AgentInput{Messages: msgCopy})
+ s.Messages = nil // Return only new messages to the append channel.
for {
ev, ok := iter.Next()
if !ok {
@@ -182,6 +183,7 @@ func NewParallelGraph(ctx context.Context, cfg *ParallelConfig, cptr checkpoint.
s := state.(*WorkflowGraphState)
msgCopy := s.SnapshotMessages()
iter := ag.Run(ctx, &AgentInput{Messages: msgCopy})
+ s.Messages = nil // Return only new messages to the append channel.
for {
ev, ok := iter.Next()
if !ok {
@@ -259,6 +261,7 @@ func NewLoopGraph(ctx context.Context, cfg *LoopConfig, cptr checkpoint.BaseChec
// the underlying array with the graph's concurrent goroutines.
msgCopy := append([]*schema.Message(nil), s.Messages...)
iter := ag.Run(ctx, &AgentInput{Messages: msgCopy})
+ s.Messages = nil // Return only new messages to the append channel.
for {
ev, ok := iter.Next()
if !ok {
diff --git a/internal/harness/core/workflow_graph_test.go b/internal/harness/core/workflow_graph_test.go
index 9bf5ef9ecd..342ff99c6a 100644
--- a/internal/harness/core/workflow_graph_test.go
+++ b/internal/harness/core/workflow_graph_test.go
@@ -755,7 +755,7 @@ func TestGraph_LargeParallel_50Nodes(t *testing.T) {
name := fmt.Sprintf("leaf_%d", idx)
sg.AddNode(name, func(ctx context.Context, state interface{}) (interface{}, error) {
s := state.(*dagState)
- s.Messages = append(s.Messages, fmt.Sprintf("leaf %d done", idx))
+ s.Messages = []string{fmt.Sprintf("leaf %d done", idx)}
return s, nil
})
if prev == "" {
@@ -1104,7 +1104,7 @@ func TestGraph_100NodeChain(t *testing.T) {
names[i] = name
sg.AddNode(name, func(ctx context.Context, state interface{}) (interface{}, error) {
s := state.(*dagState)
- s.Messages = append(s.Messages, name)
+ s.Messages = []string{name}
s.Step = idx
return s, nil
})
@@ -1192,7 +1192,7 @@ func TestGraph_50WayFanIn(t *testing.T) {
case *dagState:
msgCount = len(s.Messages)
case map[string]interface{}:
- if msgs, ok := s["Messages"].([]interface{}); ok {
+ if msgs, ok := s["Messages"].([]string); ok {
msgCount = len(msgs)
}
default:
@@ -1221,7 +1221,7 @@ func TestGraph_DeepConditionalBranching(t *testing.T) {
name := fmt.Sprintf("level_%d", i)
sg.AddNode(name, func(ctx context.Context, state interface{}) (interface{}, error) {
s := state.(*dagState)
- s.Messages = append(s.Messages, name)
+ s.Messages = []string{name}
return s, nil
})
}
@@ -1245,7 +1245,7 @@ func TestGraph_DeepConditionalBranching(t *testing.T) {
case *dagState:
msgCount = len(s.Messages)
case map[string]interface{}:
- if msgs, ok := s["Messages"].([]interface{}); ok {
+ if msgs, ok := s["Messages"].([]string); ok {
msgCount = len(msgs)
}
default:
diff --git a/internal/harness/graph/channels/reducer.go b/internal/harness/graph/channels/reducer.go
index f3f8742bb1..106a4e2bcb 100644
--- a/internal/harness/graph/channels/reducer.go
+++ b/internal/harness/graph/channels/reducer.go
@@ -70,7 +70,20 @@ func CreateReducerChannel(fieldName string, fieldType reflect.Type, reducer type
var channel Channel
switch fieldType.Kind() {
- case reflect.Slice, reflect.Array:
+ case reflect.Slice:
+ operator := BinaryOperator(func(a, b interface{}) interface{} {
+ return reflect.AppendSlice(reflect.ValueOf(a), reflect.ValueOf(b)).Interface()
+ })
+ if fieldType == reflect.TypeFor[[]any]() {
+ operator = ListAppend
+ }
+ if reducer != nil {
+ operator = BinaryOperator(reducer)
+ }
+ channel = NewBinaryOperatorAggregate(reflect.Zero(fieldType).Interface(), operator)
+ channel.SetKey(fieldName)
+ return channel, nil
+ case reflect.Array:
// For slices, use BinaryOperatorAggregate with append operator
channel = NewBinaryOperatorAggregate(fieldType, ListAppend)
case reflect.Map: