compile_rule built body atoms before compiling the where-condition, so
a column referenced only by the condition (not selected into the head)
compiled to _ in its atom while the condition referenced an unbound
variable: +gold(Name) <- customer(_, Name, _), Tier = "gold". The
engine accepts that rule and silently satisfies the comparison, so the
derived relation matched every row instead of filtering.
Conditions now compile first, registering their columns in the variable
environment before atoms are built:
+gold(Name) <- customer(_, Name, Tier), Tier = "gold".
Found by a live migration demo (a Derived with where(tier == "gold")
returned silver customers). The existing test_with_condition passed
because it never asserted the binding; it now does, plus a regression
test for the condition-only column case. Engine-side acceptance of
unbound comparison variables is filed separately.
What
compile_rule built body atoms before compiling the where-condition. A column referenced only by the condition compiled to _ in its atom while the condition referenced an unbound variable:
The engine accepts that rule and silently satisfies the comparison, so the derived relation matched EVERY customer, silver included. Verified live before the fix; after the fix the clause binds the column and the engine filters correctly:
The fix is an ordering change: conditions compile first, registering their columns in the variable environment before atoms are built. This is the shared compiler, so it affects every Derived rule with a where() on a non-selected column - define_rules and migrations alike.
How it slipped through
test_with_condition asserted the head and the condition string but never that the condition column was bound in the atom. It now does, plus a regression test asserting the exact clause for the condition-only-column case. Full SDK suite: 958 passed.
Found while building a live demo of the migration strategy. The engine-side half (accepting rules with unbound comparison variables and silently satisfying them - a wrong-results landmine of the same family as #91) is filed separately.
Merge order
Independent - no conflicts with #98-#105.