Repository navigation
Fixes 35200: Reject negated EXISTS rules and keep inferred triples out of inferenceLevel=none - #35201
Conversation
FixedPointRuleCheck only rejected E_NotExists, but Jena parses
FILTER(!EXISTS {..}) and FILTER(!(EXISTS {..})) as E_LogicalNot(E_Exists),
so a non-monotone rule passed validation and could make the fixed point
depend on rule order.
EXISTS is now accepted only as a condition the whole FILTER requires (the
filter itself or one of its && conjuncts). That is the one position where
it can only turn true as facts are added; under !, inside IF/COALESCE, in
a comparison or bound by BIND it can flip to false. Allow-listing the
monotone position is stricter than deny-listing E_LogicalNot and also
catches those other wrappers. The pattern inside an accepted EXISTS is now
inspected as well, so MINUS or NOT EXISTS cannot hide inside it.
Stored rules go through the same validator on startup, so existing rules
that negate EXISTS are disabled with the reason recorded.
Two ways a materialization run recorded a failure it had no business recording: Lost lease. When a run found its lease taken over it called recordFailure, and markFailed is an unconditional UPDATE, so it could overwrite the status the run that took over had just written (dirty flag and lastError on a rule that run had materialized cleanly). The lost lease is now a dedicated exception: the run writes nothing to the rule rows and surfaces InferenceRunInProgressException, so the scheduled app ends STOPPED and the REST call returns 409, the same as meeting the lock at start. A dirtyVersion CAS on markFailed would not help here: the takeover run does not bump dirtyVersion. Superseded run. Ongoing writes mark every rule dirty and keep adding facts, so a run can exhaust its 64-pass budget because of the write rate, not the rules. When the budget runs out and any rule's dirtyVersion (or the set of rules) changed since listForRun, the run is treated as superseded: rules are left dirty without a lastError and the run ends with InferenceRunSupersededException (409, app STOPPED). A budget exhausted against unchanged inputs still fails every enabled rule as before.
RdfInferenceApp only checked materializedInferenceEnabled, so with the flag set on a non-Fuseki store (QLever) every scheduled run went on to InferenceMaterializer, which rejects the store as unavailable, and the run ended FAILED each time. It now uses RdfRepository.supportsMaterializedInference, the same predicate the query path and status reporting use, and completes as an empty run.
inferenceRuleStatus.tripleCount and the explanation's tripleCount are declared int64, but jsonschema2pojo generated Integer, so InferenceRuleRepository narrowed the BIGINT lastTripleCount with Math.toIntExact and a rule graph past 2^31-1 triples made every status read throw. Both fields now use existingJavaType java.lang.Long, the convention other int64 schema fields follow, and the narrowing is gone. The TypeScript and Python models are unchanged: they already map int64 to number/int.
refreshLineage loaded the edge's details with .orElse(null), and the loader returned empty both when the edge no longer existed and when it existed with no stored details. A lineage add replayed after the edge was deleted therefore re-added the edge without details, leaving a phantom upstream/downstream edge in the knowledge graph. The loader now returns the stored edge (with possibly null details) or empty when the relationship row is gone. When it is gone, the replay removes the edge, which is idempotent and leaves the graph matching the database whatever order the add and delete replays run in.
Fuseki's tdb2:unionDefaultGraph includes every named graph, the rule
graphs under <baseUri>graph/inferred/ among them, and the NONE path ran
the query unchanged, so none returned the same derived triples as
custom.
While materialized inference is enabled, RdfRepository now runs
asserted-only reads with every non-inferred named graph as the query
dataset: FROM for the default graph and FROM NAMED so GRAPH patterns
cannot reach inferred graphs either. Jena evaluates several FROM graphs
as a distinct union, so property paths that cross graphs and triples
stored in two graphs behave as on the union default graph. A query that
declares its own dataset runs as written.
Alternatives considered:
- An algebra rewrite of default-graph patterns into
GRAPH ?g { } FILTER(!STRSTARTS(STR(?g), prefix)) breaks property paths
that span graphs and returns duplicates for triples held in more than
one graph; fixing that needs per-pattern DISTINCT subqueries that
defeat the optimizer.
- A second Fuseki dataset whose default graph unions only asserted
graphs needs the graph set at assembly time and a deployment change,
and asserted graphs are not a closed set (SPARQL updates and loaders
create graphs).
- A fixed FROM list of the graphs OpenMetadata writes misses graphs
created by SPARQL updates.
Trade-offs: the graph list is read from Fuseki (a quad-index scan) and
cached for 30 seconds in a single-entry Caffeine cache, so a graph
created in that window is missing from none until the refresh; inferred
graphs are never let in. Jena executes a multi-graph FROM dataset
through a read-only union view instead of TDB2's native union default
graph, so none queries cost more than before when inference is enabled.
With materialized inference disabled the query is not rewritten, so
rule graphs left behind must be cleared.
Callers switched to the asserted-only read: the SPARQL endpoint and MCP
tool at none, selectJsonWithoutInference (agent SPARQL; its javadoc no
longer mentions a configured default inference), the complete-lineage
endpoint, the lineage path finder and the RDF insights (centrality,
communities, co-occurrence). Inference explanations, SHACL validation,
semantic search and the MCP describe/tag tools keep reading the union.
A run now also ends with 409 when another run takes it over or when writes keep changing the rules' inputs until it runs out of passes.
… background
SELECT DISTINCT ?g { GRAPH ?g { ?s ?p ?o } } matches every quad in the
store to name its graphs. An empty GRAPH pattern lists the graph names
directly. Refresh the asserted graph list in the background every two
minutes, so a none query never waits on the listing.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
…rule A graph OpenMetadata created, such as an insights graph, stayed out of asserted-only reads until the periodic refresh, and a list read before the first projection stayed empty. Writes through RdfRepository now name the graphs they reach; one missing from the cached list, an update whose targets cannot be read, or a blue/green promotion drops the list so the next read relists. An empty list is never kept. Record the asserted-only dataset rule, the refresh interval and the rejected alternatives.
|
Both findings are addressed in 9465389. Cached graph list hides graphs OM just created. Writes through Decision record.
|
| void graphsWritten(final Collection<String> graphs) { | ||
| final List<String> known = assertedGraphs.getIfPresent(GRAPH_LIST_KEY); | ||
| if (known == null) { | ||
| return; | ||
| } | ||
| final String prefix = inferredGraphPrefix.get(); | ||
| if (graphs.stream().anyMatch(graph -> !graph.startsWith(prefix) && !known.contains(graph))) { | ||
| assertedGraphs.invalidate(GRAPH_LIST_KEY); | ||
| } | ||
| } |
There was a problem hiding this comment.
💡 Bug: graphsWritten skips invalidation while the first graph listing is in flight
graphsWritten returns early when getIfPresent is null, but a synchronous Caffeine LoadingCache also returns null while a load for the key is still running. Here is the race: query thread Q calls assertedGraphs.get, and its loader lists graphs from Fuseki. Meanwhile writer W commits an INSERT into a new graph (an insights graph, say) and calls graphsWritten, which sees null and returns. If Q's listing was read before W's commit, Q's list lacks the new graph, and that list stays cached until the 2-minute refresh. This is the staleness the commit set out to remove, and the ADR says a write by this server naming a missing graph "drops it so the next read relists". Fix: invalidate when known == null as well. invalidate on a key that is still computing waits for the compute and then removes the result, and it is a cheap no-op when nothing is cached.
Invalidate also when the list is absent, which covers an in-flight load:
void graphsWritten(final Collection<String> graphs) {
final List<String> known = assertedGraphs.getIfPresent(GRAPH_LIST_KEY);
final String prefix = inferredGraphPrefix.get();
if (known == null
|| graphs.stream().anyMatch(graph -> !graph.startsWith(prefix) && !known.contains(graph))) {
assertedGraphs.invalidate(GRAPH_LIST_KEY);
}
}
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 2 closed / 3 findings🔴 High risk · Changing RDF inference materialization, graph filtering, and lineage replay could leave derived results or lineage projections inconsistent with stored data. Adds a per-server cache of named graphs so
Resolved this session: the cached graph list no longer hides graphs OM itself just created (e.g. centrality), and the asserted-only dataset rule and 2-minute TTL are now recorded in 💡 Bug: graphsWritten skips invalidation while the first graph listing is in flight📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/AssertedOnlyQueries.java:81-90
Invalidate also when the list is absent, which covers an in-flight load✅ 2 closed✅ Bug: Cached graph list hides graphs OM itself just created, e.g. centrality
✅ Quality: Asserted-only dataset rule and 2-minute TTL are not recorded in docs/decisions
🤖 Prompt for agentsOptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
…ackport 2.0 #37069) (#37177) * Fixes #36671: Live RDF entity writes send only the changed triples (backport 2.0 #37069) Backport of #37069, adapted to 2.0: - 2.0 has no InferenceInvalidatingRdfStorage or AssertedGraphTrackingRdfStorage (main-only, from #28042 and #35201), so their changes and tests are left out. - 2.0 does not project table columns as resources, so RdfPropertyMapper keeps only the named list cells, and the two tests that relied on column triples use extension properties or the 2.0 counts instead. - The new tests use 2.0's JsonLdTranslator constructor and JenaFusekiStorage.isTimeoutError, now package-private for the circuit-breaker test. - The ADR and the production setup guide drop the inference statements that do not apply. (cherry picked from commit d811bd7) * Run RdfEntityDiffWriteIT on 2.0: add FusekiTestImage, wide table in custom properties 2.0 has no FusekiTestImage and does not project a table's columns, so the wide-table test changes a table tag on a table with 200 custom properties. * Benchmark 2.0 with tables wide in custom properties 2.0 does not project a table's columns, so the disk-growth harness builds tables with 300 custom properties and changes one per write instead of moving a column tag. The decision record gains the 2.0 measurement.



Describe your changes:
Fixes #35200
Follow-up to phase 0 (#34963, #34970) of
docs/plans/2026-10-07-fuseki-native-reasoning.md. Fixes defects found reviewing the merged inference work: a validator gap,inferenceLevel=nonereturning inferred triples, rule status written by runs that no longer own the result, phantom lineage edges, scheduled runs on stores that cannot materialize, and an int overflow.Type of change:
High-level design:
FixedPointRuleCheck). EXISTS is accepted only where the whole FILTER requires it: the filter itself or one of its&&conjuncts, the only position where it can only turn true as facts are added. This also catchesIF,COALESCE, comparisons andBIND, not just!, and the pattern inside an accepted EXISTS is now checked too (FILTER EXISTS { … MINUS … }used to pass). Stored rules are revalidated on startup, so existing negated rules get disabled with the reason.inferenceLevel=nonereads asserted data only. While materialized inference is enabled,RdfRepository.executeAssertedSparqlQuery(AssertedOnlyQueries) names every graph outside<baseUri>graph/inferred/asFROMandFROM NAMED. Jena evaluates severalFROMgraphs as a de-duplicating union, so property paths across graphs behave as on the union default graph, andFROM NAMEDkeepsGRAPHpatterns away from rule graphs. A query that declares its own dataset runs as written. The graph list is read withGRAPH ?g {}(graph names from the index, not a scan of every quad) and refreshed in the background every two minutes.nonepath of/v1/rdf/sparqland the MCP SPARQL tool,selectJsonWithoutInference(agent SPARQL), complete lineage,LineagePathFinder, and the centrality, community and co-occurrence insights.GRAPH ?gwith a filter breaks cross-graph property paths and returns duplicates; a second Fuseki dataset needs a deployment change; a fixed list of OM's graphs misses graphs created by SPARQL updates.nonequeries use Jena's union view instead of TDB2's native union. Disabling inference does not clear rule graphs (documented).409, scheduled runSTOPPED). AdirtyVersionguard onmarkFailedwould not work, since the run that took over does not bump it.dirtyVersion, or the rule set, changed since the run started, the run is superseded: rules stay dirty with nolastError,409/STOPPED. Unchanged inputs still fail every enabled rule as before.refreshLineageremoves a deleted edge instead of re-adding it.RdfInferenceAppchecksRdfRepository.supportsMaterializedInference(config), so a QLever store completes an empty run instead of failing every five minutes.Long(existingJavaType: java.lang.LongoninferenceRuleStatus.tripleCountand the explanation schema), droppingMath.toIntExact. TS and Python models are unchanged.Docs:
rdf-production-setup.md(inference levels, lease loss, superseded runs) andrdf-ontology-contract.md.Tests:
Use cases covered
!EXISTS,!(EXISTS),IF,BINDandMINUSinsideEXISTSare rejected; a stored negated rule is disabled with its reason.domain-membership-inheritance, the inheritedom:belongsToDomaintriple is visible atcustomand not atnone, while the asserted triple is visible atnone.Unit tests
InferenceRuleValidatorTest,InferenceMaterializerTest,InferenceRuleRepositoryTest,AssertedOnlyQueriesTest(7 cases through Jena's dataset handling),RdfLiveWriteTest, newRdfInferenceAppTest. All oforg.openmetadata.service.rdf.**plusRdfResourceTestand theOntologyReasoningResourcetests: 1055 run, 0 failures;SparqlQueryToolTest12, 0 failures. Each new unit test fails before its fix.Backend integration tests
RdfInferenceMaterializationIT(inferenceLevelNoneLeavesOutMaterializedConclusions),RdfInferenceMultiServerIT(lease takeover).RdfResourceIT,RdfInferenceMultiServerIT,RdfInferenceMaterializationITRdfResourceIT,RdfInferenceMaterializationITafter the graph-listing changeManual testing performed
None beyond the tests above.
UI screen recording:
Not applicable — backend-only change.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.tripleCountmaps tojava.lang.Long; generated TS and Python are unchanged.