Repository navigation
Description
Found during review of #1698 and confirmed by calling the helper directly. This is pre-existing and not introduced by that PR — but it is the same symptom #1698 is fixing (a retraction that silently has no effect), reached through a different door, so it's worth its own issue rather than living in a review thread.
What happens
resolve_latest_ops_keep_asserts (fluree-db-query/src/binary_range.rs:1580) is the lifecycle-resolution helper that turns an overlay log into current state. It groups flakes by walking adjacent runs and closing a group the moment same_fact_identity (:860) returns false — and that identity includes m, the flake metadata.
But every comparator orders … t, op, m — t before m (fluree-db-core/src/comparator.rs:161-207; cmp_spot is s, p, object, t, op, meta). So when two flakes share (s, p, o, dt) and differ only in metadata, the later-t retraction is separated from its own assert by the sibling's assert. The run closes early, the retraction never meets the flake it cancels, and the retracted assert is emitted as live.
Confirmed
@list ["a","b","a"], DELETE the position-0 entry
-> [("a", i:0), ("a", i:2), ("b", i:1)] // retraction had no effect
ex:label "hello"@en, "hello"@fr, DELETE "hello"@en
-> [Some("en"), Some("fr")] // retraction had no effect
Deleting the position-2 entry instead passes, which shows the shape of it: it only fails when the retracted entry's metadata sorts below a surviving sibling's. On any list with a repeated value that's roughly a coin flip, not a rare corner.
Why it matters
The helper is reached from four call sites (:796, :1432, :1487, and — after #1698 — overlay_only_flakes), so this affects overlay-only reads generally, not one lane. The user-visible shape is the one we keep coming back to: a delete commits successfully and the data is still there.
This is also a recurrence of a bug class we've hit before. RDF fact identity here is (s, p, o, dt, m) with m = FlakeMeta{lang, i}, and #1273 was the same story in range::remove_stale_flakes — a key that mishandles m collapses langString variants sharing a lexical form and @list members repeating a value at different indices. Worth noting that the existing regression coverage uses single-occurrence values only, so it passes with this bug present.
Suggested direction
Group on (s, p, o, dt) and resolve per-m inside the group, rather than relying on run adjacency:
// inside the group, keep the newest op per distinct `m`
let mut by_meta: HashMap<&Option<FlakeMeta>, usize> = HashMap::new();
// ... then emit the winners that are assertsReordering the comparators to put m ahead of t would also work, but that changes index ordering semantics repo-wide and I don't think it's the right lever here.
Whatever lands should be pinned by both shapes above — a repeated @list value and one lexical form under two language tags — since either alone leaves half the mechanism uncovered.
Activity
fix(query): resolve per-metadata inside a fact run, and sweep the thi…
perf(query): group a fact run by sorting on metadata, not by scanning…
fix(query): group fact runs by an order that agrees with metadata equ…