Repository navigation
fix(magic-sets): fix fb adornment encoding — silent empty results and recursive binding (#297, #298) - #300
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Sep 26, 2026
adityamukho
added a commit
that referenced
this pull request
Sep 26, 2026
…#297) (#409) A recursive rule whose intermediate variable is bound by a call to another user rule, e.g. (chain ?x ?y) :- (link ?x ?mid) (chain ?mid ?y), failed with "Unbound variable in rule head: ?mid" (INT-022) when queried with a literal first argument such as (chain :a ?y). build_propagation_rules built the magic rule for the recursive call from the guard plus only the non-RuleInvocation clauses preceding it, so it emitted (__magic_chain_bf ?mid) :- (__magic_chain_bf ?x) with ?mid unbound. #300 fixed only the case where a fact pattern binds the intermediate. Keep every preceding clause, including rule invocations, as standard magic-sets rewriting does. All rewritten rules are positive, so the added dependency on the (guarded) called predicate is safe. Adds integration tests for the reopened repro and a left-recursive variant, and a unit test pinning the propagation-rule body. Claude-Session: https://claude.ai/code/session_01BedF9ZmqVZLkvDwn91fuKy 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.
Summary
Fixes two v1.2.0 regressions in magic sets rewriting (
src/query/datalog/magic_sets.rs):(reports-to ?emp :alice)returned empty results when the bound argument was a keyword in value position. Root cause:build_seed_factsusedUuid::new_v4()as the seed entity, and the 1-arg guard bound the variable to the random UUID (entity position) instead of the keyword value (value position).(reach :a ?y)with intermediate variable?midwas unable to be reproduced via test before or after the fix (thebfpath it exercises was already correct). Closing as no-repro / misdiagnosis.Fix — sentinel entity + 2-arg guard for
fbadornments:sentinel_entity(magic_attr)helper — deterministicUuid::new_v5(OID, magic_attr), unique per magic predicate, stable across runs.build_seed_factsfb branch: sentinel replacesUuid::new_v4(); keyword stays in value position.inject_magic_guardfb branch: emits 2-arg guard[Uuid(sentinel), bound_var]— variable now binds from value position, preservingKeywordtype.build_propagation_rulesfb branch: mirrors Phase 1 & 2 Complete: Minigraf embedded graph database with persistent storage #3 for guard; sentinel in propagation rule head so derived facts land in value position.bfpath is untouched.Test plan
test_value_position_keyword_binding— integration test for bug: literal keyword bound in rule call resolves as entity UUID, silently mismatches keyword values in rule body #298; was failing before fix, passes aftertest_recursive_intermediate_variable_with_keyword_entity— regression guard for bug: magic sets rewriting rejects intermediate variables when first rule arg is bound by literal keyword #297 scenariotest_fb_seed_uses_sentinel_entity— unit: sentinel is deterministic (same UUID on two calls)test_fb_guard_is_two_arg— unit: guard args are[Uuid, Symbol]forfbadornmenttest_fb_sentinel_matches_seed— unit: sentinel UUID in guard equals entity UUID in seed fact🤖 Generated with Claude Code