Repository navigation
fix(rules): recursion through a rule with not / not-join / or (#633) - #635
Merged
Merged
Conversation
StratifiedEvaluator ran each rule with not/not-join/or/or-join once per stratum, after the positive rules' fixpoint, so recursion through such a rule stopped after one step. A stratum whose rules call one of its mixed predicates now repeats (positive fixpoint, then the mixed rules) until the mixed pass derives nothing new. The mixed pass skips heads already in the store, so a repeat can see that, and the loop is bounded by max_iterations, max_derived_facts and max_results (INT-020). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz
Each repeated pass's RecursiveEvaluator saw earlier passes' facts as base facts, so a recursion alternating between positive and mixed rules could derive more than max_results. Count the positive passes' new facts with the mixed rules' in one total for the evaluation. Found by Codex review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 19, 2026
adityamukho
added a commit
that referenced
this pull request
Oct 19, 2026
… (#636) Backport of #635 from v3. StratifiedEvaluator ran each rule with not/not-join/or/or-join once per stratum, after the positive rules' fixpoint, so recursion through such a rule stopped after one step. A stratum whose rules call one of its mixed predicates now repeats until the mixed pass derives nothing new; the mixed pass skips heads already in the store; max_iterations, max_derived_facts and max_results bound the loop (INT-020), with max_results counting every derived fact. The or test reads a variable an entity pattern binds: on v2.x an or branch compares a keyword and a ref exactly (changed on v3 by #546). Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs #633 (stays open until the v2.0.x backport ships).
Problem
StratifiedEvaluator::evaluateran a stratum's positive-only rules to a fixpoint, then each rule withnot/not-join/or/or-joinonce. When recursion passes through such a rule it stays in one stratum (#628 only raises callers off a cycle), so the mixed rule's output never fed back: the chain example in #633 returned 7 of 10 rows, the mutual one 4 of 10.Fix
transactevery binding's head), which is what lets it detect "nothing new".max_iterations, new mixed facts per pass bymax_derived_facts, and every fact the rules derive in the evaluation (positive and mixed, across strata and passes) bymax_results— all INT-020. Before,max_resultswas checked per stratum for positive rules only.Tests
tests/not_join_test.rs: direct recursion throughnot(10 rows; 8 with:dblocked), mutual recursion throughnot-join(both predicates), recursion throughor.evaluator.rsunit tests: a counter recursing through anotrule reaches its fixpoint; without a guard it ends with INT-020 viamax_iterationsand viamax_results;max_resultscounts the positive passes' facts too (found by Codex review).1606 tests (1596 passing, 10 ignored). Docs: CHANGELOG, CLAUDE.md, README, TEST_COVERAGE.
Review with
git diff -w— most of the evaluator diff is re-indentation inside the new loop.🤖 Generated with Claude Code
https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz