8000 A pseudo-attribute in a rule body reads the rule evaluator's copy of the fact · Issue #661 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

A pseudo-attribute in a rule body reads the rule evaluator's copy of the fact #661

Closed

Description

@adityamukho

Summary

A per-fact pseudo-attribute (:db/valid-from, :db/valid-to, :db/tx-count, :db/tx-id) in the body of a rule without not / not-join / or / or-join returns the metadata of the rule evaluator's working copy of the fact, not the stored fact:

(transact {:valid-from "2020-01-01T00:00:00Z" :valid-to "2021-01-01T00:00:00Z"} [[:a :edge :b]])
(rule [(vf ?x ?vf) [?x :edge ?y] [?x :db/valid-from ?vf]])
(rule [(vt ?x ?vt) [?x :edge ?y] [?x :db/valid-to ?vt]])
(query [:find ?x ?vf :valid-at :any-valid-time :where (vf ?x ?vf)])   ; the evaluation time, not 1577836800000
(query [:find ?x ?vt :valid-at :any-valid-time :where (vt ?x ?vt)])   ; 9223372036854775807, not 1609459200000

The same pattern outside a rule ([?x :edge ?y] [?x :db/valid-from ?vf]) returns the stored values. A rule with a not (or another mixed clause) in its body also returns the stored values.

  • Affected: every release from v0.15.0 (temporal metadata bindings) through v2.0.8, and v3.
  • Cause: RecursiveEvaluator::evaluate_recursive_rules copies the base facts into a new FactStorage with transact, one fact per call, so every copy gets a new tx_id and tx_count, valid_from = the evaluation time and valid_to = forever. Positive rule bodies are matched against that copy. StratifiedEvaluator's mixed-rule pass matches against load_fact copies, which keep the metadata.
  • Workaround: put the pseudo-attribute in the query body instead of a rule body, or add a mixed clause that never excludes a row.

Fix

Rule bodies read the stored fact's metadata, on v3 (as part of moving rule queries to the streaming engine, #548, with an executor fix so the oracle agrees) and on main for a v2.0.x patch.

Activity

  1. added this to the v3.0.0 milestone on Oct 20, 2026
  2. added
    bugSomething isn't working
    known-issueBug present in a published release and not yet fixed in one; listed in the pinned known-issues issue
    on Oct 20, 2026
  3. adityamukho commented on Oct 20, 2026

    @adityamukho
    CollaboratorAuthor

    Fixed on main by #666 (squash); v3 fix in #665. Stays open until the v2.0.x patch is released.

  4. added a commit that references this issue on Oct 20, 2026
  5. adityamukho commented on Oct 20, 2026

    @adityamukho
    CollaboratorAuthor

    v3 fix merged in #665. Stays open until the v2.0.x patch with #666 is released.

  6. added a commit that references this issue on Oct 21, 2026
  7. removed
    known-issueBug present in a published release and not yet fixed in one; listed in the pinned known-issues issue
    on Oct 21, 2026
  8. adityamukho commented on Oct 21, 2026

    @adityamukho
    CollaboratorAuthor

    Fixed in v2.0.9 (released 2026-10-21, on crates.io) and in v3.0.0. Listed under "Fixed in v2.0.9" in #421.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdata-integrityData integrity issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0