Skip to content

Fixes #38042: validate RDF inverse pairs before registration - #38147

Merged
fmcardoso merged 6 commits into
mainfrom
fmcardoso/38042-symmetric-inverse-partner
Nov 19, 2026
Merged

fmcardoso merged 6 commits into
mainfrom
fmcardoso/38042-symmetric-inverse-partner

Conversation

@fmcardoso

@fmcardoso fmcardoso commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #38042

Follow-up to #38069, its symmetric-partner finding, and Gitar's decision-record requests (1, 2), and its shared-partner finding.

RDF import now keeps authored B edges beside symmetric A and resolves every predicate (authored edge or inverse target) by RDF identity. It reuses the governing registry type or a type already planned in the same batch, so one predicate never gets two types and no alias such as exactMatch appears beside seeded synonym.

Every new definition is validated before inverse pairs are wired, and again before any is saved, in real imports and dry runs alike. A failing definition is skipped, together with any new definition whose own owl:inverseOf names it. Its declaration no longer claims a partner that declares no inverse, so that partner pairs with the next valid claimer whatever the IRI order. Each skipped type is named, and the import returns HTTP 200 with accurate counts where main returned 400 after half-saving the pair.

Existing partners are rechecked before new types are inserted and again after insertion. The partner is then completed with EntityRepository.updateIfCurrent. If the version comparison fails, the partner is re-read once:

  • if it now points at the new type (a concurrent import made the same claim), the pair is complete;
  • if it is still unclaimed (an unrelated edit), the conditional write is retried once;
  • if another type claimed it or it keeps changing, the concurrent edit survives and the new type's inverse is cleared before edges are added. A late validation failure is handled the same way.

Type of change:

  • Bug fix

High-level design:

Extends the existing importer registration pipeline and RelationshipTypeResolver.findByPredicate. In order: resolve governed identities by predicate, prepare every candidate read-only and drop invalid ones (with definitions that declare them as inverse), wire candidate pairs, refresh existing partners, prepare again and discard invalid wired components, then persist accepted types. The partner completion is a version compare-and-set on an unchanged original and a deep copy, with one re-read after a lost comparison.

Known limits:

  • A same-user PATCH that the repository consolidates in-session can keep its version, so the compare-and-set does not detect that edit and it can be overwritten. Guarding updatedAt as well (as KnowledgePageRepository does) would need a relationship-type storage override; not done here.
  • The registration is not one transaction across all definitions.
  • Previously stored definitions are not deleted when an imported component is rejected.

No schema or migration changes.

Tests:

Use cases covered

  • Symmetric A keeps its self-inverse; B keeps no inverse and reads as B at both ends for both UUID orderings.
  • Each concurrency boundary has its own test in GlossaryRdfImportConcurrencyIT. The tests use a portable JDBI statement gate, with no MySQL trigger or named lock, and touch only rows they create:
    • a claim after registry discovery is rejected before insertion;
    • a claim after the new type's insertion clears the persisted inverse;
    • a claim just before the partner write is not overwritten (compare-and-set);
    • the same claim (partner → the new type) just before the partner write keeps the pair;
    • an unrelated description edit just before the partner write still completes the pair;
    • a partner validation failure clears the new inverse and returns 200 with a message.
  • Contradictory partner characteristics leave neither half registered in both real and dry-run imports, with matching messages and counts. Each edge that uses a skipped type gets the same message in both runs: "Relation skipped: its relationship type '' was skipped as invalid" (the real run used to say "is not registered", and the dry run said nothing).
  • An invalid gamma owl:inverseOf beta declaration no longer takes down the valid alpha/beta pair, whether gamma's IRI sorts before or after alpha's.
  • X owl:inverseOf skos:exactMatch reuses seeded synonym, with no alias. An edge authored with a governed predicate uses its governed name.
  • skos:related plus ex:mirrors owl:inverseOf skos:related in one batch registers one type for skos:related. This is a unit test with an injected resolver; the IT that deleted and re-inserted the seeded row is removed.

Unit tests

GlossaryRdfImporterTest: 19 passed, 0 skipped. Changed-class line coverage was not measured.

Backend integration tests

72c69ec1814 (edge messages for skipped types): GlossaryRdfImporterTest 19/19, GlossaryRdfImportIT 40/40, GlossaryRdfImportConcurrencyIT 6/6, 0 skipped, on the same command with -Dit.test=GlossaryRdfImportIT,GlossaryRdfImportConcurrencyIT. The table below is the earlier full run.

PASSED — focused mysql-elasticsearch verification of the tree committed as 8aa654e2b10.

Class Executed Skipped Failures/errors
GlossaryRdfImportIT 40 0 0
GlossaryTermRelationEdgeIT 15 0 0
RelationshipTypeResourceIT 172 27 0
RelationshipTypeContradictionIT 9 0 0
GlossaryRdfImportConcurrencyIT 6 0 0
Inherited history-pagination container 0 5 0

Total: 242 executed, 32 inherited skips, 0 failures/errors, plus 19 unit tests. The same run also executed a temporary HTTP-recording subclass of the concurrency IT (6 cases, not committed): Failsafe reported 280 run. Per-class counts are grouped by testcase classname because parallel Failsafe reports mix suite headers.

mvn -B -Dmaven.repo.local="$PWD/.context/m2" verify \
  -pl :openmetadata-integration-tests -am \
  -Dspring-boot.repackage.skip=true -Dresolve.skip=true \
  -Pmysql-elasticsearch -DintegrationTests.lane=parallel \
  -Dit.test=GlossaryRdfImportIT,GlossaryTermRelationEdgeIT,RelationshipTypeResourceIT,RelationshipTypeContradictionIT,GlossaryRdfImportConcurrencyIT \
  -Dfailsafe.failIfNoSpecifiedTests=false \
  -Dtest=GlossaryRdfImporterTest -Dsurefire.failIfNoSpecifiedTests=false

The live before/after table below came from a temporary local HTTP probe IT, which is not committed.

Production-only regression proof: each check kept the committed tests, reverted one production fix, and ran the matching tests with the compiled override first on the classpath (its load location verified). Each failed at its intended assertion, with 0 skips:

Reverted fix Failing test(s) Assertion
Re-read/retry after a lost compare-and-set sameClaimBeforePartnerWriteKeepsTheNewInverse, unrelatedEditBeforePartnerWriteStillCompletesThePair 2/2 failed: messages expected empty, got "kept changing while completing"
Validation before wiring importDoesNotRejectAValidPairForAnUnwiredInvalidDeclaration[true] relations expected 2, was 1; [false] passed
Rejected claimer excluded from partner selection same [true] alpha's inverse expected beta, was unset; [false] passed
Skip a definition whose declared inverse is rejected importSkipsInvalidInversePairWithoutSavingEitherHalf (both) registered expected 1, was 2
Skip edges of a skipped type in both runs (72c69ec1814, full Maven run with the old importer) importSkipsInvalidInversePairWithoutSavingEitherHalf (both) relation-skip messages expected 3, was 0 (real run: "is not registered" ×3)
Batch predicate reuse (unit) collectRelationTypesRegistersOnePredicateOnceAcrossEdgeAndInverseSlots 18/19 passed; expected [skosRelated], was [related, skosRelated]
Pre-insert claim recheck claimAfterDiscoveryIsRejectedBeforeInsertion new type version expected 0.1, was 0.2
Post-insert persisted-inverse clear claimAfterInsertionClearsThePersistedInverse stored inverse cleared: expected true, was false
updateIfCurrent partner write claimBeforePartnerWriteIsNotOverwritten partner inverse expected winner, was forward
Guarded partner validation partnerValidationFailureClearsTheNewInverse expected HTTP 200, was 400

The unchanged tests for authored-predicate reuse and dry-run validation were revert-proven on b21ffa44f92.

After restoring the source, the 10 selected API cases and all 19 unit tests passed.

mvn -B -Dmaven.repo.local="$PWD/.context/m2" spotless:check -pl openmetadata-service,openmetadata-integration-tests
python3 .github/scripts/plan_local_java_tests.py --check-branch
python3 scripts/harness/check_decision_records.py
git diff --check

All passed. Other engines, full repository coverage and CI monitoring were not run.

Ingestion integration tests

Not applicable — no ingestion changes.

Playwright (UI) tests

Not applicable — backend importer changes; no Playwright run.

Visual regression baselines

Not applicable — no rendering changes.

Manual testing performed

Built the real application against MySQL + Elasticsearch on allocated ports, authenticated as admin, and issued real import, relationship-type GET, term GET and concurrent PATCH requests. No credentials are included here.

Case Before Fixed branch
Contradictory inverse partner main: import 400; forward type exists with missing inverse target Import 200; both invalid types absent, skip message; independent valid type imports
Inverse already governed (skos:exactMatch) main: import 400; X points at missing exactMatch Import 200; X readable, synonym unchanged, no alias
skos:related edge + ex:mirrors owl:inverseOf skos:related a236bcb: import 200; related and skosRelated both on skos:related Import 200; one type on skos:related, no duplicates
B claimed by C just before the partner write a236bcb: import 200; competing claim overwritten (partner back to inverse=A, edits lost) Import 200; after one re-read, partner keeps C with edited description/palette; A's inverse cleared
Partner validation fails at completion a236bcb: import 400 after A was saved pointing at B Import 200; A's inverse cleared, message names the partner
B claimed by C after discovery / after insertion main: import 200, A→B beside B→C; a236bcb: already fixed Import 200; A has no inverse, B→C and edited fields preserved
Concurrent same claim (partner → A) just before A's partner write b21ffa44f92: import 200, "changed while completing"; A's inverse cleared, leaving B→A one-way Import 200, no messages; A↔B, A at version 0.1
Unrelated description edit of B just before the partner write b21ffa44f92: import 200, "changed while completing"; pair dropped Import 200, no messages; A↔B, edited description kept
Symmetric A / named B cycle main: B-authored views can return A Both UUID orders keep authored names; no conflict warning

UI screen recording:

Not applicable — backend-only bug fix.

Checklist:

  • Read CONTRIBUTING.md.
  • PR title and Fixes #38042 identify the linked issue.
  • Non-obvious constraints have short comments.
  • Schema/migration and UI recording requirements are not applicable.
  • Added behavior tests and failing-before/passing-after evidence above.
  • Self-reviewed final commit 8aa654e2b10 against REVIEW.md.
  • Added and cited the decision records.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 4/5

Fix the cleanup write before merging so dropping an inverse pair cannot erase concurrent edits.

Findings

  1. P1 Cleanup overwrites concurrent edits ▶

Summary

RDF imports now reuse governed relationship types, reject invalid definitions before saving, and protect existing inverse partners from competing edits.

  • RDF imports keep each predicate's governed relationship name.
  • Glossary imports skip invalid inverse pairs and keep valid relations.
  • RDF imports finish inverse links without overwriting newer partner edits.

fmcardoso documents the accepted limits: same-user edits that keep their version can be overwritten, registration is not one transaction, and rejected components do not remove previously stored definitions.

Reviews (2) · Last reviewed commit: "Report relations of a skipped RDF relati..." · Reviewed by Greptile

@fmcardoso
fmcardoso requested a review from a team as a code owner November 18, 2026 15:19
@fmcardoso
fmcardoso requested a review from yan-3005 November 18, 2026 15:19
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

Keep a symmetric property's self-reference while leaving its named partner
without an inverse. A one-way B-to-A link beside A's self-inverse changes
B-authored edges to A during UUID canonicalization.

Retain fresh-state partner completion, cover both UUID orderings with a
three-term HTTP regression, and trim inverse-wiring comments to constraints.
@fmcardoso
fmcardoso marked this pull request as draft November 18, 2026 16:34
Resolve inverse predicates to their governed types and prepare every new
candidate before saving any pair. Skip invalid pairs together so validation
cannot leave the first type pointing at an absent partner.

Recheck existing claims before insertion and before partner updates, clearing
our new inverse when either check loses. Preserve fresh governed fields while
making the remaining non-atomic window explicit.

Exercise actual symmetric wiring, record the identity-preserving rule, and
cover contradictory partners, predicate reuse, and controlled concurrent
claims through real HTTP integration tests.
@fmcardoso
fmcardoso force-pushed the fmcardoso/38042-symmetric-inverse-partner branch from f9fb754 to a236bcb Compare November 18, 2026 16:47
@fmcardoso fmcardoso changed the title Fixes #38042: don't link a named inverse to a symmetric partner on RDF import Fixes #38042: validate RDF inverse pairs before registration Nov 18, 2026
Complete an existing partner with updateIfCurrent on an unchanged original,
treating a stale version or a late validation failure as a lost claim that
clears the new type's inverse. Resolve authored and inverse predicates against
the registry and the current batch, so one predicate never gets two types.

Run the same read-only validation in dry runs, limit rejection to types
actually wired to an invalid one, and name every skipped type.

Replace the MySQL trigger and named lock with portable JDBI gates, giving the
pre-insert, post-insert, compare-and-set and partner-validation checks their
own failing-without-it tests. Record the governed-predicate, skip-as-a-whole
and lost-claim rules in a decision record.
When the partner's version comparison fails, re-read it once: accept a
partner that now points at the new type, retry the conditional write once
when it is still unclaimed, and clear the new inverse only when another type
claimed it or it keeps changing. Concurrent imports making the same claim and
unrelated partner edits no longer leave a one-way pair.

Validate new definitions before wiring inverse pairs. A rejected definition
no longer claims a partner that declares no inverse, so the partner pairs
with the next valid claimer regardless of IRI order; a definition whose own
declaration names a rejected one is still skipped with it.

Move the in-batch predicate test to a unit test with an injected resolver
instead of deleting the seeded skos:related row, add same-claim and
unrelated-edit gate cases plus the reverse-sorted claimer variant, align the
decision record with the code, and drop a redundant impact-map entry.
When a relationship type in the imported file failed validation, the real
import still tried to add each edge that used it and reported
"Relationship type '<t>' is not registered" per edge, while the dry run
dropped those edges silently. Counts matched, but the two runs returned
different messages, and the real-run wording hid the cause.

Both runs now skip edges whose type was skipped as invalid before reaching
the repository, with one message per edge:
"Relation <t> skipped: its relationship type '<t>' was skipped as invalid".
@gitar-bot

gitar-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 3 closed / 3 findings

RDF import now validates and conditionally updates shared relationship-type inverse pairs; concurrency failures could leave conflicting claims or inconsistent registry state.

Fixes RDF import so inverse pairs are validated before registration, with invalid definitions skipped and reported instead of half-saving a pair, and governed predicates reused rather than aliased. Resolved the missing decision records for the symmetric-partner and import rules, and the invalid type claiming a shared inverse partner before validation. No open issues remain.

✅ 3 closed
✅ Quality: Symmetric-partner inverse rule is not recorded in docs/decisions

📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:670-672 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:702-712
This PR makes a judgment call about how RDF import treats owl:inverseOf on a symmetric property, and no record in docs/decisions/ states it. The description says "The fix leaves B's inverse unset when its partner is symmetric so both ends keep B". Another reading of the same OWL is possible: inverseOf on a symmetric A can be taken as A and B being equivalent, which is what the code comment deleted here described. isCompatibleInversePartner now rejects any symmetric partner, both for types in the import and for types already in the registry. That changes what gets stored for later imports, for exports and for the Studio, which shares this registry of types (ADR:2026-10-21-native-relations-instantiate-registry-relationship-types). The PR also deletes the code comments that gave the OWL 2 DL reasoning, so after the squash-merge nothing in the tree explains the rule.

The record would say: "On glossary RDF import, a symmetric relationship type keeps its self-inverse even when it declares owl:inverseOf B. B is registered with no inverse, so edges authored as B stay B at both ends instead of being canonicalized to the symmetric type. Relationship types already imported are not rewritten."

✅ Quality: Import rules for governed reuse, pair skipping and lost claims lack ADR

📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:669-683 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:1031-1045 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:1076-1090 📄 docs/decisions/2026-11-18-rdf-import-symmetric-inverse-partners-stay-unlinked.md:13-15
The new ADR covers only the symmetric-partner rule. This commit also adds three import rules that no record in docs/decisions/ states, and the repository's review rules say one record does not cover a second decision.

  1. Governed reuse: collectInversePartner resolves the inverse with findByPredicate and reuses the type it finds. The description says: "An inverse predicate already governed under another name reuses that type instead of creating an alias such as exactMatch beside seeded synonym."
  2. Pair skipping: rejectInvalidRelationPairs prepares every type before any write. expandInvalidInversePairs then drops the whole inverse component. The description says: "Invalid new pairs are validated before any batch member is saved and skipped together with a message; independent valid types can still import."
  3. Lost claims: refreshInversePartners, persistRelationTypeUpdates and clearNewInverse let a concurrent edit win and clear the new type's inverse. The description says the importer "clears its own new inverse if the later check detects a lost claim". It also states a known limit: the final read and write have no conditional update.

The description is squash-merged and never reaches git log, so these rules would exist only in code.

✅ Edge Case: Invalid type can claim a shared inverse partner before validation runs

📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:649-654 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:706-720 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:801-815 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/GlossaryRdfImporter.java:1062-1076 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/GlossaryRdfImportIT.java:976-990 📄 docs/decisions/2026-11-18-rdf-import-registers-governed-inverse-components.md:17
wireInversePartners decides who gets a shared partner before any type is validated, and rejectInvalidRelationPairs only runs afterwards. inversePredicateIri picks the lexicographically first candidate, so the partner a new type points to depends on IRI order, not on whether the claimer is valid.

Trigger: rename gamma in importDoesNotRejectAValidPairForAnUnwiredInvalidDeclaration so its IRI sorts before alpha (e.g. aGamma). Then:

  1. beta resolves its reverse inverse to the invalid gamma and gets wired to it.
  2. alpha sees that beta already points to gamma, so it gets the "different inverse" message and its inverse is left unset.
  3. gamma fails prepareInternal, and expandInvalidInversePairs also skips beta.

The valid alpha/beta pair is lost and alpha is imported with no inverse. This breaks the ADR rule that "a rejected inverse declaration is not a connection to an otherwise valid component", and the test only passes because of how its names happen to sort.

Fix: run prepareInternal on each new type before wiring, and leave types that fail it out of the candidate partners in wireInversePartners/normalizeNewInverseReferences. Add the reverse-sorted variant of the test.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@fmcardoso
fmcardoso marked this pull request as ready for review November 19, 2026 08:59
Comment on lines +1238 to +1242
private void clearPersistedInverse(UUID typeId, UUID partnerId) {
RelationshipType current = registry.get().require(typeId);
if (current.getInverse() != null && partnerId.equals(current.getInverse().getId())) {
current.setInverse(null);
overwriteRelationType(current);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Cleanup overwrites concurrent edits. When an existing partner is claimed elsewhere or cannot be completed, clearPersistedInverse reads the newly saved type and then passes that snapshot to createOrUpdate. A different user can edit its description or inverse between those calls. createOrUpdate loads the newer row as its baseline but writes the older snapshot over it, silently losing that edit—even when its version advanced.

Use an unchanged original and a copy with updateIfCurrent for cleanup too. After a conflict, re-read and clear only an inverse that still names the rejected partner.

Knowledge Base Used: Metadata entity lifecycle

@fmcardoso
fmcardoso added this pull request to stack #38191 November 19, 2026 09:02
@fmcardoso
fmcardoso merged commit 85c922a into main Nov 19, 2026
99 checks passed
@fmcardoso
fmcardoso deleted the fmcardoso/38042-symmetric-inverse-partner branch November 19, 2026 09:42
fmcardoso added a commit that referenced this pull request Nov 19, 2026
#38147 was squash-merged into main; conflicts resolved against its PR head, so this PR's diff is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M4KprReeYHb7DDyP4ujmSX
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.

[Detail Bug] Glossary RDF import can persist relationship types with dangling inverses, breaking relatedTerms reads

2 participants