8000 fix(rules): recursion through a rule with not / not-join / or (#633) by adityamukho · Pull Request #635 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(rules): recursion through a rule with not / not-join / or (#633) - #635

Merged
adityamukho merged 2 commits into
v3from
fix/633-mixed-recursion
Oct 19, 2026
Merged

adityamukho merged 2 commits into
v3from
fix/633-mixed-recursion

Conversation

@adityamukho
@adityamukho adityamu 8000 kho commented Oct 19, 2026 •
Copy link
Copy Markdown
Collaborator

Refs #633 (stays open until the v2.0.x backport ships).

Problem

StratifiedEvaluator::evaluate ran a stratum's positive-only rules to a fixpoint, then each rule with not / not-join / or / or-join once. 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

  • A stratum in which some rule calls a mixed predicate of the same stratum repeats (positive fixpoint, then mixed rules) until the mixed pass derives no new fact. Monotone: every negated predicate is in a lower, complete stratum.
  • The mixed pass now skips heads already in the store (it used to transact every binding's head), which is what lets it detect "nothing new".
  • Bounded: passes by max_iterations, new mixed facts per pass by max_derived_facts, and every fact the rules derive in the evaluation (positive and mixed, across strata and passes) by max_results — all INT-020. Before, max_results was checked per stratum for positive rules only.
  • Strata without such recursion run exactly one pass, as before.

Tests

  • tests/not_join_test.rs: direct recursion through not (10 rows; 8 with :d blocked), mutual recursion through not-join (both predicates), recursion through or.
  • evaluator.rs unit tests: a counter recursing through a not rule reaches its fixpoint; without a guard it ends with INT-020 via max_iterations and via max_results; max_results counts 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

adityamukho and others added 2 commits October 19, 2026 23:41
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
codecov Bot commented Oct 19, 2026
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.67901% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/query/datalog/evaluator.rs 95.67% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit d87dfff into v3 Oct 19, 2026
29 of 30 checks passed
@adityamukho
adityamukho deleted the fix/633-mixed-recursion branch October 19, 2026 19:05
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>
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

0