[CP-SAT] Duplicate timer registration in StartDirectSolver when UserTimer aliases WallTimer
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 85/100
Research direction
Inspect ortools/base/timer.h, ortools/sat/model.h, and the timer registrations in ortools/sat/cp_model_solver.cc, then reproduce the failure with the provided CP-SAT Python example using two workers and direct solve enabled. Confirm that duplicate WallTimer/UserTimer registration violates the singleton invariant, apply the minimal conditional registration fix, and add or run a regression test confirming the solver returns OPTIMAL with objective value 1.
Written by the indexing model from the issue text.
Description
Version / Commit
OR-Tools commit bf6d356392ad4230ae55230a2256407aa0de84a8.
The same issue is present on the public main branch as inspected on November 29, 2026.
Root Cause
DefaultCpModelSolver::StartDirectSolver() registers both WallTimer and UserTimer in the same model.
However, ortools/base/timer.h:65 defines:
typedef WallTimer UserTimer;
Consequently, both registrations use the same C++ type ID, violating the singleton invariant in Model::Register().
Affected locations:
ortools/base/timer.h:65ortools/sat/cp_model_solver.cc:3965–3966ortools/sat/model.h:195–199
Proposed Minimal Reproduction
from ortools.sat.python import cp_model
model = cp_model.CpModel()
x = model.new_bool_var("x")
model.maximize(x)
solver = cp_model.CpSolver()
solver.parameters.num_workers = 2
solver.parameters.cp_model_presolve = True
solver.parameters.cp_model_direct_solve = True
solver.parameters.log_search_progress = True
print(solver.solve(model))
Expected Behavior
The solver returns OPTIMAL with objective value 1.
Predicted Failure
CHECK(!singletons_.contains(type_id))
The conflicting registrations have been verified by source inspection. The minimal reproducer has not yet been executed on a pristine upstream build.
Suggested Fix
- direct_solver_model_->Register<UserTimer>(model_->GetOrCreate<UserTimer>());
+ if constexpr (!std::is_same_v<WallTimer, UserTimer>) {
+ direct_solver_model_->Register<UserTimer>(
+ model_->GetOrCreate<UserTimer>());
+ }
The source file already includes <type_traits>.
This preserves compatibility if UserTimer becomes a distinct type in the future.
A regression test exercising direct solve with at least two workers is recommended. The proposed patch has not yet been build-tested.
- Dominant language
- C++
- Stars
- 14.5k
- Forks
- 2.6k
- Avg merge
- 9h 43m
- Merged PRs (30d)
- 53
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/or-tools
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
Maintainers usually reply within 1 day
-
CP-SAT: TimeTableEdgeFinding can report false INFEASIBLE for large cumulative scheduling modelsPossibly taken @lperron claimed this today. OpenBug Solver: CP-SAT Solver
google/or-tools#5672 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Python (v10.0-rc.1): Model.restore_assignment() and Assignment.objective() take ownership of C++-owned objects (segfault)Possibly taken @Mizux claimed this today. OpenLang: Python Solver: Routing & CP Solver
google/or-tools#5670 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
Similar issues
-
c++ easy first-contributor first-contributors good first issue help wanted up-for-grabs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
fork-commit-merge/fork-commit-merge#8709 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
ClickHouse/clickhouse-odbc#680 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ionut-mihalache/aqua#31 · 1 comment ·