Repository navigation
Fix duplicate triples from re-asserted facts in the V6 incremental indexer - #1508
Merged
Merged
Conversation
This was referenced Jul 18, 2026
q-qp-p
pushed a commit
to q-qp-p/fluree-db
that referenced
this pull request
Aug 4, 2026
Delivers the fluree#1508 duplicate-triples / assert-retract-resurrection fix (fluree-db-indexer dedup_fact_lifecycles) to the virtual-dataset perf lineage — audit finding F-AUD-2 (audit-2026-07/00-MASTER-AUDIT.md). Merge verified conflict-free pre-flight via git merge-tree (2 files auto-merged in disjoint regions; decision record audit-2026-07/decisions/DEC-001-pr-bundling.md, Adjudication B).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-inserting triples that already exist in the database left the indexed view with duplicate rows: the same subject-property-object appearing many times (observed ~16× in the reporting ledger), along with spurious assert/retract churn in transaction history views. Live queries against in-memory novelty were correct; the duplicates appeared only after an incremental index build and compounded with each subsequent one. A full rebuild silently healed them, which made the bug look intermittent.
Root cause: commit files are event logs of user assertions, not state deltas — re-asserting a present fact is a legitimate event that records a new transaction, and every layer that materializes state from those events must apply RDF set semantics itself. Three of the four materializers did (in-memory novelty via
NoveltyFactState, the query overlay viaresolve_overlay_ops, and the full rebuild viaKWayMerge::next_deduped), but the V6 incremental pipeline replayed raw commit events with no lifecycle resolution:resolve_incremental_commits_v6sorted records without collapsing them, andmerge_novelty's two-pointer walk assumes at most one op per fact identity, so each duplicate assertion event materialized as an additional physical row in the FLI3 leaves.Changes
Set-semantics dedup in the incremental resolve (the core fix)
dedup_fact_lifecyclesruns after the(g_id, SPOT)sort inresolve_incremental_commits_v6and resolves each fact's in-window event sequence to a single final op, mirroring the in-memory novelty rules exactly so the updated index materializes the same state a live query resolves: a re-assert of a currently-asserted fact is a no-op (the earlier assert and itstsurvive, matchingNoveltyFactState's skip rule), any other op becomes the identity's winner, and same-tties resolve retract-wins (matchingresolve_overlay_ops).Fact identity is the resolved V2 identity
(o_type, o_i)— the identitymerge_novelty, replay, and the query overlay all compare by — rather than raw v1 fields. This matters becauseOTypeRegistry::resolvecollapses the datatype dict id for 1:1 object kinds (a boolean isxsd:booleanwhatever datatype IRI the commit carried) and consultslang_idonly forrdf:langString, so datatype-IRI variants and stray language tags on one fact dedup together while genuine language tags and list positions stay distinct. The dedup compacts in place behind a write cursor: a window with no duplicate facts copies nothing, and multi-record groups resolve through a reused scratch buffer in O(k log k).Correct stats deltas via base presence
The signed stats hooks (per-property/datatype/graph flake counts and rdf:type class counts) previously derived ±1 deltas from each record's op against base-seeded counts, which double-counts re-asserts and, once lifecycles collapse, applies unbalanced deltas for retract-then-reassert and assert-then-retract windows. The Phase 2 SPOT merge now reports which novelty ops matched an existing base row (
MergeOutput::matched, threaded throughupdate_leaf→ branch update →Phase2TaskOutput, collected for the SPOT order only), and the Phase 3b feed uses a newIdStatsHook::on_record_with_base_presence: +1 only for an assert of a base-absent fact, −1 only for a retract of a base-present one, 0 otherwise. Monotone accumulators (HLL sketches, touched-property sets,last_modified_t) still observe every record. The from-scratch event-replay feeds (rebuild/import) keep the unchanged legacyon_record. This also fixes a pre-existing bug: every re-assert of an indexed fact used to permanently inflate its property count.No history entries for non-transitions
The history sidecar is a transition log: time-travel replay undoes a retract entry by marking the fact present before it, so a retract entry with no paired assert anywhere makes replay fabricate the fact's presence at every
tbefore the retraction.merge_noveltyno longer writes a history entry for a retract of a fact the leaf never materialized (theGreaterarm and the post-rows drain loop), and the rebuild path skips retract-winner lifecycles whose identity has no assert anywhere in the commit log. This fixes both the ghost introduced by lifecycle collapsing (a fact asserted and retracted within one window deduped to a bare retract) and a pre-existing ghost when a user retracts a fact that never existed.Known limitations and follow-ups
history-transition-log-plan.md.tassert while novelty and the incremental path keep the first assert'st, so the two build paths can materialize different rowtfor the same event log. Pre-existing, out of scope here; folded into the plan file as a blocking design decision for the rework.Fixes #1412