Skip to content

Identical triples accumulate and become undeleteable via where+delete+insert pattern #1192

Closed

Description

@IX-Erich

Summary

When using the where + delete + insert transaction pattern repeatedly against the same subject, identical triples (same subject, predicate, and object value) can accumulate, violating RDF set semantics. Once accumulated, these duplicate triples cannot be removed via the transaction API — delete transactions return success but the triple persists.

This creates entities that permanently violate SHACL sh:maxCount constraints with no API-level remediation.

Environment

  • Fluree Server v3 (HTTP API, fluree/server Docker image)
  • Ledger created via standard fluree/create
  • Transactions via HTTP POST to /fluree/transact

Reproduction

Step 1: Create a SHACL shape constraining a property to maxCount 1

{
  "@context": {
    "ex": "http://example.org/",
    "sh": "http://www.w3.org/ns/shacl#",
    "xsd": "http://www.w3.org/2001/XMLSchema#"
  },
  "insert": {
    "@id": "ex:ThingShape",
    "@type": "sh:NodeShape",
    "sh:targetClass": {"@id": "ex:Thing"},
    "sh:property": {
      "sh:path": {"@id": "ex:slug"},
      "sh:datatype": {"@id": "xsd:string"},
      "sh:minCount": 1,
      "sh:maxCount": 1
    }
  }
}

Step 2: Repeatedly run a where+delete+insert transaction

Run this transaction multiple times (simulating an idempotent bootstrap/sync operation):

{
  "@context": {"ex": "http://example.org/"},
  "where": [{"@id": "?s", "@type": "ex:Thing"}],
  "delete": [{"@id": "?s", "?p": "?o"}],
  "insert": {
    "@id": "ex:thing-1",
    "@type": "ex:Thing",
    "ex:slug": "my-slug-value"
  }
}

After several runs, querying ex:thing-1 returns:

{"@id": "ex:thing-1", "ex:slug": ["my-slug-value", "my-slug-value"]}

The SHACL shape now reports a violation: count 2 is greater than maximum count of 1.

Step 3: Attempt to delete the duplicate — fails silently

{
  "@context": {"ex": "http://example.org/"},
  "where": [{"@id": "ex:thing-1", "ex:slug": "?v"}],
  "delete": [{"@id": "ex:thing-1", "ex:slug": "?v"}]
}

Transaction returns 200 OK (success), but querying the entity still shows count 2 for the slug. The triple is undeleteable.

Attempting a combined delete+insert also fails because SHACL validates the intermediate state and sees count 2 before the delete takes effect.

Observed behavior (from production)

In our production Fluree instance, we have entities with accumulated identical loom:slug values (e.g., ["03-provenance-attestation-anchoring", "03-provenance-attestation-anchoring"]). We attempted to remediate via:

  1. Targeted where+delete — returns success, triple persists
  2. Remove SHACL shape, then delete — SHACL shape removed successfully, but the duplicate triple still cannot be deleted
  3. 20 iterations of delete transactions — all return success, triple remains
  4. Delete all properties via ?p ?o wildcard — most properties removed, but the accumulated slug persists

The only workaround was to create new entities with a different sync strategy (per-document diff-aware upsert instead of bulk where+delete+insert).

Expected behavior

  1. RDF set semantics: Inserting the same (subject, predicate, object) triple multiple times should be idempotent — the triple should exist exactly once.
  2. Delete consistency: A delete transaction that returns success should actually remove the matched triples. Silent no-ops on delete are a data integrity issue.
  3. SHACL intermediate state: If where+delete+insert is evaluated in a single transaction, SHACL validation should apply to the final state, not an intermediate state after insert but before delete.

Impact

  • Entities become permanently non-compliant with SHACL constraints
  • No API-level remediation exists — the only workaround is to avoid the pattern
  • Idempotent bootstrap/migration scripts that use where+delete+insert become destructive over repeated runs
  • CI pipelines that re-sync data on every deploy progressively corrupt entities

Possible root causes

  • The where+delete+insert pattern may have a transaction ordering issue where insert is applied before delete is fully committed
  • JSON-LD type inference may create distinct internal representations for values that appear identical (e.g., bare string vs {"@value": "...", "@type": "xsd:string"}), causing the delete to miss one variant
  • The delete API may match on a subset of the internal triple representation, leaving "phantom" duplicates

Activity

  1. IX-Erich commented on Mar 4, 2026

    @IX-Erich
    Author

    Please note - this was generated by Opus 4.6 based on its findings. I hope this is a useful report and not ai hallucination. Apologies in advance if it is noise. Thx

  2. IX-Erich commented on Mar 4, 2026

    @IX-Erich
    Author

    Additional finding: phantom IRIs from failed transactions

    During remediation of the corrupted entities described above, we discovered a more severe variant:

    1. When a transaction fails SHACL validation, the entity IRI is still allocated in the storage layer
    2. The IRI then exists as a "phantom" — it can be matched in where clauses (e.g., by @type), but select * returns only {"@id": "..."} with no properties
    3. Subsequent insert transactions targeting this phantom IRI succeed (return a commit hash) but the properties are silently discarded — they never persist
    4. Delete/retract transactions also succeed silently but have no effect
    5. The phantom IRI is permanently corrupted — it cannot be populated, modified, or deleted

    Reproduction:

    1. Create a SHACL shape with required properties (e.g., sh:minCount 1 on ex:order)
    2. Attempt to insert an entity of the target class missing required properties → transaction is rejected with SHACL violation
    3. Query for the entity by IRI → it exists (returns {"@id": "ex:the-entity"}) but has no properties
    4. Attempt a valid insert with all required properties at the same IRI → transaction succeeds (returns commit hash) but properties don't persist
    5. The IRI is now permanently unusable

    Impact: This means failed transactions permanently "poison" IRI namespace entries. The only workaround is to use a completely new IRI that has never been the target of any transaction (successful or failed). This is particularly problematic for idempotent sync/bootstrap operations that retry with the same IRIs.

  3. bplatz commented on May 17, 2026

    @bplatz
    Contributor

    Closed, old version

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions