8000 fix(rules): a pseudo-attribute in a rule body reads the stored fact (#661) by adityamukho · Pull Request #665 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix(rules): a pseudo-attribute in a rule body reads the stored fact (#661) - #665

Merged
adityamukho merged 2 commits into
v3from
fix/661-rule-pseudo-attrs
Oct 20, 2026
Merged

adityamukho merged 2 commits into
v3from
fix/661-rule-pseudo-attrs

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Fixes the v3 side of #661 (data-integrity, known-issue, listed in #421). No closing keyword: #661 stays open until the v2.0.x patch with the main backport ships.

Cause

RecursiveEvaluator::evaluate_recursive_rules copied the base facts into its working FactStorage with transact, one fact per call: every copy got a new tx-id and tx-count, valid-from = the evaluation time and valid-to = forever. A positive rule body's :db/valid-from, :db/valid-to, :db/tx-count and :db/tx-id read those. The mixed-rule pass (StratifiedEvaluator) already matched against load_fact copies, which keep the metadata.

Fix

Load the base facts as stored (load_facts, then restore_tx_counter so derived facts get later counts).

Tests

tests/recursive_rules_test.rs: for each of the four pseudo-attributes, a positive rule and a recursive rule (later iterations read the base facts again) return the same rows as the pattern in a query body, on a fact with an explicit 2020–2021 valid window and two later transactions. Fails before the fix.

Counts: 1,678 tests (1,668 passing, 10 ignored); the documented counts were stale (see #663, which edits the same lines; whichever merges second combines them).

CHANGELOG: Fixed entry. No docs-site change (the docs never described the wrong values).

Main backport: separate PR next.

🤖 Generated with Claude Code

https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT

…661)

RecursiveEvaluator copied the base facts into its working storage with
transact, one fact per call, so each copy got a new tx-id and tx-count,
valid-from = the evaluation time and valid-to = forever, and a positive
rule body's :db/valid-from, :db/valid-to, :db/tx-count and :db/tx-id read
those. The base facts are now loaded as stored (load_facts), as the
mixed-rule pass already did. Test counts brought up to date (1678 total,
1668 passing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT
…nts combined: 1681 total, 1671 passing)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT
@codecov
codecov Bot commented Oct 20, 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 98af518 into v3 Oct 20, 2026
23 of 24 checks passed
@adityamukho
adityamukho deleted the fix/661-rule-pseudo-attrs branch October 20, 2026 16:45
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