Skip to content

[Detail Bug] RDF/SPARQL: Outbox replay can resurrect deleted non-lineage and glossary relationship edges #36026

Done

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_3377c26d-da48-4ccd-b83a-22c542f4fe83/bugs/bug_ba8b337b-013c-4081-af18-594b1f3feb65

Introduced in #32262 by @harshach on Sep 9, 2026

Summary

  • Context: The RDF projection (openmetadata-service/src/main/java/org/openmetadata/service/rdf/) mirrors SQL relationship edges into a SPARQL knowledge graph via durable RdfLiveWrite commands (RdfLiveWriteStore outbox) and the blue-green rebuild journal, which replays the storage-level mutations those writes performed, long after capture.
  • Bug: Replayed ADD commands for non-UPSTREAM relationships and glossary term relations blindly re-insert their triples (repository.addRelationship / repository.addGlossaryTermRelation are unconditional INSERT DATA), unlike the UPSTREAM lineage branch which reconciles against SQL at replay time (refreshLineage).
  • Actual vs. expected: When an ADD command is delivered late (storage-outage retry, or blue/green rebuild journal replay) after the SQL edge was deleted by a path that emits no remove command (bulk relationship updates, CSV import), the replay resurrects a triple whose SQL row no longer exists; the established replay contract ("leaves the graph matching the database whatever order the add and delete replays run in") is honored only for lineage.
  • Impact: Stale om:owns / om:contains / prov:used / skos:broader edges are served to SPARQL consumers indefinitely (until an indexing run happens to cover the source entity or a full rebuild), misrepresenting ownership, containment, lineage-adjacent and glossary relations.

Code with Bug

openmetadata-service/src/main/java/org/openmetadata/service/rdf/RdfLiveWrite.java:

record RelationshipChange(String relationshipJson, boolean remove) implements RdfLiveWrite {
  ...
  @Override
  public void apply(final RdfRepository repository) {
    final EntityRelationship relationship =
        JsonUtils.readValue(relationshipJson, EntityRelationship.class);
    if (remove) {
      repository.removeRelationship(relationship);
    } else if (relationship.getRelationshipType() == Relationship.UPSTREAM) {
      repository.refreshLineage(relationship);   // <-- reconciles against SQL before projecting
    } else {
      repository.addRelationship(relationship);  // <-- BUG 🔴 blind INSERT DATA, no SQL re-check
    }
  }
}

record GlossaryRelationChange(UUID fromId, UUID toId, String relationType, boolean remove)
    implements RdfLiveWrite {
  @Override
  public void apply(final RdfRepository repository) {
    if (remove) {
      repository.removeGlossaryTermRelation(fromId, toId, relationType);
    } else {
      repository.addGlossaryTermRelation(fromId, toId, relationType);  // <-- BUG 🔴 blind INSERT DATA
    }
  }
}

Explanation

  • The outbox/replay mechanism can deliver an ADD well after it was captured (e.g., Fuseki outage retry, or replay during blue/green promotion).
  • For non-UPSTREAM relationships and glossary relations, the replayed ADD path unconditionally does INSERT DATA and does not verify the corresponding entity_relationship row still exists.
  • Some SQL deletion paths do not enqueue any RDF remove command (bulk relationship updates, owner removals, CSV import relationship clears). If such a deletion happens after the ADD was captured but before the ADD is replayed, the replay will reinsert a triple that no longer exists in SQL.
  • Once reinserted, later entity refresh/upsert does not delete these “hook-managed” relationship predicates, so the stale triple persists until a reindex run happens to cover the entity or a full rebuild.

Codebase Inconsistency

The lineage path implements the intended replay contract by reconciling against SQL during replay, removing the relationship instead of inserting if the SQL edge is gone:

// RdfRepository.refreshLineage — the replay contract the other two branches lack
final Optional<RdfProjectionLoaders.StoredLineageEdge> storedEdge =
    projectionLoaders.lineageDetailsLoader().load(lineage.getFromId(), lineage.getToId());
if (storedEdge.isEmpty()) {
  removeRelationship(lineage);   // <-- replay of an add whose SQL edge is gone deletes instead
} else {
  projectLineage(lineage, storedEdge.get().details());
}

Failing Test

mvn -pl openmetadata-service test -Dtest=RdfLiveWriteTest

Two added tests in openmetadata-service/src/test/java/org/openmetadata/service/rdf/RdfLiveWriteTest.java fail on current code:

  • genericRelationshipAdditionReplayedAfterTheEdgeWasDeletedResurrectsIt (CONTAINS)
  • glossaryRelationAdditionReplayedAfterTheRelationWasDeletedResurrectsIt (skos:broader)

Output summary: Tests run: 18, Failures: 2; failure is expected: <false> but was: <true> showing the triple is resurrected. The existing lineage test lineageAdditionReplayedAfterTheEdgeWasDeletedDoesNotResurrectIt passes, confirming the asymmetry.

Recommended Fix

Give the non-UPSTREAM and glossary add paths the same replay-time SQL reconciliation as lineage: if the replayed ADD’s SQL row no longer exists, remove/no-op rather than INSERT DATA.

// RdfLiveWrite.RelationshipChange.apply
} else if (relationship.getRelationshipType() == Relationship.UPSTREAM) {
  repository.refreshLineage(relationship);
} else {
  repository.refreshRelationship(relationship);  // <-- FIX 🟢 loads the edge from SQL; gone → removeRelationship
}

Implement refreshRelationship to consult SQL for (fromId, toId, relation) before projecting. Apply the same pattern for glossary term relations (including canonical-direction/relationType handling).

History

This bug was introduced in commit d821be9 ("Fixes #32057: single-writer RDF reindex pipeline and Jena 6.2.0 upgrade (#32262)", 2026-09-09). That commit shipped RelationshipChange.apply / GlossaryRelationChange.apply calling unconditional insert paths.

Commit 431885dde6 later added replay-time SQL reconciliation for lineage (refreshLineage) and a dedicated test, but left the non-UPSTREAM and glossary branches on the original blind INSERT DATA logic.

Activity

  1. iamkiayun commented on Nov 23, 2026

    @iamkiayun
    Contributor

    Hi — I'd like to pick this up if no one is already working on it.

    Verified on main that RdfRepository.refreshRelationship (non-UPSTREAM branch) and refreshGlossaryTermRelation only check endpoint liveness (hasLiveEnds / areLive) rather than reconciling edge existence against SQL like refreshLineage does.

    Plan: reconcile replayed non-UPSTREAM relationships and typed glossary term relations against SQL at replay time (removing stale triples if the edge no longer exists or an endpoint is no longer live) and add unit + RdfLiveWriteRecoveryIT regression tests. Let me know if there are any extra constraints to keep in mind.

  2. added a commit that references this issue on Nov 24, 2026
    0c6f3b0
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

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done ✅

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions