Skip to content

Fix harness DAG slow-branch test cased by nil initialization of pregel engine - #16591

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
yingfeng:fixharness
Jul 3, 2026
Merged

yingfeng merged 1 commit 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 the size:XS This PR changes 0-9 lines, ignoring generated files. label 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 04:38
@yingfeng
yingfeng marked this pull request as ready for review July 3, 2026 04:38
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A test for DAG merge ordering (TestGraph_DAG_SlowBranchMerge) was removed from workflow_graph_test.go and re-added, with updated imports and refined synchronization logic, in harness_test.go. No production code changes are included.

Changes

Test relocation

Layer / File(s) Summary
Remove obsolete DAG test
internal/harness/core/workflow_graph_test.go
Deletes the TestGraph_DAG_SlowBranchMerge test that verified merge nodes wait for slow-branch completion.
Re-add DAG test with updated synchronization
internal/harness/harness_test.go
Adds sync, time, and graph/types imports, and reintroduces TestGraph_DAG_SlowBranchMerge with a dispatch->fast/slow->merge DAG, channel-based blocking, and timeout-based assertions on execution order.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: ☯️ refactor

Suggested reviewers: yuzhichang

Poem

A test hopped from file to file,
Same DAG, same merge, new style,
Channels block, then release with cheer,
Slow node finishes, merge draws near,
Hop hop hop — the order's clear! 🐇

🚥 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 background context are missing. Add a Summary section that briefly explains the fix, the affected harness test behavior, and any relevant background.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is specific and matches the main change: fixing the harness DAG slow-branch test around pregel engine initialization.

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: 2

🤖 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/harness_test.go`:
- Around line 132-135: The slow node added via sg.AddNode("slow") can remain
blocked if an earlier timeout path calls t.Fatal before releaseSlow is closed.
Update the harness test to invoke compiled.Invoke with a cancellable context
instead of context.Background(), and add a one-shot release helper around
releaseSlow so the slow goroutine is always unblocked on both success and
failure paths. Make sure the cleanup is wired in the test flow around the
slow-node coordination and the timeout checks that can fail early.
- Around line 198-211: The order-check in harness_test.go can falsely pass when
one of the sentinels is still unset, because the comparison in the harness test
only checks mergeIdx against slowIdx. Update the test logic around the order
scan so it explicitly verifies that both the "slow" and "merge" nodes were found
before comparing their positions, using the same order slice and sentinel
variables in the harness test.
🪄 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: 01543992-2d0c-4fa2-b5b4-1bf69d5b83e5

📥 Commits

Reviewing files that changed from the base of the PR and between 9182296 and c4bcb1c.

📒 Files selected for processing (2)
  • internal/harness/core/workflow_graph_test.go
  • internal/harness/harness_test.go
💤 Files with no reviewable changes (1)
  • internal/harness/core/workflow_graph_test.go

Comment on lines +132 to +135
sg.AddNode("slow", func(ctx context.Context, state any) (any, error) {
close(slowStarted)
<-releaseSlow
record("slow")

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Make the blocked slow node cancellable on failure paths.

If any timeout before Line 186 calls t.Fatal, releaseSlow is never closed while compiled.Invoke(context.Background(), ...) may still be blocked in the slow node. Use a cancellable context and a one-shot release helper so the goroutine can unwind even when the test fails early.

Proposed fix
 	releaseSlow := make(chan struct{})
+	var releaseSlowOnce sync.Once
+	release := func() {
+		releaseSlowOnce.Do(func() { close(releaseSlow) })
+	}
+	defer release()
 	mergeRan := make(chan struct{}, 1)
@@
 	sg.AddNode("slow", func(ctx context.Context, state any) (any, error) {
 		close(slowStarted)
-		<-releaseSlow
+		select {
+		case <-releaseSlow:
+		case <-ctx.Done():
+			return nil, ctx.Err()
+		}
 		record("slow")
 		return map[string]any{"messages": []string{"slow done"}}, nil
 	})
@@
 	done := make(chan error, 1)
+	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+	defer cancel()
 	go func() {
-		_, err := compiled.Invoke(context.Background(), map[string]any{})
+		_, err := compiled.Invoke(ctx, map[string]any{})
 		done <- err
 	}()
@@
-	close(releaseSlow)
+	release()

Also applies to: 162-186

🤖 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/harness_test.go` around lines 132 - 135, The slow node added
via sg.AddNode("slow") can remain blocked if an earlier timeout path calls
t.Fatal before releaseSlow is closed. Update the harness test to invoke
compiled.Invoke with a cancellable context instead of context.Background(), and
add a one-shot release helper around releaseSlow so the slow goroutine is always
unblocked on both success and failure paths. Make sure the cleanup is wired in
the test flow around the slow-node coordination and the timeout checks that can
fail early.

Comment on lines +198 to +211
if len(order) != 4 {
t.Errorf("expected 4 nodes (dispatch+fast+slow+merge), got %d: %v", len(order), order)
}
slowIdx, mergeIdx := -1, -1
for i, name := range order {
switch name {
case "slow":
slowIdx = i
case "merge":
mergeIdx = i
}
}
if mergeIdx < slowIdx {
t.Errorf("BUG: merge before slow branch. merge=%d, slow=%d", mergeIdx, slowIdx)

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

Validate that both ordered nodes were actually recorded.

mergeIdx < slowIdx passes when slowIdx == -1 and mergeIdx >= 0, so a malformed order with no recorded slow can still log success if the length happens to be 4. Fail fast when either sentinel remains unset.

Proposed fix
 	if len(order) != 4 {
-		t.Errorf("expected 4 nodes (dispatch+fast+slow+merge), got %d: %v", len(order), order)
+		t.Fatalf("expected 4 nodes (dispatch+fast+slow+merge), got %d: %v", len(order), order)
 	}
@@
 	}
-	if mergeIdx < slowIdx {
+	if slowIdx == -1 || mergeIdx == -1 {
+		t.Fatalf("expected slow and merge to be recorded, got order: %v", order)
+	}
+	if mergeIdx <= slowIdx {
 		t.Errorf("BUG: merge before slow branch. merge=%d, slow=%d", mergeIdx, slowIdx)
 	} else {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if len(order) != 4 {
t.Errorf("expected 4 nodes (dispatch+fast+slow+merge), got %d: %v", len(order), order)
}
slowIdx, mergeIdx := -1, -1
for i, name := range order {
switch name {
case "slow":
slowIdx = i
case "merge":
mergeIdx = i
}
}
if mergeIdx < slowIdx {
t.Errorf("BUG: merge before slow branch. merge=%d, slow=%d", mergeIdx, slowIdx)
if len(order) != 4 {
t.Fatalf("expected 4 nodes (dispatch+fast+slow+merge), got %d: %v", len(order), order)
}
slowIdx, mergeIdx := -1, -1
for i, name := range order {
switch name {
case "slow":
slowIdx = i
case "merge":
mergeIdx = i
}
}
if slowIdx == -1 || mergeIdx == -1 {
t.Fatalf("expected slow and merge to be recorded, got order: %v", order)
}
if mergeIdx <= slowIdx {
t.Errorf("BUG: merge before slow branch. merge=%d, slow=%d", mergeIdx, slowIdx)
🤖 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/harness_test.go` around lines 198 - 211, The order-check in
harness_test.go can falsely pass when one of the sentinels is still unset,
because the comparison in the harness test only checks mergeIdx against slowIdx.
Update the test logic around the order scan so it explicitly verifies that both
the "slow" and "merge" nodes were found before comparing their positions, using
the same order slice and sentinel variables in the harness test.

@yingfeng
yingfeng merged commit 19fcb4a into infiniflow:main Jul 3, 2026
9 of 12 checks passed
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 size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant