Skip to content

Refactor(harness): remove naive inline graph engine , unify graph execution under single pregel engine - #16608

Merged
yingfeng merged 8 commits into
infiniflow:mainfrom
yingfeng:fixharness
Jul 3, 2026
Merged

yingfeng merged 8 commits into
infiniflow:mainfrom
yingfeng:fixharness

Conversation

@yingfeng

@yingfeng yingfeng commented Jul 3, 2026

Copy link
Copy Markdown
Member

No description provided.

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Jul 3, 2026
@yingfeng yingfeng added the ci Continue Integration label Jul 3, 2026
@yingfeng
yingfeng marked this pull request as draft July 3, 2026 09:08
@yingfeng
yingfeng marked this pull request as ready for review July 3, 2026 09:08
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds shared graph interfaces and types, refactors graph construction and execution around internal implementations, wires Pregel through init-time registration, and updates harness consumers and tests to use types.StateGraph, types.CompiledGraph, and checkpoint.BaseCheckpointer.

Changes

Graph types/execution abstraction refactor

Layer / File(s) Summary
Shared graph contracts
internal/harness/graph/types/types.go
Adds exported graph structs, graph and compiled-graph interfaces, and Pregel runner registration hooks in types.
Internal graph and inspection implementation
internal/harness/graph/graph/*, internal/harness/core/setup_pregel_test.go
Reworks the graph package around internal implementations, moves checkpoint access behind checkpoint.BaseCheckpointer, and adds Pregel side-effect import setup.
Pregel engine and runner wiring
internal/harness/graph/pregel/*
Refactors the Pregel engine to the new graph/checkpointer abstractions and registers the runner during package init.
Harness re-export wiring
internal/harness/harness.go
Redirects harness exports to the new types/checkpoint abstractions and removes the earlier inline runner registration.
Core harness consumers migrated to types/checkpoint
internal/harness/core/*
Updates ReAct, workflow, sub-agent, and task wiring to the new types and checkpointer APIs, including loop and recursion-limit changes.
Graph package tests adapted to Pregel and inspector APIs
internal/harness/graph/graph/*_test.go
Skips Pregel-only legacy tests and routes state/history/fork operations through the inspector interface.
Production and integration test adjustments
internal/harness/core/*test.go, internal/harness/graph/channels/reducer.go
Updates stress and integration coverage for the new execution behavior, trigger-mode setter, recursion limits, and reducer initialization.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested reviewers: JinHai-CN, yuzhichang

Poem

I’m a rabbit, quick and bright,
Hopping through types by moonlight.
Checkpoints hum, and loops now sing,
With Pregel softly taking wing.
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was provided, so the required Summary section and context from the template are missing. Add a Summary section that briefly explains the goal, background, and main impact of the refactor.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: moving graph execution to a single Pregel engine and removing the inline engine.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/harness/core/agentcore_test.go (1)

32-40: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Guard empty responses before indexing. &mockModel{} panics if Generate runs before any addResp; return an error instead of indexing m.responses[m.callCount].

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/core/agentcore_test.go` around lines 32 - 40, The mock model
Generate path in mockModel should not index m.responses when the slice is empty,
since &mockModel{} can be used before any addResp call. Update Generate to guard
against len(m.responses) == 0 before selecting m.responses[m.callCount], and
return a non-nil error in that case; keep the existing callCount cycling logic
intact for the non-empty case.
🧹 Nitpick comments (7)
internal/harness/graph/graph/graph.go (2)

358-379: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Compile silently ignores options of unexpected type.

opts ...interface{} with a CompileOption type assertion means any mistyped/wrong option is dropped without error, masking configuration mistakes (e.g., a checkpointer or recursion limit that never takes effect). Consider returning an error for opts that aren't CompileOption.

♻️ Proposed change
 	for _, opt := range opts {
 		if fn, ok := opt.(CompileOption); ok {
 			fn(cg)
+		} else {
+			return nil, fmt.Errorf("graph: unsupported compile option type %T", opt)
 		}
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/graph/graph.go` around lines 358 - 379, The Compile
method on stateGraph is dropping any option that does not satisfy CompileOption,
which hides configuration mistakes. Update Compile to validate each entry in
opts and return an error when an unexpected option type is passed instead of
silently skipping it, while keeping the existing behavior for valid
CompileOption values and the cg/nodeTriggerMode setup.

381-385: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Type WithCheckpointer as checkpoint.BaseCheckpointer
compiledGraph.checkpointer is later asserted to checkpoint.BaseCheckpointer in GetState/GetStateHistory, so the current interface{} signature lets invalid values slip through and panic at runtime. Typing the option prevents that at compile time.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/graph/graph.go` around lines 381 - 385, The
WithCheckpointer CompileOption is too loosely typed with interface{}, which
allows invalid values to be set on compiledGraph.checkpointer and later panic in
GetState and GetStateHistory when they assert checkpoint.BaseCheckpointer.
Update WithCheckpointer to accept checkpoint.BaseCheckpointer directly, and keep
the assignment in the returned closure aligned with compiledGraph.checkpointer
so invalid checkpointers are rejected at compile time.
internal/harness/core/setup_pregel_test.go (1)

1-4: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Stale doc comment.

The comment says "Package core_test" while the declaration is package core, and references graph.PregelRunFunc, which is now types.PregelRunFunc (set via types.SetPregelRunFunc). Update to avoid confusion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/core/setup_pregel_test.go` around lines 1 - 4, Update the
stale package comment in the setup file so it matches the actual package
declaration and current API names. The comment should no longer say "Package
core_test" when the file declares package core, and it should reference
types.PregelRunFunc and types.SetPregelRunFunc instead of graph.PregelRunFunc.
Keep the intent of explaining that importing pregel triggers init setup for
compiled.Invoke(), but align the wording with the current symbols.
internal/harness/graph/graph/compiled.go (1)

35-50: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

NewCompiledStateGraph panics on any other types.CompiledGraph implementation.

The signature now accepts the types.CompiledGraph interface, but the default branch panics for anything other than *compiledGraph/*CompiledStateGraph. Since the return type is a concrete *CompiledStateGraph (no error), a caller passing a different implementation gets a hard crash. Consider documenting this precondition clearly, or returning (*CompiledStateGraph, error) if external implementations are plausible.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/graph/compiled.go` around lines 35 - 50,
NewCompiledStateGraph currently accepts the types.CompiledGraph interface but
still panics for any implementation other than *compiledGraph or
*CompiledStateGraph. Either document this constructor as only supporting those
concrete types, or change NewCompiledStateGraph to return (*CompiledStateGraph,
error) and handle the default case without crashing; use the
NewCompiledStateGraph switch and its compiledGraph/CompiledStateGraph cases as
the reference points.
internal/harness/graph/graph/message.go (1)

161-171: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unchecked type assertion on NewStateGraph result.

NewStateGraph(stateSchema).(*stateGraph) will panic if NewStateGraph ever returns a different concrete implementation of types.StateGraph. Since both live in this package the invariant holds today, but consider constructing the *stateGraph directly (or via an internal constructor) to avoid coupling NewMessageGraph to the assertion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/graph/message.go` around lines 161 - 171, Unchecked
type assertion in NewMessageGraph: NewStateGraph(stateSchema).(*stateGraph) can
panic if the concrete type ever changes. Update NewMessageGraph to build the
concrete stateGraph directly, or route it through an internal constructor that
returns *stateGraph, so the MessageGraph setup and messagesChannel registration
no longer depend on the assertion.
internal/harness/core/production_stress_test.go (1)

175-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Seq/par/soak blocks still discard the real error; inconsistent with the loop block's fix.

The loop-graph block (invokeErr at Line 237) now surfaces the concrete error, but the sequential (Line 179) and parallel (Line 208) blocks still emit a generic fmt.Errorf("failed"), and the soak test (Line 339) drops invokeErr entirely. This makes root-causing failures in these sections harder than necessary, and is inconsistent with the described intent for this change.

♻️ Proposed fix
-			if invokeErr != nil {
-				results <- result{fmt.Sprintf("seq_%d", id), fmt.Errorf("failed"), 0}
+			if invokeErr != nil {
+				results <- result{fmt.Sprintf("seq_%d", id), invokeErr, 0}
 				return
 			}
-			if invokeErr != nil {
-				results <- result{fmt.Sprintf("par_%d", id), fmt.Errorf("failed"), 0}
+			if invokeErr != nil {
+				results <- result{fmt.Sprintf("par_%d", id), invokeErr, 0}
 				return
 			}
-		if invokeErr != nil {
-			t.Fatalf("iteration %d failed", i)
+		if invokeErr != nil {
+			t.Fatalf("iteration %d failed: %v", i, invokeErr)
 		}

Also applies to: 204-211, 335-340

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/core/production_stress_test.go` around lines 175 - 182, The
sequential, parallel, and soak paths in production_stress_test still hide or
drop the real invokeErr, unlike the loop-graph fix. Update the result handling
in runGraphAndCollect callers so the seq and par blocks propagate invokeErr
instead of fmt.Errorf("failed"), and the soak block also preserves and returns
the concrete error. Use the existing runGraphAndCollect, result, and invokeErr
handling in production_stress_test as the anchors when making the change.
internal/harness/graph/pregel/engine.go (1)

1509-1521: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid mutating inputMap while ranging over it.

The inputMap[guessed] = value insertion happens during iteration of inputMap. Go permits this (the new entry may be produced or skipped), and it's currently harmless because guessed is already a registered channel and would just hit the continue. Still, this is a fragile pattern — collecting remaps into a side list and applying them after the loop makes intent explicit and refactor-safe.

♻️ Suggested refactor
-	for key, value := range inputMap {
-		if _, ok := registry.Get(key); ok {
-			continue
-		}
-		guessed := caseFoldKey(registry, key)
-		if guessed != "" {
-			delete(inputMap, key)
-			inputMap[guessed] = value
-		} else {
-			registry.Register(key, channels.NewLastValue(value))
-		}
-	}
+	remaps := make(map[string]string)
+	for key := range inputMap {
+		if _, ok := registry.Get(key); ok {
+			continue
+		}
+		if guessed := caseFoldKey(registry, key); guessed != "" {
+			remaps[key] = guessed
+		} else {
+			registry.Register(key, channels.NewLastValue(inputMap[key]))
+		}
+	}
+	for from, to := range remaps {
+		inputMap[to] = inputMap[from]
+		delete(inputMap, from)
+	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/pregel/engine.go` around lines 1509 - 1521, Avoid
mutating inputMap during its own range loop in the engine write path. In the
input-registration block that uses registry.Get, caseFoldKey, and
channels.NewLastValue, collect any key remaps (and registrations) in a temporary
list while iterating, then apply the delete/insert or registry.Register actions
after the loop. This keeps the behavior the same but makes the intent explicit
and avoids fragile iteration-time map writes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/harness/graph/graph/graph_enterprise_integration_test.go`:
- Line 269: The Pregel skip in the enterprise graph integration tests should be
removed so these cases keep running until exact parity exists. Update the test
setup in TestEnterprise_ConditionalEdge_MultiWay and
TestEnterprise_DAGWithConditionalEdge so they are not gated by the t.Skip in
graph_enterprise_integration_test.go, and keep them enabled against the current
graph engine coverage rather than deferring entirely to Pregel. If parity is
still incomplete, add or adapt the existing enterprise assertions instead of
skipping the tests.

In `@internal/harness/graph/graph/state_inspector.go`:
- Line 80: Guard the direct checkpoint.BaseCheckpointer type assertion in
StateInspector methods before calling any checkpointer operations, since
compiledGraph.checkpointer is an interface and WithCheckpointer allows
non-BaseCheckpointer values that can panic. Update the StateInspector methods
that currently use cg.checkpointer.(checkpoint.BaseCheckpointer), especially
UpdateState and ForkThread, to perform a comma-ok assertion once, return a
descriptive error if the cast fails, and reuse the typed value for the
subsequent Get/Put/List calls.

In `@internal/harness/graph/pregel/init_pregel.go`:
- Around line 16-42: runCompiledGraph is ignoring the requested stream mode, so
compiledGraph.Stream(...) cannot produce the correct streaming shape. Update
runCompiledGraph to pass streamMode through to the Pregel engine instead of
always calling engine.RunSync, using the existing runCompiledGraph and
NewEngine/engine execution path to route StreamMode* requests correctly.

---

Outside diff comments:
In `@internal/harness/core/agentcore_test.go`:
- Around line 32-40: The mock model Generate path in mockModel should not index
m.responses when the slice is empty, since &mockModel{} can be used before any
addResp call. Update Generate to guard against len(m.responses) == 0 before
selecting m.responses[m.callCount], and return a non-nil error in that case;
keep the existing callCount cycling logic intact for the non-empty case.

---

Nitpick comments:
In `@internal/harness/core/production_stress_test.go`:
- Around line 175-182: The sequential, parallel, and soak paths in
production_stress_test still hide or drop the real invokeErr, unlike the
loop-graph fix. Update the result handling in runGraphAndCollect callers so the
seq and par blocks propagate invokeErr instead of fmt.Errorf("failed"), and the
soak block also preserves and returns the concrete error. Use the existing
runGraphAndCollect, result, and invokeErr handling in production_stress_test as
the anchors when making the change.

In `@internal/harness/core/setup_pregel_test.go`:
- Around line 1-4: Update the stale package comment in the setup file so it
matches the actual package declaration and current API names. The comment should
no longer say "Package core_test" when the file declares package core, and it
should reference types.PregelRunFunc and types.SetPregelRunFunc instead of
graph.PregelRunFunc. Keep the intent of explaining that importing pregel
triggers init setup for compiled.Invoke(), but align the wording with the
current symbols.

In `@internal/harness/graph/graph/compiled.go`:
- Around line 35-50: NewCompiledStateGraph currently accepts the
types.CompiledGraph interface but still panics for any implementation other than
*compiledGraph or *CompiledStateGraph. Either document this constructor as only
supporting those concrete types, or change NewCompiledStateGraph to return
(*CompiledStateGraph, error) and handle the default case without crashing; use
the NewCompiledStateGraph switch and its compiledGraph/CompiledStateGraph cases
as the reference points.

In `@internal/harness/graph/graph/graph.go`:
- Around line 358-379: The Compile method on stateGraph is dropping any option
that does not satisfy CompileOption, which hides configuration mistakes. Update
Compile to validate each entry in opts and return an error when an unexpected
option type is passed instead of silently skipping it, while keeping the
existing behavior for valid CompileOption values and the cg/nodeTriggerMode
setup.
- Around line 381-385: The WithCheckpointer CompileOption is too loosely typed
with interface{}, which allows invalid values to be set on
compiledGraph.checkpointer and later panic in GetState and GetStateHistory when
they assert checkpoint.BaseCheckpointer. Update WithCheckpointer to accept
checkpoint.BaseCheckpointer directly, and keep the assignment in the returned
closure aligned with compiledGraph.checkpointer so invalid checkpointers are
rejected at compile time.

In `@internal/harness/graph/graph/message.go`:
- Around line 161-171: Unchecked type assertion in NewMessageGraph:
NewStateGraph(stateSchema).(*stateGraph) can panic if the concrete type ever
changes. Update NewMessageGraph to build the concrete stateGraph directly, or
route it through an internal constructor that returns *stateGraph, so the
MessageGraph setup and messagesChannel registration no longer depend on the
assertion.

In `@internal/harness/graph/pregel/engine.go`:
- Around line 1509-1521: Avoid mutating inputMap during its own range loop in
the engine write path. In the input-registration block that uses registry.Get,
caseFoldKey, and channels.NewLastValue, collect any key remaps (and
registrations) in a temporary list while iterating, then apply the delete/insert
or registry.Register actions after the loop. This keeps the behavior the same
but makes the intent explicit and avoids fragile iteration-time map writes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 254329ba-c5b6-4c5c-bf1c-6a8fd82c1877

📥 Commits

Reviewing files that changed from the base of the PR and between 1880e65 and 680356c.

📒 Files selected for processing (45)
  • internal/harness/core/agentcore_test.go
  • internal/harness/core/graph_integration_test.go
  • internal/harness/core/multiagent_integration_test.go
  • internal/harness/core/production_stress_test.go
  • internal/harness/core/react_agent.go
  • internal/harness/core/react_graph.go
  • internal/harness/core/setup_pregel_test.go
  • internal/harness/core/subagent_node.go
  • internal/harness/core/subagent_node_test.go
  • internal/harness/core/workflow_graph.go
  • internal/harness/core/workflow_graph_test.go
  • internal/harness/graph/channels/reducer.go
  • internal/harness/graph/graph/checkpoint_recovery_test.go
  • internal/harness/graph/graph/compiled.go
  • internal/harness/graph/graph/graph.go
  • internal/harness/graph/graph/graph_advanced_fault_edge_test.go
  • internal/harness/graph/graph/graph_channel_test.go
  • internal/harness/graph/graph/graph_checkpoint_migration_test.go
  • internal/harness/graph/graph/graph_concurrency_test.go
  • internal/harness/graph/graph/graph_enterprise_integration_test.go
  • internal/harness/graph/graph/graph_integration_test.go
  • internal/harness/graph/graph/graph_persistence_evolution_test.go
  • internal/harness/graph/graph/graph_subgraph_state_test.go
  • internal/harness/graph/graph/graph_test.go
  • internal/harness/graph/graph/graph_time_travel_test.go
  • internal/harness/graph/graph/graph_timetravel_send_test.go
  • internal/harness/graph/graph/graph_topology_checkpoint_edge_test.go
  • internal/harness/graph/graph/loop.go
  • internal/harness/graph/graph/message.go
  • internal/harness/graph/graph/parallel.go
  • internal/harness/graph/graph/state.go
  • internal/harness/graph/graph/state_inspector.go
  • internal/harness/graph/graph/state_inspector_test.go
  • internal/harness/graph/pregel/engine.go
  • internal/harness/graph/pregel/engine_test.go
  • internal/harness/graph/pregel/init_pregel.go
  • internal/harness/graph/pregel/pregel_async_stream_edge_test.go
  • internal/harness/graph/pregel/pregel_durability_timetravel_test.go
  • internal/harness/graph/pregel/pregel_fault_edge_test.go
  • internal/harness/graph/pregel/pregel_perf_benchmark_test.go
  • internal/harness/graph/pregel/pregel_pressure_test.go
  • internal/harness/graph/pregel/subgraph.go
  • internal/harness/graph/task/decorator.go
  • internal/harness/graph/types/types.go
  • internal/harness/harness.go


// TestEnterprise_ConditionalEdge_MultiWay verifies a 3-way conditional edge.
func TestEnterprise_ConditionalEdge_MultiWay(t *testing.T) {
t.Skip("requires Pregel engine - see pregel/ for equivalent tests")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check pregel/ tests for equivalent multi-way conditional-edge and DAG-conditional coverage
rg -n -i 'conditionaledge|multiway|dagwithconditional' internal/harness/graph/pregel --type=go

Repository: infiniflow/ragflow

Length of output: 1328


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '220,320p' internal/harness/graph/graph/graph_enterprise_integration_test.go
printf '\n---\n'
sed -n '520,580p' internal/harness/graph/graph/graph_enterprise_integration_test.go
printf '\n=== PREGEL ===\n'
sed -n '600,700p' internal/harness/graph/pregel/pregel_pressure_test.go
printf '\n---\n'
sed -n '1500,1575p' internal/harness/graph/pregel/pregel_pressure_test.go

Repository: infiniflow/ragflow

Length of output: 10234


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -i 'path_c|3-way|multi-way|multiway|AddConditionalEdges\(' internal/harness/graph/pregel --type=go

Repository: infiniflow/ragflow

Length of output: 985


Keep these tests enabled until Pregel has exact parity

TestEnterprise_ConditionalEdge_MultiWay still has no matching 3-way Pregel case, and TestEnterprise_DAGWithConditionalEdge only lines up with a simpler 2-branch DAG. The current skip hides coverage for these shapes at internal/harness/graph/graph/graph_enterprise_integration_test.go:269, 542.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/graph/graph_enterprise_integration_test.go` at line
269, The Pregel skip in the enterprise graph integration tests should be removed
so these cases keep running until exact parity exists. Update the test setup in
TestEnterprise_ConditionalEdge_MultiWay and
TestEnterprise_DAGWithConditionalEdge so they are not gated by the t.Skip in
graph_enterprise_integration_test.go, and keep them enabled against the current
graph engine coverage rather than deferring entirely to Pregel. If parity is
still incomplete, add or adapt the existing enterprise assertions instead of
skipping the tests.

Comment on lines +16 to +42
func runCompiledGraph(
ctx context.Context,
cg types.CompiledGraph,
input interface{},
config *types.RunnableConfig,
streamMode types.StreamMode,
) (interface{}, error) {
interruptKeys := make([]string, 0, len(cg.GetInterrupts()))
for k := range cg.GetInterrupts() {
interruptKeys = append(interruptKeys, k)
}
interruptAfterKeys := make([]string, 0, len(cg.GetInterruptsAfter()))
for k := range cg.GetInterruptsAfter() {
interruptAfterKeys = append(interruptAfterKeys, k)
}

cp, _ := cg.GetCheckpointer().(checkpoint.BaseCheckpointer)
engine := NewEngine(cg.GetGraph(),
WithCheckpointer(cp),
WithInterrupts(interruptKeys...),
WithInterruptsAfter(interruptAfterKeys...),
WithRecursionLimit(cg.GetRecursionLimit()),
WithDebug(cg.IsDebug()),
WithConfig(config),
)
return engine.RunSync(ctx, input)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Where is PregelRunFunc invoked, and does Stream route through it with streamMode?
rg -nP 'PregelRunFunc|func .*\brun\b\(' internal/harness/graph/graph/compiled.go
rg -nP 'func .*compiledGraph.*Stream\(' internal/harness/graph/graph/compiled.go -A 15

Repository: infiniflow/ragflow

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the relevant graph/compiled files and inspect the call path for runCompiledGraph.
fd -a 'compiled.go|init_pregel.go' internal/harness/graph

printf '\n--- init_pregel.go ---\n'
wc -l internal/harness/graph/pregel/init_pregel.go
cat -n internal/harness/graph/pregel/init_pregel.go | sed -n '1,140p'

printf '\n--- compiled.go candidates ---\n'
fd -a 'compiled.go' internal/harness/graph

Repository: infiniflow/ragflow

Length of output: 1880


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- compiled.go outline ---\n'
ast-grep outline internal/harness/graph/graph/compiled.go --view expanded || true

printf '\n--- search for PregelRunFunc / Stream / runCompiledGraph ---\n'
rg -n "PregelRunFunc|SetPregelRunFunc|runCompiledGraph|streamMode|func .*Stream\(" internal/harness/graph -A 6 -B 4

printf '\n--- relevant type definitions ---\n'
fd -a 'types.go' internal/harness/graph
rg -n "type PregelRunFunc|type StreamMode|func .*Invoke|func .*Stream\(" internal/harness/graph/types -A 8 -B 4

Repository: infiniflow/ragflow

Length of output: 35084


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- graph.go Stream/run ---\n'
sed -n '420,470p' internal/harness/graph/graph/graph.go

printf '\n--- pregel engine methods ---\n'
rg -n "func .*RunSync|func .*Run\(" internal/harness/graph/pregel -A 20 -B 6

printf '\n--- search for streamMode use in pregel engine ---\n'
rg -n "streamMode|StreamMode" internal/harness/graph/pregel -A 4 -B 4

Repository: infiniflow/ragflow

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- engine recursion limit defaults/options ---\n'
rg -n "recursionLimit|WithRecursionLimit|NewEngine\(" internal/harness/graph/pregel/engine.go internal/harness/graph/pregel -A 6 -B 4

printf '\n--- compiled graph recursion limit plumbing ---\n'
rg -n "GetRecursionLimit\(|recursionLimit" internal/harness/graph/graph internal/harness/graph/types -A 4 -B 4

printf '\n--- any zero-limit tests or guards ---\n'
rg -n "RecursionLimit.*0|WithRecursionLimit\(0\)|recursion limit" internal/harness/graph -A 4 -B 4

Repository: infiniflow/ragflow

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '124,180p' internal/harness/graph/graph/compiled.go

Repository: infiniflow/ragflow

Length of output: 1776


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n--- compiled graph stream tests/usages ---\n'
rg -n "CompiledStateGraph.*Stream|\.Stream\(ctx, .*StreamMode|StreamModeUpdates|StreamModeTasks|StreamModeCheckpoints" internal/harness/graph/graph internal/harness/graph/pregel -A 4 -B 4

printf '\n--- pregel stream-mode expectations in tests ---\n'
sed -n '1,180p' internal/harness/graph/pregel/pregel_stream_retry_integration_test.go

Repository: infiniflow/ragflow

Length of output: 13606


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '250,320p' internal/harness/graph/graph/graph_integration_test.go

Repository: infiniflow/ragflow

Length of output: 2104


Forward streamMode to the Pregel engine
compiledGraph.Stream(...) passes the requested mode into this hook, but runCompiledGraph ignores it and always calls engine.RunSync(...). That collapses every StreamMode* request into a single final result instead of the requested stream shape.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/pregel/init_pregel.go` around lines 16 - 42,
runCompiledGraph is ignoring the requested stream mode, so
compiledGraph.Stream(...) cannot produce the correct streaming shape. Update
runCompiledGraph to pass streamMode through to the Pregel engine instead of
always calling engine.RunSync, using the existing runCompiledGraph and
NewEngine/engine execution path to route StreamMode* requests correctly.

@yingfeng
yingfeng merged commit 8db68e3 into infiniflow:main Jul 3, 2026
3 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/harness/graph/graph/state_inspector.go`:
- Around line 233-241: The fallback path in the checkpoint update flow returns
the original config, which can leave callers pointing at the old checkpoint
instead of the newly created one. In the state inspector’s checkpoint update
logic, update the `err != nil || len(entries) == 0` branch to return a config
that includes `newThreadID` (and the new checkpoint identity if available)
rather than the input `config`, so the caller always advances to the updated
checkpoint even when `cp.List` fails or returns no entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8827b7ca-179c-4af9-bb64-b7a1814bd3e1

📥 Commits

Reviewing files that changed from the base of the PR and between 3efa0fe and 41b93ef.

📒 Files selected for processing (1)
  • internal/harness/graph/graph/state_inspector.go

Comment on lines +233 to +241
if err := cp.Put(ctx, newConfig, cpData); err != nil {
return nil, fmt.Errorf("failed to save updated checkpoint: %w", err)
}

// 4. Return the config for the new checkpoint.
listCfg := map[string]interface{}{
constants.ConfigKeyThreadID: newThreadID,
}
entries, err := cg.checkpointer.List(ctx, listCfg, 1)
entries, err := cp.List(ctx, listCfg, 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify List ordering (newest first?) and whether callers depend on the returned config id.
sed -n '600,700p' internal/harness/graph/checkpoint/checkpoint.go
rg -nP '\.UpdateState\s*\(' internal/harness --type=go -C2

Repository: infiniflow/ragflow

Length of output: 7363


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant implementation and nearby helpers.
sed -n '180,290p' internal/harness/graph/graph/state_inspector.go
printf '\n---\n'
sed -n '1,220p' internal/harness/graph/graph/state_inspector_test.go
printf '\n---\n'
sed -n '1,220p' internal/harness/graph/checkpoint/checkpoint.go

Repository: infiniflow/ragflow

Length of output: 16828


Return a config with the new checkpoint on the fallback path
List(limit=1) is newest-first, but the err != nil || len(entries) == 0 path falls back to the input config, which leaves callers on the pre-update checkpoint. Return at least a config carrying newThreadID instead of the original config here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/harness/graph/graph/state_inspector.go` around lines 233 - 241, The
fallback path in the checkpoint update flow returns the original config, which
can leave callers pointing at the old checkpoint instead of the newly created
one. In the state inspector’s checkpoint update logic, update the `err != nil ||
len(entries) == 0` branch to return a config that includes `newThreadID` (and
the new checkpoint identity if available) rather than the input `config`, so the
caller always advances to the updated checkpoint even when `cp.List` fails or
returns no entries.

xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant