Skip to content

Fix wrong answers and overflows in set, scheduling, and FlatZinc - #302

Merged
zayenz merged 8 commits into
mainfrom
fix/model-harness-constraint-bugs
Dec 4, 2026
Merged

zayenz merged 8 commits into
mainfrom
fix/model-harness-constraint-bugs

Conversation

@zayenz

@zayenz zayenz commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Fixes seven bugs across set constraints, unary and cumulative scheduling, MiniZinc regular, and trace-view range lists, and bounds the auxiliary set created by set order relations with a set operation. Each fix has a regression test that fails (or triggers ASan/UBSan) on main and passes on this branch.

Fixes

  • Missed solutions in set element with SOT_UNION (variable and constant set arrays) when the selector is also the result, as in roots(x, s, s). The propagator modified the selector before consuming an iterator over the result's lower bound. Tests: Set::Element::Union::Shared and Set::Element::UnionConst::Shared — both fail on main, pass here.
  • Accepted wrong solutions in the integer/set channel with a single set variable (also broke roots when the largest value its image can contain is 0). Bounding x[i] to 0..0 matched the initial cache, so propagate() never included i in y[0]. Test: Set::Channel::Int::Single — fails on main, passes here.
  • Missed failure in unary overload detection (also used for cumulative reduced to unary) when task durations sum past the int limits. OmegaNode and OmegaLambdaNode now accumulate in long long int and clamp when reading back. Test: Int::Unary::LongTaskOverload (three tasks of length 10^9 must end by 2*10^9) — on main the space does not fail and UBSan reports signed overflow in gecode/int/unary/tree.hpp; here it fails as expected and UBSan is clean.
  • Order-dependent pruning in unary not-first/not-last: tasks tied on latest start or completion times were not all pruned, so equivalent spaces with different task storage orders could propagate differently. Test: Int::Unary::TiedNotLast (posts the same tasks in two orders and expects the same bound 12) — fails on main, passes here. The sweep replay Int::Unary::Opt::Fix::0::[4,0,3,3,0,5]::Def+A, which previously reported "different result after re-enable", also passes.
  • No solution instead of false for reified MiniZinc regular (Gecode's mznlib) when an input can take a value outside 1..S. Overriding fzn_regular.mzn to call gecode_regular dropped fzn_regular_is_decomposed = true, so MiniZinc compiled reified regular with a marker-symbol encoding (S+1/S+2) that assumes inputs are in 1..S and ruled out out-of-alphabet values instead of making b false. New gecode/flatzinc/mznlib/fzn_regular_reif.mzn encodes reified regular directly as one native gecode_regular (keeping the propagator instead of falling back to a state-variable decomposition; non-reified regular is unchanged): values outside 1..S map to S+1 (direct if the domain is inside 1..S, a constant-array element constraint for bounded inputs with ub(x) - lb(x) < 1024 to stay domain consistent, otherwise if-then-else), a dead state absorbs S+1 and missing transitions, and a final marker symbol reaches an end state on S+3 (true) from accepting states and S+2 (false) from all other states. Tests: smoke case in .github/ci/flatzinc-tools-smoke.sh (run in CI with MiniZinc 2.10.1; the FlatZinc test framework starts from FlatZinc text and cannot see mznlib) — by hand with MiniZinc 2.11.0, =====UNSATISFIABLE===== on main, regular-x=3 here; all-solutions comparison against a reference implementation over 600 random reified instances (1–3 states, 1–3 symbols, 1–3 inputs, domains reaching outside 1..S) — every sampled instance mismatched without the fix, no mismatches here; unbounded var int inputs and negated regular also give the right answer.
  • Undefined behaviour (signed integer overflow) when posting cumulative with a single task while deciding whether to use the unary propagator; results were not affected in practice. Tests: Int::Cumulative::SingleTask::Typed and Int::Cumulative::SingleTask::Untyped — both pass in Release either way; under UBSan, main reports signed integer overflow: 1 + 2147483647 at gecode/int/cumulative.cpp:70, clean here.
  • Undefined behaviour (uninitialized read) when creating or cloning integer or set trace views: RangeList::copy() read its uninitialized output pointer before overwriting it. Test: existing FlatZinc::Branching::AuxVarClone — under ASan+UBSan, main reports upcast of misaligned address 0xbebebebebebebebe in range-list.hpp, clean here.

Performance

rel(home, x, op, y, r, z) for SRT_LQ, SRT_LT, SRT_GQ, and SRT_GR previously created its auxiliary set variable over the whole set universe; it is now bounded by the operands' upper bounds. Solutions are unchanged. New tests: Set::RelOp::Order::* (16 tests; order relations were not covered for rel with an operation before) — on main they did not finish within 10 minutes and reached 8 GB of memory; here all 16 pass in 0.7 s.

Left out

A FlatZinc parser change that checks the argument count of equality, domain, and on-restart constraints before reading fixed argument positions. On main the constraint posters do not check argument counts either, so guarding only the parser would just move the out-of-range read into the poster. Adding argument-count checks to the posters first is a separate change. Because the parser is unchanged, no regeneration was needed.

Testing

All run on this branch:

  • New tests: each fails (or reports a sanitizer error) on main and passes with its fix, as above.
  • macOS, AppleClang 21, Release: all tests (all tags, including sweeps) of Set::Element (27), Set::Channel (15), Int::Unary (152), Int::Cumulative (5095, includes Cumulatives), Set::RelOp (856), Set::Rel (20), FlatZinc (161), and Int::NoOverlap (17) — all pass.
  • macOS, ASan+UBSan (RelWithDebInfo, halt on error): Set::Element, Set::Channel, Int::Unary, Int::Cumulative, Set::RelOp, and FlatZinc (all tags) — all pass with no report; check suite: 570 tests, all pass with no report.
  • Linux, GCC 15.2, Release: check-standard target (7012 tests) — all pass.
  • Lint and formatting: misc/check.py lint (full tree, clang-tidy 22) exited 0; format-check clean; misc/tidy.py --check passed.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected reified MiniZinc regular constraints when input values fall outside the automaton’s valid range.
    • Improved correctness of set-element, integer/set-channel, and set-ordering constraints.
    • Fixed overflow and task-order issues in unary scheduling propagation and cumulative constraints.
    • Corrected range-list copying behavior.
  • Performance
    • Reduced unnecessary auxiliary set bounds in set-ordering relations.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: MiniZinc regular reification

Layer / File(s) Summary
Reified regular decomposition and test
gecode/flatzinc/mznlib/fzn_regular_reif.mzn, .github/ci/flatzinc-tools-smoke.sh, changelog.in
The reified predicate maps symbols outside 1..S and extends the automaton for the Boolean result. The smoke test checks a satisfying case with x=3 and `b=false.

Unary scheduling

Layer / File(s) Summary
Widened completion-time calculations
gecode/int/unary.hh, gecode/int/task.hh, gecode/int/task/tree.hpp, gecode/int/unary/task.hpp, gecode/int/unary/tree.hpp, test/int/unary.cpp, changelog.in
Unary tree fields and completion-time calculations use long long int; returned completion times are clamped. Tests cover long tasks under basic and advanced propagation.
Grouped not-last bounds
gecode/int/unary/not-first-not-last.hpp, test/int/unary.cpp, changelog.in
The not-last calculations group tasks with equal latest start times. Tests check the result for two posting orders.

Cumulative capacity arithmetic

Layer / File(s) Summary
Widened cumulative usage checks
gecode/int/cumulative.cpp, test/int/cumulative.cpp, changelog.in
Both cumulative overloads widen the minimum-usage sum before comparing it with capacity. Typed and untyped tests post a single task.

RangeList copying

Layer / File(s) Summary
Copy destination handling
gecode/kernel/range-list.hpp, changelog.in
RangeList::copy assigns the newly built ranges without linking the previous destination list to the sentinel. Its documentation states that the previous destination value is ignored.

Integer-to-set channel

Layer / File(s) Summary
Assigned-value inclusion and regression test
gecode/set/channel/int.hpp, test/set/channel.cpp, changelog.in
When an integer view is assigned, ChannelInt::post includes its index in the corresponding set. A single-set test covers this case.

Set-union element propagation

Layer / File(s) Summary
Aliased selector and result handling
gecode/set/element/union.hpp, gecode/set/element/unionConst.hpp, test/set/element.cpp, changelog.in
The propagators revise backward updates and check candidate membership before modifying the selector-result variable. Tests cover variable and constant set arrays with a shared selector and result.

Set-operation order relations

Layer / File(s) Summary
Bounded temporary set and relation tests
gecode/set/rel-op/post.hpp, test/set/rel-op.cpp, changelog.in
Order-relation posting derives the temporary set's upper bound from the operation and operands. Tests cover the set operations and four order relations.

Change: Bug fix

Merge Risk: Minimal · up to 71ef3

This change fixes several wrong-answer and overflow bugs in set, scheduling, and MiniZinc handling. Each fix has a regression test and a changelog entry. No remaining merge-blocking risk was identified.

Security architecture risk: Minimal · up to 71ef3

Reified MiniZinc regular can now report false for an out-of-alphabet value instead of ruling that value out. The scheduling fix keeps the existing constraint entrypoints. Consumers that directly use Gecode’s low-level scheduling headers should check source compatibility and rebuild against matching headers. The reviewed changes establish no new security exposure or failure-containment regression.

Security review details

Security Blast Radius

  • observed — The two routed unary header ranges change fields on existing scheduling tree nodes, not model submission or constraint posting signatures. The MiniZinc override changes what models using reified regular send to the existing FlatZinc registry.

Dependencies

  • observed — The new override depends on the existing six-argument gecode_regular contract. It supplies a flattened transition table, and the existing FlatZinc adapter reads that table in row order to construct a DFA. The adapter relies on the caller to supply a table matching the declared dimensions.

Data and control flow

  • observed — For a nonempty sequence, the reified override maps out-of-alphabet values to a dead-state symbol and appends a symbol encoding the result Boolean. The terminal transition enforces agreement between that Boolean and the automaton’s acceptance.

Resilience and Maintainability Implications

  • observed — Unary scheduling preserves wide completion-time values for overload detection. The integer accessors saturate at Gecode’s infinity sentinels, which lie outside valid task times; callers can compare those results against valid bounds but cannot recover the exact out-of-range sum.
  • observed — A model can now use false from reified regular to handle an out-of-alphabet assignment without that assignment itself making the model infeasible. This is a guarantee about the constraint’s Boolean result, not validation of arbitrary FlatZinc transition tables.
  • observed — Trace-view creation and cloning can copy a range list without an initialized destination pointer. Copy publishes a completed list, or null for empty input, and does not reuse or dispose of old ranges; overwrite remains the separate operation for an existing list.

Rollout and rollback

  • inferred — The override is installed through the existing MiniZinc solver-library directory; it does not introduce an operator permission or a separate enablement step. For downstream code that directly uses the Omega types, keep compiled consumers and headers on matching versions when upgrading or rolling back. Calls that pass two int arguments to plus need an explicit choice of overload and the matching sentinel convention.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 675ca37f-e35b-42e3-8de2-53cdc2ffb463
Commits

Reviewing files that changed from the base of the PR and between cb89bcc and 71ef30d.

Files selected for processing: 3

  • changelog.in
  • gecode/flatzinc/mznlib/fzn_regular_reif.mzn
  • gecode/int/unary.hh

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@zayenz
zayenz force-pushed the fix/model-harness-constraint-bugs branch 2 times, most recently from cb89bcc to 0804038 Compare December 4, 2026 13:59
@zayenz
zayenz changed the base branch from main to fix/flatzinc-shared-value-arrays December 4, 2026 13:59
@zayenz
zayenz changed the base branch from fix/flatzinc-shared-value-arrays to main December 4, 2026 14:10
When the selector and result views alias, the SOT_UNION element
propagators modified the selector before consuming an iterator over the
result's lower bound, which could drop valid solutions (including from
MiniZinc's roots(x, s, s)).

Cache the lower-bound difference before modifying the selector for
variable sets, and check the subset condition before modifying the
selector for constant sets.
Posting ChannelInt bounds every integer variable to 0..ys.size()-1.
With a single set variable that assigns every x[i] to 0, which matches
the initial cache, so propagate() never sees x[i] as modified and never
includes i in y[0]. This let the channel accept invalid solutions and
broke MiniZinc's roots when the largest image value is 0.

Include i in ys[xs[i].val()] at posting whenever xs[i] is already
assigned.
OmegaNode and OmegaLambdaNode summed task processing and earliest
completion times in int. When task durations summed beyond the integer
limits, the sum overflowed and unary overload detection (also used for
cumulative constraints reduced to unary) missed the overload.

Store processing and completion times in long long int, clamp completion
times to [-Limits::infinity, Limits::infinity] when reading from the
trees, and subtract in long long int when updating task start bounds.
not_last() reset j to -1 on every iteration of the outer loop, so among
tasks with equal latest completion or start times only the first in
storage order received the tighter bound. Because not_first_not_last()
runs not_last() forward and backward, propagation could differ between
equivalent spaces with different task orders.

Keep j across iterations and insert tasks with equal latest start time
together, following Vilím's algorithm, in a shared not_last_bounds()
helper used by both mandatory and optional tasks.
Gecode's fzn_regular.mzn overrides MiniZinc's standard definition to
call the native gecode_regular propagator. Because that drops
fzn_regular_is_decomposed = true, MiniZinc compiled reified regular
(b <-> regular(...)) into a plain regular over a larger automaton with
a final marker symbol for b (S+1 for false, S+2 for true). That
encoding assumes every input is in 1..S; values outside 1..S either
collided with a marker symbol or lay outside the alphabet, so valid
assignments with b = false were ruled out (for instance, x in 2..3,
S = 2, not regular([x], ...) reported unsatisfiable instead of x = 3).

Add gecode/flatzinc/mznlib/fzn_regular_reif.mzn to encode reified
regular directly as a single gecode_regular call instead of falling
back to a decomposition with auxiliary state variables. Non-reified
regular is unchanged.

Each input x is mapped to 1..S+1, keeping values in 1..S and sending
all other values to S+1:
- inputs whose domain is inside 1..S are passed directly;
- bounded inputs with ub(x) - lb(x) < 1024 map through an element
  constraint on a constant array (domain consistent);
- remaining inputs use an if-then-else expression.

The extended automaton adds a dead state (reached on S+1 and on every
missing transition) and an end state. A final marker symbol carries b:
from accepting states only S+3 (true) reaches the end state, and from
all other states (including the dead state) only S+2 (false) does.
When posting cumulative, Gecode checks whether the two smallest task
usages exceed the capacity so it can reduce to unary. With a single
task, the second-smallest usage stays INT_MAX, so min_u + min_u2
overflowed signed int when min_u was positive.

Sum in long long int to avoid signed overflow; a single task now takes
the unary branch.
RangeList::copy() stored the incoming value of its output pointer r in
its sentinel before overwriting it. Integer and set trace views pass an
uninitialized RangeList* when created or cloned, so that dead store read
uninitialized memory. Remove the dead sentinel.next(r) call.
For the order relations SRT_LQ, SRT_LT, SRT_GQ, and SRT_GR,
rel(home, x, op, y, r, z) created its auxiliary set variable for x op y
over the full set universe. Because the set order propagator walks every
value of the upper bound, posting these relations was extremely slow and
memory-intensive.

Bound the auxiliary set by the union of lub(x) and lub(y) for SOT_UNION
and SOT_DISJOINT_UNION, their intersection for SOT_INTERSECTION, and
lub(x) for SOT_MINUS.
@zayenz
zayenz force-pushed the fix/model-harness-constraint-bugs branch from 0804038 to 71ef30d Compare December 4, 2026 14:12
@zayenz
zayenz merged commit 4c36baf into main Dec 4, 2026
5 checks passed
zayenz added a commit that referenced this pull request Dec 5, 2026
Gecode 6.6.2 was released on 5 December from release/6.6.2. Its fixes came from PRs #305, #304, and #302, whose changelog entries already end the 7.0.0 section directly above 6.6.1. Insert the 6.6.2 release header above them, so that they move into 6.6.2. The 6.6-only Boost.Interval entry has no counterpart on main.

The set order relation entry now names SRT_LE, as in the released 6.6.2 changelog: 6.6 has no SRT_LT, which main introduced in 7.0.0.
zayenz added a commit that referenced this pull request Dec 5, 2026
Gecode 6.6.2 was released on 5 December from release/6.6.2. Its fixes came from PRs #305, #304, and #302, whose changelog entries already end the 7.0.0 section directly above 6.6.1. Insert the 6.6.2 release header above them, so that they move into 6.6.2. The 6.6-only Boost.Interval entry has no counterpart on main.

The set order relation entry now names SRT_LE, as in the released 6.6.2 changelog: 6.6 has no SRT_LT, which main introduced in 7.0.0.
zayenz added a commit that referenced this pull request Dec 5, 2026
Gecode 6.6.2 was released on 5 December from release/6.6.2. Its fixes came from PRs #305, #304, and #302, whose changelog entries already end the 7.0.0 section directly above 6.6.1. Insert the 6.6.2 release header above them, so that they move into 6.6.2. The 6.6-only Boost.Interval entry has no counterpart on main.

The set order relation entry now names SRT_LE, as in the released 6.6.2 changelog: 6.6 has no SRT_LT, which main introduced in 7.0.0.
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.

1 participant