Repository navigation
Description
For a rule run someone has to audit later, the claim we want to be able to make is "these rules, as of the rules ledger's t = R, over this data as of t = D", and be able to re-run it and get the same answer. Keeping the rules in their own ledger is the natural layout for that (rules get their own history, approvals and access), but on current main (55ecf81da) a cross-ledger f:rulesSource can't be pinned, and it drops f:sparql rules without saying so. I had Claude go through what's supported today and repro the two problems on the v4.2.6 CLI (the cross-ledger code hasn't changed since).
What pins today
| Where the rules live | Pinned with a @t: data query? |
|---|---|
The data ledger's own default graph, or a local f:rulesSource graph |
Yes. load_rule_set reads the rules graph at the query's t (fluree-db-query/src/datalog_rules/execute.rs:76-85) |
Query-time rules |
The caller supplies the text, so yes, but they're admin-only: under a non-root view policy they're stripped with a tracing::debug! and nothing in the response (fluree-db-api/src/view/query.rs:1786-1796) |
Another ledger, via f:rulesSource + f:ledger |
No. The rules ledger resolves at its head for the request (fluree-db-api/src/cross_ledger/resolver.rs:144-157), and f:atT is refused as Phase 3 (resolver.rs:81-87, docs/security/cross-ledger-policy.md:609-616) |
So the only pinned two-ledger setup today is a runner that reads the rule text out of the rules ledger at @t:R itself and passes it as query-time rules against data@t:D, as root.
The silent part: cross-ledger f:sparql rules
materialize_rules keeps only FlakeValue::Json values of f:rule (fluree-db-api/src/cross_ledger/rules_materializer.rs:91-98, and the module doc at :12-15 says it mirrors the local extractor). The local extractor has since learned f:sparql and refuses any other datatype by name (fluree-db-query/src/datalog_rules/mod.rs:250-281), so the two have drifted: the same SPARQL rule runs when stored in the data ledger and disappears when stored in a rules ledger. The cross-ledger docs (cross-ledger-policy.md:602-607) say a bad cross-ledger rule fails the query because "silently weakening the configured reasoning model is the worst failure mode", which I agree with, and which is what this does.
Repro
Data ledger d2: ex:alice ex:score 5, ex:bob ex:score 50, both ex:Account. Its #config points f:rulesSource at graph ex:rules of ledger rules:main (the TriG from cross-ledger-policy.md:576-590). The rules graph holds ex:r1 (@json: score > 10 → ex:Candidate) and ex:r2 (f:sparql: CONSTRUCT { ?a a ex:SparqlCandidate } WHERE { ?a ex:score ?s }).
{"from": "d2:main@t:2", "select": ["?a","?c"], "where": {"@id":"?a","@type":"?c"}, "reasoning": "datalog"}returnsbobasex:Candidate, and noex:SparqlCandidateat all.- Add
ex:r3(@json: score > 1 →ex:Candidate) to the rules ledger. The same query, still pinned atd2:main@t:2, now returnsaliceas a candidate too. - The same
ex:r2stored in a data ledger's own default graph derivesex:SparqlCandidatefor both accounts.
What I think we want, roughly in order
- Cross-ledger
f:sparqlrules travel, or fail. Query-time rules already accept anf:sparql-typed value (fluree-db-query/src/datalog_rules/parse.rs:63-81), so carrying the datatype across the wire may be all it takes; failing the query like a malformed JSON rule would also be fine. This one's small and it's the silent one. - A pinned rules read. Either
f:atTforf:rulesSource(Phase 3), or, perhaps more useful for a runner, a per-query way to name the rules source and itstnext to a pinnedfrom, e.g."rulesFrom": "rules:main@t:12", under the same admin gate query-time rules have. I don't have a strong opinion on which; the second doesn't need a config write per run. - Say what ran. The tracked
reasoningblock (ReasoningTally,fluree-db-core/src/tracking.rs:644-668) carries the evaluation time but not which rules source, at whicht, or a rule-set hash. The cache key already hashes the rule set (rule_set.content_hash(),fluree-db-query/src/execute/reasoning_prep.rs:171-186), so surfacing it (plus the resolvedtof a cross-ledger source, whichresolver.rsalready has ashead.t) would let a caller record "rules@R over data@D" without trusting its own bookkeeping. - More of a question than a suggestion: should stripping query-time rules under a non-root policy be a 4xx (or at least a tracked warning) rather than a debug log? A query that reads a derived predicate just comes back empty today, and nothing tells the caller why.
Happy to talk through any of these, and to split 1 out on its own if that's easier to land.
Activity
aaj3f commentedon Nov 19, 2026
Picking this up. Items 1 and 2 seem unambiguous to me, so they're in progress now and a PR will link back here: cross-ledger
f:sparqlrules will travel (the cross-ledger materializer and the local extractor will share one classifier for anf:rulevalue, so they can't drift again, and a value that's neither@jsonnorf:sparqlfails the query naming the rule, as it does locally), and the trackedreasoningblock will carry the rule set's hash plus, for a cross-ledger source, its ledger and thetit resolved to. Cross-ledger rules also lose their@idon the wire today (they run as_:query_rule_N), so errors and the tally will name them by their IRI.Items 3 and 4 read to me as decisions more than fixes, so I'd like @bplatz's read before anything gets built. Claude laid out the options; pasting its notes, lightly edited:
3. Pinning the rules read. Two shapes, and they aren't mutually exclusive:
f:atTonf:rulesSource(the Phase 3 fieldcross_ledger/resolver.rs:81-87refuses today). The pin lives in D's config, so "this ledger reasons with rules@R" is a config fact with its own history, and every query uses it. The cost is a config write each time the pin moves, plus what Phase 3 always needed: a check that the rules ledger still holdst(so a pin past retention fails rather than quietly reading the head), and the per-request head cache (ResolveCtx::resolved_heads) keyed by(ledger, t)instead of ledger alone. Since policy and schema sources share the resolver, it would land for them too, which is either a feature or scope creep depending on how you look at it.rulesFrom, e.g."rulesFrom": "rules:main@t:12#http://example.org/rules", under the same admin gate query-timeruleshave (an unrestricted view, andf:allowQueryTimeRulesnot turned off). The address grammar already parses that shape (LedgerRef::parse,fluree-db-core/src/dataset_ref.rs), so there's no new syntax to invent, just a new request key (and aPRAGMAfor SPARQL). It would replace the configured rules for that query rather than add to them, which seems like the auditable reading of "these rules, as of R".Claude's recommendation, fwiw, is
rulesFromfirst: it's what a runner needs to re-run "rules@R over data@D" without a config write per run, and once item 2 lands, the tally reports the rules ledger andtan unpinned run used, so any run can be re-run pinned afterwards.f:atTcould follow whenever someone needs the pin to be the ledger's standing configuration.4. Query-time rules that are dropped without a word. Under a non-root policy they're stripped with a
tracing::debug!(view/query.rs:1793-1796, andview/dataset_query.rs:637-643for the history branch), so a query that reads a derived predicate just comes back empty. There's a sibling a few lines above (view/query.rs:1776-1784): when the ledger's config setsf:allowQueryTimeRules falseunder an override control that denies the query,rulesis cleared the same quiet way. Two options:explainalready refuses a restricted view (view/explain.rs:67-71), and the rest of the reasoning surface, which has been moving towards refusing rather than answering from less than was asked for. The risk is a client that sends the sameruleswhatever the identity and is happy to have them ignored; I'd guess that's rare, but I don't actually know.ignored_rulescount on thereasoningblock, say). Non-breaking, but only a tracked request ever sees it.Claude leans towards refusing, at least for the policy case. It changes a response a client could depend on, though, so I'd rather we agree on it before it's built. Happy to talk through any of these.