Skip to content

Report cyclic library dependencies as errors - #3236

Open
akozhushko wants to merge 2 commits into
eclipse-4diac:developfrom
akozhushko:fix/dependency-cycle
Open

akozhushko wants to merge 2 commits into
eclipse-4diac:developfrom
akozhushko:fix/dependency-cycle

Conversation

@akozhushko

@akozhushko akozhushko commented Nov 25, 2026 •

Copy link
Copy Markdown

Dependency resolution did not end when libraries require each other (a requires b, b requires a), when a library requires itself, or when the versions of libraries select each other without end. The worklist of buildDependencies never became empty and the build job kept running.

As suggested in the review, such libraries are now reported as errors instead of being resolved. The marker is attached to the dependencies of the project manifest like the other dependency markers in LibraryMarkerFactory:

  • Cyclic library dependency: a 1.0.0 -> b 1.0.0 -> a 1.0.0. (other libraries of overlapping cycles are listed as "Also involved")
  • Library a 1.0.0 requires itself (version 2.0.0).
  • The versions of the libraries a, b could not be resolved consistently because their requirements depend on each other.

The libraries of a cycle are not resolved and not linked, also with the preference to force load the explicit dependencies, and existing links to them are removed. Other libraries are resolved as before.

Changes in the resolution loop (details in the commit message):

  • The queue holds each library once and the changed flag of a dependency node is reset when it is visited.
  • A dependency that a new version of a library no longer requires is queued, so its own requirements are removed too.
  • Cycles of the resolved requirements are blocked after the queue is empty. Libraries that only lie behind a cycle are not reported.
  • Libraries that change each other's requirements without end are found by an exact repeated-state check, not by a visit counter, so a long acyclic chain is not reported.
  • The loop checks for cancellation.

On 968 random graphs without a cycle the result equals the original, except one graph with one additional download of a library that is not needed.

LibraryDependencyCycleTest (31 tests, libraries created with the new LibraryTestFixtures.createLibrary) checks the messages, that the libraries are not linked, removal of existing links, conflicts, the order of the project requirements and termination. A timeout and a cancelled build make a test fail instead of hanging. It also fails for 13 deliberately broken variants of the resolution.

Limitations:

  • The resolution stays greedy (highest version, no backtracking). A cycle or oscillation is reported for the chosen versions, even if another choice would avoid it, so the message does not claim that no solution exists.
  • If the resolution stops early because a library cannot be resolved, a cycle next to it can stay linked (the original code did not end on such graphs).
  • For libraries that oscillate, the result depends on the order of the project requirements and of the library names, as before.
  • A library named Project still replaces the cause of the project in a shared dependency, as before.

Related issue: #2978.

Copilot AI 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.

🟡 Changes recommended

Conflicting self-dependencies can still cause infinite resolution loops, and the cycle regression can pass on an unavailable-library error without verifying successful resolution.

2 open issues
What changed in this PR

This PR addresses nonterminating library dependency resolution in 4diac IDE by clearing each node’s change flag after processing, allowing cycles with stable version constraints to finish.

Changes:

  • Reset dependency-node state before processing.
  • Mark nodes changed when their last dependency cause is removed.
  • Add a watchdog-backed cycle regression test and register its fixtures.
File Description
tests/​org.eclipse.fordiac.ide.test.library/​src/​org/​eclipse/​fordiac/​ide/​test/​library/​LibraryTestFixtures.java Registers test08 and test09 archives.
tests/​org.eclipse.fordiac.ide.test.library/​src/​org/​eclipse/​fordiac/​ide/​test/​library/​LibraryDependencyCycleTest.java Adds an explicit-build cycle test with watchdog cancellation.
plugins/​org.eclipse.fordiac.ide.library/​src/​org/​eclipse/​fordiac/​ide/​library/​LibraryManager.java Resets the change flag before processing each dependency node.
plugins/​org.eclipse.fordiac.ide.library/​src/​org/​eclipse/​fordiac/​ide/​library/​DependencyNode.java Adds flag reset support and propagates removal of the last cause.

Review effort: Balanced

@akozhushko
akozhushko requested a balanced review from Copilot November 25, 2026 15:14

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Test Results (pull_request)

  156 files  + 1    156 suites  +1   1m 42s ⏱️ -20s
6 723 tests +31  6 722 ✅ +31  1 💤 ±0  0 ❌ ±0 
6 724 runs  +31  6 723 ✅ +31  1 💤 ±0  0 ❌ ±0 

Results for commit dcf4a0b. ± Comparison against base commit d2a1c54.

♻️ This comment has been updated with latest results.

Copilot AI 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.

🟡 Changes recommended

The dependency-processing limit counts skipped duplicate queue entries, causing false cycle errors on acyclic graphs and potentially leaving transitive dependencies unresolved.

3 open issues
2 resolved since last review

Review effort: Balanced

}

// import valid nodes
importDependencyNodes(project, libManagerData, projectManifest, markerList, progress.split(15));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the new fixture, this still links test10 1.0.0 after reporting that it requires itself at 2.0.0. Please skip importing the conflicting library and assert that it stays unlinked when force-loading is disabled.

final boolean rangeChanged = recalculate();
if (removed && causes.isEmpty()) {
// the node is not needed any more: it has to be visited again even if its range did not change
changed = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When a version change drops a dependency, LibraryManager calls removeCause at line 833 but never queues the changed node. Please enqueue it so its transitive dependencies can be removed too.

@@ -0,0 +1,134 @@
/*******************************************************************************
* Copyright (c) 2026 Andrii Kozhushko

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the copyright here should be MSR , please clarify that who gets the copyright

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • Copyright (c) 2026 MSR Software GmbH

@oberlehner

Copy link
Copy Markdown
Member

Instead of resolving cycles, I would report them as errors. A library that requires itself, or libraries that require each other (directly or transitively), should create an error marker whose message says what is wrong and which libraries are involved, e.g.:

  • Library test10 1.0.0 requires itself (version 2.0.0).
  • Cyclic library dependency: test08 1.0.0 -> test09 1.0.0 -> test08 1.0.0.

Libraries of the cycle should not be linked.

Please attach the marker like the other dependency markers in LibraryMarkerFactory. The current message after 100 visits does not show the cycle or the conflicting requirements, and a cycle with compatible versions (test08/test09) gets no marker at all.

None of the standard libraries in data/typelibrary has a cycle, so existing projects are not affected.

Please adapt LibraryDependencyCycleTest accordingly: expect an error marker for test08/test09 and for test10, check the message, not only the number of markers, and check that none of these libraries is linked.

@akozhushko

Copy link
Copy Markdown
Author

Thanks for the review. I changed the PR as you suggested: cycles are now reported as errors instead of being resolved. Each cycle gets one error marker on the manifest that names the libraries and versions, and the libraries of a cycle are not linked. LibraryDependencyCycleTest checks the messages for test08/test09 and test10 and that none of them is linked. Graphs without a cycle are resolved as before.

@oberlehner oberlehner added this to the 3.5 milestone Nov 26, 2026
@akozhushko
akozhushko requested a lite review from Copilot November 27, 2026 06:40

Copilot AI 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.

🟡 Changes recommended

Critical unresolved defects can leave dependency resolution incomplete, repeatedly re-enqueue nodes, or loop indefinitely, while additional test, API-versioning, and attribution issues remain.

6 open issues
2 resolved since last review

Review effort: Lite

@akozhushko akozhushko changed the title Terminate dependency resolution on cyclic library dependencies Report cyclic library dependencies as errors Nov 27, 2026
@akozhushko
akozhushko requested a lite review from Copilot November 27, 2026 07:30

Copilot AI 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.

Comment on lines +844 to +846
if (before != null) {
reportUnstable(data, new TreeSet<>(visited.subList(before.intValue(), visited.size())));
return false;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added in ace6135: testLibrariesWhoseVersionsSwitchEachOtherAreReported with test11/test12 in the versions 1.0.0 and 2.0.0. The build ends, the two libraries are reported and not linked, and test01 is still linked.

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2025, 2026 Primetals Technologies Austria GmbH
* Copyright (c) 2025, 2026 Primetals Technologies Austria GmbH, MSR Software GmbH

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The range "2025, 2026" was in the notice before this pull request; this change only adds MSR Software GmbH and a contributor line.

@oberlehner oberlehner linked an issue Nov 27, 2026 that may be closed by this pull request
4 tasks
The fixtures only extract the prepared test archives. A test for the
resolution of library dependencies needs libraries that require each other
in chosen versions, which would need a new archive for every graph.

LibraryTestFixtures.createLibrary builds a library with the given symbolic
name, version and requirements (symbolic name and version range) and
extracts it into the workspace library folder. removeFixtureLibraries
and hasFixtureLibraries take these libraries into account, so a test class
that creates libraries leaves the workspace as it found it.

No test uses it yet.

Signed-off-by: Andrii Kozhushko <kozhushko378@gmail.com>
The dependency resolution never ended for libraries that require each other
(a requires b, b requires a), for a library that requires itself, and for
libraries whose versions select each other without end: the worklist of
buildDependencies never became empty.

Such libraries are now reported as an error marker on the dependencies of the
project manifest and are not resolved or linked, also with the preference to
force load the explicit dependencies. Existing links to them are removed.
Messages: "Cyclic library dependency: a 1.0.0 -> b 1.0.0 -> a 1.0.0.",
"Library a 1.0.0 requires itself (version 2.0.0)." and, for versions that
select each other, "The versions of the libraries a, b could not be resolved
consistently because their requirements depend on each other.". A cycle of
overlapping cycles names the other involved libraries.

How it works:
- After the queue is empty, the requirements of the resolved versions form
  a graph. Its cycles are blocked, but only the cycles that no other cycle
  leads to, so that libraries behind a cycle are not reported as well.
- The queue holds each library once, a library is visited when its range
  or its need changed, and the changed flag is reset when it is visited.
- A repeated state (libraries, requirements and ranges) is looked up only for
  libraries that were visited before. It means that the greedy choice of the
  highest versions oscillates. The libraries of the period that lie on a
  cycle of the requirements seen during the period are blocked, other
  libraries are not affected. The state is only built for repeated visits and
  the recorded states are dropped when something is blocked.
- A dependency that a new version of a library no longer requires is queued,
  so that its own requirements are removed as well, and a library that is not
  needed any more is removed when it is visited.
- A conflict (empty version range) of a blocked library keeps its
  marker. The cause named "Project" is not dropped by a library of that name.
- The resolution checks for cancellation in its loop.

Graphs without a cycle are resolved as before. The resolution is still
greedy: it does not search other versions, so a cycle or an oscillation can
be reported although another choice of versions would avoid it, and a cycle
next to a library that cannot be resolved can stay linked if the resolution
stops early.

LibraryDependencyCycleTest creates the libraries with
LibraryTestFixtures.createLibrary. It covers direct, transitive, overlapping
and self-requiring cycles, cycles behind a cycle, versions that select each
other, a library that is not blocked beside a blocked one, conflicts, the
order of the project requirements, force loading, removal of existing links
and termination of resolutions that ended in an endless loop before. A
timeout and a cancelled build make the tests fail instead of hang.

Related issue: eclipse-4diac#2978.

Signed-off-by: Andrii Kozhushko <kozhushko378@gmail.com>
@akozhushko
akozhushko requested a lite review from Copilot November 28, 2026 12:44

Copilot AI 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.

🔵 Needs a closer look

The stateful dependency-resolver rewrite adds worklists, historical traces, cycle blocking, and asynchronous discovery whose termination and cleanup behavior cannot be fully validated statically, especially without the Eclipse integration and regression suites.

2 open issues
5 resolved since last review

Review effort: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[M2-07] Analyse downloader/import security and verify M2

4 participants