8000 fix(or): seed an or branch whose expression reads an outer variable (#620, v2.x backport) by adityamukho · Pull Request #623 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(or): seed an or branch whose expression reads an outer variable (#620, v2.x backport) - #623

Merged
adityamukho merged 1 commit into
mainfrom
fix/620-or-outer-expr-v2
Oct 18, 2026
Merged

adityamukho merged 1 commit into
mainfrom
fix/620-or-outer-expr-v2

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Backport of #622 (v3) to v2.x, for issue #620: an or / or-join branch whose expression reads a variable only the outer row binds never matched, so the or silently dropped rows, in queries and in rule bodies.

(transact [[:a :n 1] [:b :n 2]])
(query [:find ?v :where [?e :n ?v] (or [(> ?v 1)] [(< ?v 0)])])           ;; was: no rows, now: 2
(query [:find ?v :where [?e :n ?v] (or-join [?v] [(> ?v 1)] [(< ?v 0)])])  ;; was: no rows, now: 2

Fix

branch_outer_reads (executor.rs) finds the variables a branch's expressions, including those in nested branches, read but that the branch never binds through a pattern, a rule invocation or an expression output. A branch with any of these takes a seeded path:

  • for or, the existing path where each incoming row seeds the branches;
  • for or-join, a new per-row path seeded with the row's join variables. v2 had no seeded path for or-join; this one is the same as v3's metadata-read path (Pseudo-attribute metadata depends on plan order #594).

Tests

  • tests/disjunction_test.rs gains 5 tests: the issue's queries, a branch that binds a new variable from an outer one, nested or, or-join, and rule bodies. All 5 failed before the fix and pass with and without --features wasm.
  • Unit test test_branch_outer_reads.
  • cargo test: 1280 passed, 0 failed. cargo clippy -- -D warnings is clean.
  • Codex review (read-only): no findings.

cargo test --features wasm --test disjunction_test has 3 short-circuit test failures that already fail on main and are unrelated.

#620 is a data-integrity issue that stays open until the v2.x patch is published, so this PR carries no closing keyword.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz

…620)

Backport of the v3 fix (#622). apply_or_clauses evaluated plain or /
or-join branches from an empty binding and joined the union back onto
the incoming rows. A branch whose expression reads a variable only the
outer row binds -- [(> ?v 1)] after [?e :n ?v] -- saw it unbound and
matched nothing, so the or dropped rows silently, in queries and in
rule bodies.

branch_outer_reads names the variables a branch's expressions (its own
and its nested branches') read but the branch does not bind by a
pattern, rule invocation or expression output. A branch with any now
takes a seeded path: each incoming row seeds a plain or's branches, and
an or-join's join variables seed its branches per row (a new per-row
path on v2, the one v3 uses for metadata reads).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz
@codecov
codecov Bot commented Oct 18, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit dcbc19e into main Oct 18, 2026
22 checks passed
@adityamukho
adityamukho deleted the fix/620-or-outer-expr-v2 branch October 18, 2026 08:24
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