Skip to content

[Fix-18409][Common] Fix DAG.addEdge accepting an edge that creates a cycle when paths converge#18410

Open
nkuprins wants to merge 1 commit into
apache:devfrom
nkuprins:Fix-18409
Open

[Fix-18409][Common] Fix DAG.addEdge accepting an edge that creates a cycle when paths converge#18410
nkuprins wants to merge 1 commit into
apache:devfrom
nkuprins:Fix-18409

Conversation

@nkuprins

Copy link
Copy Markdown

Was this PR generated or assisted by AI?

YES - the bug was found using AI-assisted static analysis, and the fix and regression test were AI-assisted. I verified everything myself: I confirmed the failure by running the new test against unmodified dev (fails), reviewed the logic, and confirmed the fix (passes) with the full dolphinscheduler-common suite green.

Purpose of the pull request

Closes #18409. DAG.isLegalAddEdge bounds its cycle-check BFS with a node-count budget (--verticesCount > 0) instead of tracking visited nodes. On graphs where paths converge, a node is enqueued once per incoming edge, exhausting the budget before the BFS reaches fromNode, so a cycle-creating edge is wrongly judged legal and inserted. This replaces the budget with a visited-set - the correct BFS termination condition - which cannot be defeated by path convergence and also avoids redundant re-enqueueing on dense graphs.

Brief change log

  • common/graph/DAG.java: track visited nodes in isLegalAddEdge instead of a decrementing verticesCount budget; add HashSet import.
  • common/graph/DAGTest.java: add testCycleWithConvergingPaths, a fan-shaped graph asserting the cycle-creating back-edge is rejected and no cycle is introduced.

Verify this pull request

This change added tests and can be verified as follows:

  • testCycleWithConvergingPaths fails on current dev (addEdge returns true for a cycle-creating edge) and passes with the fix.
  • Full dolphinscheduler-common suite passes (139 tests, 0 failures) on JDK 8.
  • Spotless format check passes.

@nkuprins nkuprins requested a review from SbloodyS as a code owner July 10, 2026 23:37
@boring-cyborg

boring-cyborg Bot commented Jul 10, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines. (https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)

@SbloodyS SbloodyS requested a review from ruanwenjun July 13, 2026 06:22
@SbloodyS SbloodyS added the bug Something isn't working label Jul 13, 2026
@SbloodyS SbloodyS added this to the 3.5.0 milestone Jul 13, 2026
@SbloodyS SbloodyS added the first time contributor First-time contributor label Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working first time contributor First-time contributor test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [common] DAG.addEdge may accept an edge that creates a cycle when paths converge

2 participants