Skip to content

chore: Revert "fix: clone the solution before sending it to the consumer"#1648

Merged
triceo merged 5 commits into
TimefoldAI:mainfrom
zepfred:chore/revert-clone
Jun 16, 2025
Merged

chore: Revert "fix: clone the solution before sending it to the consumer"#1648
triceo merged 5 commits into
TimefoldAI:mainfrom
zepfred:chore/revert-clone

Conversation

@zepfred

@zepfred zepfred commented Jun 12, 2025

Copy link
Copy Markdown
Contributor

No description provided.

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.

Pull Request Overview

Revert the previous change that cloned the solution before sending it to consumers, restoring direct use of the solver’s internal instance and updating tests and docs accordingly.

  • Removed the cloning-based test in BestSolutionHolderTest
  • Updated assertions in DefaultConstructionHeuristicPhaseTest to expect the same instance
  • Removed cloneBestSolution() and related cloning calls in core solver classes; updated documentation to warn about in-place mutation

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
BestSolutionHolderTest.java Removed test verifying cloning between phases
DefaultConstructionHeuristicPhaseTest.java Changed assertion to check for same solution instance
SolverScope.java Deleted cloneBestSolution() and inlined cloning call
SolverEventSupport.java Stopped cloning before firing best-solution events
DefaultSolver.java Returned internal best solution instead of a clone
SolverJobBuilder.java Added docs warning consumers not to mutate the solution
Comments suppressed due to low confidence (3)

core/src/main/java/ai/timefold/solver/core/impl/solver/event/SolverEventSupport.java:26

  • [nitpick] Add a Javadoc comment on fireBestSolutionChanged to warn that the solution is no longer cloned and consumers receive the live instance, so they should avoid mutating it.
var event = new DefaultBestSolutionChangedEvent<>(solver, timeMillisSpent, newBestSolution, bestScore);

core/src/main/java/ai/timefold/solver/core/impl/solver/DefaultSolver.java:207

  • [nitpick] Update the method-level Javadoc for the solver’s solve/run method to note that the returned solution is not cloned and is the internal solver instance.
return solverScope.getBestSolution();

core/src/test/java/ai/timefold/solver/core/impl/solver/BestSolutionHolderTest.java:187

  • [nitpick] Introduce a new test that verifies mutations performed in bestSolutionConsumer persist into the final solution, ensuring this no-clone behavior is explicitly covered.
private record RecordedFuture(int id, CompletableFuture<Void> future) {

@triceo triceo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.
Ideally we'd mention this in the docs somewhere. Surely there is a section in there about SolutionManager and consuming the best solution. If not, perhaps it's a good time to add one.

Comment thread core/src/main/java/ai/timefold/solver/core/api/solver/SolverJobBuilder.java Outdated

@triceo triceo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM when docs improved.

Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
Comment thread docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc Outdated
@sonarqubecloud

Copy link
Copy Markdown

@triceo triceo merged commit fe93472 into TimefoldAI:main Jun 16, 2025
42 of 43 checks passed
@zepfred zepfred deleted the chore/revert-clone branch March 10, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants