Repository navigation
Fix harness DAG slow-branch test cased by nil initialization of pregel engine - #16591
Conversation
📝 WalkthroughWalkthroughA 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. ChangesTest relocation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
internal/harness/core/workflow_graph_test.gointernal/harness/harness_test.go
💤 Files with no reviewable changes (1)
- internal/harness/core/workflow_graph_test.go
| sg.AddNode("slow", func(ctx context.Context, state any) (any, error) { | ||
| close(slowStarted) | ||
| <-releaseSlow | ||
| record("slow") |
There was a problem hiding this comment.
🩺 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.
| 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) |
There was a problem hiding this comment.
🎯 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.
| 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.
No description provided.