GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [MRESOLVER-2076] Fix auto conflict resolver selection by jiteshkhatri11 · Pull Request #2132 · apache/maven-resolver

Conversation

@jiteshkhatri11

@jiteshkhatri11 jiteshkhatri11 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the auto conflict resolver configuration so that it selects the appropriate conflict resolver implementation based on the dependency graph size and available memory.

Previously, auto unconditionally delegated to ClassicConflictResolver.

The implementation now:

  • Selects PathConflictResolver when the dependency graph fits within the estimated memory threshold.
  • Falls back to ClassicConflictResolver for larger graphs.
  • Ensures conflict IDs are available before making the selection.
  • Keeps explicit classic and path configurations unchanged.

Testing

  • mvn -pl maven-resolver-util -Dtest=ConflictResolverTest test
  • mvn -pl maven-resolver-util -am test
  • mvn -pl maven-resolver-util -DskipTests spotless:check
  • git diff --check

All tests passed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cstamas
cstamas requested review from cstamas and gnodet September 8, 2026 14:47
gnodet
gnodet requested changes Sep 8, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Review Summary

This PR re-introduces the auto-selection heuristic for PathConflictResolver vs ClassicConflictResolver that was intentionally removed in cf2eaeff (PR #1942) by @cstamas ~2.5 months ago. That commit's message says:

Put PCR aside for now (#1942) — It's proven a bit problematic, and memory hungry, while the promise of O(N) over O(N^2) is cool.

The original auto-selection logic was introduced in d331083b (PR #1938) with comprehensive tests (5 new test cases), memory optimizations to PathConflictResolver, and extensive benchmarking. This PR re-introduces a subset of that logic — just the selectConflictResolver and treeExceedsThreshold methods — without the accompanying PathConflictResolver memory optimizations from #1938, and without any tests.

Before re-enabling auto-selection, the underlying PathConflictResolver issues that motivated the revert need to be resolved first. The PR description doesn't reference the revert or explain what has changed to make PCR safe to auto-select again.

See inline comments for specific code issues.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java Outdated
Comment on lines +283 to +285
if (context.get(TransformationContextKeys.CONFLICT_IDS) == null) {
new ConflictIdSorter().transformGraph(node, context);
}

@gnodet gnodet Sep 8, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🔴 Bug: wrong context key checked. This checks CONFLICT_IDS (set by ConflictMarker) but should check SORTED_CONFLICT_IDS (set by ConflictIdSorter). The original code in PR #1938 correctly checked SORTED_CONFLICT_IDS.

As written, if ConflictMarker has already run (populating CONFLICT_IDS) but ConflictIdSorter hasn't, this guard passes and the sorter never runs. In practice both delegate resolvers (ClassicConflictResolver line 119-124 and PathConflictResolver line 141-146) independently check for SORTED_CONFLICT_IDS and call ConflictIdSorter themselves, so this doesn't cause a runtime failure — but it makes this block dead code that never triggers when it should.

Suggested change
if (context.get(TransformationContextKeys.CONFLICT_IDS) == null) {
new ConflictIdSorter().transformGraph(node, context);
}
if (context.get(TransformationContextKeys.SORTED_CONFLICT_IDS) == null) {
new ConflictIdSorter().transformGraph(node, context);
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java
Comment on lines +287 to +288
Runtime rt = Runtime.getRuntime();
long available = rt.maxMemory() - (rt.totalMemory() - rt.freeMemory());

@gnodet gnodet Sep 8, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

⚠️ Unreliable heap measurement. Runtime.freeMemory() reflects the free space in the currently allocated heap, not total available memory. Its value fluctuates wildly depending on whether GC has recently run, allocation pressure from other threads, and JVM ergonomics.

This means the same dependency graph can get PathConflictResolver on one build and ClassicConflictResolver on the next, producing non-deterministic behavior — a property Maven users don't expect from dependency resolution. The original PR #1938 had this same issue but was accepted as a pragmatic trade-off alongside extensive benchmarking and the PathConflictResolver memory optimizations. Without those optimizations, the risk is higher.

Consider requesting a GC before measurement (System.gc() — advisory but common for memory heuristics), or using a fixed configurable threshold instead of runtime measurement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java
Comment on lines +275 to +302
/**
* Automatically selects the conflict resolver based on the estimated memory requirements.
* PathConflictResolver is used for dependency trees that fit within the memory threshold,
* while ClassicConflictResolver is used for larger trees.
*/
private ConflictResolver selectConflictResolver(DependencyNode node, DependencyGraphTransformationContext context)
throws RepositoryException {

if (context.get(TransformationContextKeys.CONFLICT_IDS) == null) {
new ConflictIdSorter().transformGraph(node, context);
}

Runtime rt = Runtime.getRuntime();
long available = rt.maxMemory() - (rt.totalMemory() - rt.freeMemory());

// Estimate the maximum number of Path tree nodes that would fit in 25% of available heap.
// Each Path object costs ~200 bytes (object header + fields + children list entry).
int maxPathNodes = (int) Math.min(available / (4L * 200), Integer.MAX_VALUE);

// Walk the dependency tree to count total nodes (including diamond-expanded duplicates).
// The Path tree mirrors this structure, so the count directly reflects Path tree size.
// Use early-exit: stop counting once we exceed the threshold.
if (treeExceedsThreshold(node, maxPathNodes)) {
return new ClassicConflictResolver(versionSelector, scopeSelector, optionalitySelector, scopeDeriver);
} else {
return new PathConflictResolver(versionSelector, scopeSelector, optionalitySelector, scopeDeriver);
}
}

@gnodet gnodet Sep 8, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

⚠️ Missing tests. The original PR #1938 that introduced this logic included 5 test cases covering: auto mode selection, explicit path/classic config dispatch, unknown config rejection, and default config behavior. This PR re-introduces the production code without any tests.

Given this code was removed for stability reasons, re-introducing it without tests — especially for the memory threshold heuristic and the fallback behavior — is risky. At minimum, tests should verify:

  1. auto selects PathConflictResolver for small graphs
  2. auto selects ClassicConflictResolver for large graphs
  3. Explicit path and classic configs are unaffected
  4. The tree-walking threshold check terminates early

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java
Comment on lines 121 to 122
* The name of the conflict resolver implementation to use: "auto" (default), "path", or "classic" (same as Maven 3).
* <p>

@gnodet gnodet Sep 8, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

💡 Javadoc update is premature. The class-level Javadoc (lines 46-53) still says PathConflictResolver is "Not yet recommended for production" and advises "All projects: Use ClassicConflictResolver for optimal correctness." This Javadoc update claims auto mode intelligently selects the right one, but the class-level docs discourage using PCR at all. Either the class-level docs should be updated to match, or this Javadoc should stay conservative.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jiteshkhatri11

jiteshkhatri11 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@gnodet Thanks for the detailed review. I went through the concerns, especially the relationship between #1938 and #1942.

I agree that the current implementation needs to address the previous PathConflictResolver memory/safety concerns before re-enabling automatic selection.

I'll first fix the SORTED_CONFLICT_IDS check and add the missing tests for auto selection, explicit resolver configurations, and threshold/fallback behavior.

I'll also review #1938 and #1942 to make sure the auto-selection logic is reintroduced together with the necessary safeguards.

Thanks again for pointing this out.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cstamas

cstamas commented Sep 26, 2026

Copy link
Copy Markdown
Member

@jiteshkhatri11 @gnodet is this needed after #2153 merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jiteshkhatri11 added 3 commits September 27, 2026 12:04
@jiteshkhatri11
Fix auto conflict resolver selection
907d277
@jiteshkhatri11
Fix conflict resolver auto selection
7bcca7c
@jiteshkhatri11
Add missing newline to ConflictResolverTest
7662db0
@jiteshkhatri11
jiteshkhatri11 force-pushed the fix-2076-auto-conflict-resolver branch from 04878d3 to 7662db0 Compare September 27, 2026 07:08
gnodet-bot
gnodet-bot suggested changes Sep 27, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Re-review after new commits (7662db0)

The SORTED_CONFLICT_IDS bug is fixed and a test for treeExceedsThreshold was added — thanks for addressing those.

However, the fundamental concern raised by @cstamas remains: PR #2153 fixed PathConflictResolver's OOM at the source (depth-bounded expansion in gatherCRNodes). This PR's memory heuristic was designed to prevent PathConflictResolver from receiving large graphs it couldn't handle — but that problem no longer exists. Re-introducing auto-selection based on Runtime.freeMemory() adds non-determinism (same graph → different resolver depending on GC state) without a clear benefit now that PathConflictResolver handles dense graphs safely.

Other outstanding issues from the previous review remain unaddressed — see inline comments.

Previous findings status

Finding Status
CONFLICT_IDS → SORTED_CONFLICT_IDS ✅ Addressed
Unreliable heap measurement (Runtime.freeMemory()) ❌ Not addressed
Missing tests (auto-selection coverage) ⚠️ Partially addressed (only threshold utility tested)
Premature Javadoc update (contradicts class-level docs) ❌ Not addressed

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java
Comment on lines +287 to +292
Runtime rt = Runtime.getRuntime();
long available = rt.maxMemory() - (rt.totalMemory() - rt.freeMemory());

// Estimate the maximum number of Path tree nodes that would fit in 25% of available heap.
// Each Path object costs ~200 bytes (object header + fields + children list entry).
int maxPathNodes = (int) Math.min(available / (4L * 200), Integer.MAX_VALUE);

@gnodet-bot gnodet-bot Sep 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

⚠️ Still non-deterministic (not addressed from previous review). Runtime.freeMemory() reflects GC state, allocation pressure from other threads, and JVM ergonomics. The same dependency graph can get PathConflictResolver on one invocation and ClassicConflictResolver on the next.

Moreover, since PR #2153 merged, PathConflictResolver itself uses depth-bounded expansion (IdentityHashMap<DependencyNode, Integer>) to cap Path creation. The OOM that motivated this heuristic is fixed at the source. This entire memory-estimation block is now solving a problem that no longer exists.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java
Comment on lines +294 to +301
// Walk the dependency tree to count total nodes (including diamond-expanded duplicates).
// The Path tree mirrors this structure, so the count directly reflects Path tree size.
// Use early-exit: stop counting once we exceed the threshold.
if (treeExceedsThreshold(node, maxPathNodes)) {
return new ClassicConflictResolver(versionSelector, scopeSelector, optionalitySelector, scopeDeriver);
} else {
return new PathConflictResolver(versionSelector, scopeSelector, optionalitySelector, scopeDeriver);
}

@gnodet-bot gnodet-bot Sep 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

⚠️ Heuristic no longer matches PathConflictResolver behavior. treeExceedsThreshold counts shared nodes multiple times (no visited set), mirroring the old PathConflictResolver expansion. After PR #2153, PathConflictResolver uses depth-bounded expansion and does NOT re-traverse subtrees of nodes already expanded at a shallower depth. The count from treeExceedsThreshold now overestimates PathConflictResolver's actual memory usage, causing unnecessary fallback to ClassicConflictResolver — exactly the situation auto-selection was supposed to avoid.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...-resolver-util/src/main/java/org/eclipse/aether/util/graph/transformer/ConflictResolver.java
Comment on lines +123 to +124
* When set to "auto", the resolver automatically selects the most appropriate implementation based on the
* dependency graph size and available memory.

@gnodet-bot gnodet-bot Sep 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

💡 Javadoc contradiction not addressed (from previous review). This property-level doc claims auto mode "automatically selects the most appropriate implementation," but the class-level Javadoc at lines 47 and 52-53 still says:

  • "PathConflictResolver — Not yet recommended for production"
  • "All projects: Use ClassicConflictResolver for optimal correctness"

These are contradictory. If auto mode can select PathConflictResolver, the class-level docs need updating too — or this Javadoc should stay conservative until the class docs are revised.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...olver-util/src/test/java/org/eclipse/aether/util/graph/transformer/ConflictResolverTest.java
Comment on lines 929 to +932
@ParameterizedTest
@MethodSource("conflictResolverSource")
void denseGraphDoesNotOom(ConflictResolver conflictResolver) throws RepositoryException {
// M=N=K=100: without the fix, creates M*N + M*N*K = 1,010,000 Path objects (~80 MB)
// → OutOfMemoryError on CI. With the fix: O(N+K) = 200 expansions, trivial memory.
int M = 100; // parent modules
int N = 100; // hub modules (shared, each with children)
int K = 100; // sub-hub leaf modules (shared across hubs)
int M = 100;

@gnodet-bot gnodet-bot Sep 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

⚠️ Don't strip documentation comments from existing tests. These comments (added by PR #2153) explain the test structure — e.g., M=N=K=100: without the fix, creates M*N + M*N*K = 1,010,000 Path objects (~80 MB) and the purpose of each node group. Removing them makes the test harder to understand for future contributors. Please revert the comment removals from denseGraphDoesNotOom, autoSelectionResolvesConflictsCorrectly, and defaultConfigUsesAutoSelection.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...olver-util/src/test/java/org/eclipse/aether/util/graph/transformer/ConflictResolverTest.java
Comment on lines +870 to +876
new JavaScopeDeriver());

DependencyNode root = makeDependencyNode("some-group", "root", "1.0");
DependencyNode child = makeDependencyNode("some-group", "child", "1.0");
DependencyNode grandChild = makeDependencyNode("some-group", "grand-child", "1.0");

root.setChildren(mutableList(child));

@gnodet-bot gnodet-bot Sep 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

💡 Reflection-based test is fragile. Using setAccessible(true) to test a private method couples the test to an implementation detail. If the method is renamed, moved, or its signature changes, this test breaks silently at runtime rather than at compile time.

Consider either:

  • Making treeExceedsThreshold package-private (it's a pure utility with no side effects)
  • Testing the behavior through the public API instead (verify that auto config selects the expected resolver for small vs large graphs)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jiteshkhatri11

jiteshkhatri11 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @cstamas. I rebased #2132 onto the current master, including the changes from #2153, and re-ran the ConflictResolverTest suite successfully.

Since #2153 addresses the PathConflictResolver memory issue that was blocking the previous auto-selection approach, I’d like to confirm whether you still want #2132 to reintroduce the automatic selection between PathConflictResolver and ClassicConflictResolver.

If it is no longer needed after #2153, I’m happy to close this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slachiewicz slachiewicz added the bug Something isn't working label Oct 29, 2026
@slachiewicz slachiewicz added the not for merge label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gnodet gnodet gnodet requested changes
@cstamas cstamas Awaiting requested review from cstamas
+1 more reviewer
@gnodet-bot gnodet-bot gnodet-bot requested changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bug Something isn't working not for merge

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@jiteshkhatri11 @cstamas @gnodet @gnodet-bot @slachiewicz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.