Skip to content

fix: a retraction and an assertion of one fact at one t resolve the same way everywhere - #2153

Merged
aaj3f merged 27 commits into
mainfrom
fix/same-t-one-rule
Oct 26, 2026
Merged

aaj3f merged 27 commits into
mainfrom
fix/same-t-one-rule

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Partially addresses #2090: with #2109 a restating write no longer commits a retraction and an assertion of one value at one t, and with this PR a ledger that already holds such a pair reads it the same way on every path, so its answers no longer change at an index build. Novelty's term-keyed dedup, #2027's subtype in the index, BIND's integer datatype, -0.0/"1.50" after indexing and xsd:float precision remain.
Follow-up: #2152 (the S2 spatial query surface).

Why

A commit can hold a retraction and an assertion of one fact at one t. #2109 stops new writes from producing them, but ledgers written by earlier versions have them, from three places:

  • a restating write of a subtyped big integer (the index keeps no subtype, so the retraction names the stored term and the assertion the written one): DELETE/INSERT of the value, DELETE DATA x ; INSERT DATA x, an identical upsert or graph sync, a subtype change, a revert of a delete-then-insert;
  • the same for a dateTime past the microsecond, whose two terms reload identical because the commit keeps six digits;
  • merges and reverts written before the net-change fold, which concatenated a range's flakes into one commit.

The commit doesn't record which op came last, so something has to decide, and today it's decided in more than twenty places that don't agree. The ones that matter most:

Lane Before this PR
Full rebuild (resolve_transitions), annotation arena, history replay assertion
Incremental lifecycle dedup (dedup_group), which also dropped the loser outright retraction
Query overlay (resolve_overlay_ops), core range (remove_stale_flakes) retraction
Novelty fact state, the stats fold, the batched ref deltas, CurrentFacts' key merge retraction
Binary scan's own copy of core's stale-flake removal assertion, by position
Merge/revert netting, the full rebuild's class-stats pass, export, fulltext de-stale, merge_latest_ref_objects whichever op came first
Spatial replay retraction, by sort position

So on an indexed ledger the live view and incremental builds read the value as absent, and a full rebuild reads it as present. Full rebuilds don't only happen on request: build_index_for_record falls back to one when there's no base index (a new ledger, a clone, a restore), when the commit gap is over 10,000, and on any retryable incremental failure or IncrementalAbort. So answers could change on a ledger that never asked for a reindex, and a fresh replica built from commits could disagree with the origin it cloned. Measured on main at 57bf7a944 (absent / absent / present: live, incremental, full) for every restating write shape above, and present / absent / present for a value written since the last build.

What changes

One rule. fluree_db_core::same_t owns it: at one t the assertion holds. op_order(t, op) is the sort key every walk uses (a walk in that order ends on the op that holds) and supersedes((t, op), (cur_t, cur_op)) is the streaming fold. Assertion, because every pair main and v4.2.4 write was meant to keep the value, and because the lanes that already said "assertion" are the persisted ones (run records, the history sidecar's replay, the annotation arena), so no index on disk changes meaning.

Every lane above that settles a pair by picking the op that holds goes through one of the two. (The first commit's message, 408542252, says every lane does. Two don't, and they're covered right after this list.) A few are worth calling out:

  • dedup_group now keeps the losing retraction as superseded history instead of dropping it, so the incremental merge walks the same events a rebuild does and writes the same row and sidecar. The replay property suite now enumerates same-t pairs (in both stored orders, at every slot) and checks the incremental pipeline and the rebuild against one reference at every boundary.
  • The binary scan's resolve_overlay_retractions was a private copy of core's remove_stale_flakes that had drifted to the other answer. It's gone; the three call sites call resolve_current_flakes.
  • Novelty::apply_commit dropped an assertion whose term novelty already held as asserted, even when the same commit retracted it. Under retract-wins that was harmless; under the rule it dropped the winner. It now keeps an assertion its own commit retracts, which is what bulk_apply_commits already did, so the per-commit and bulk paths agree again (their docs say they should). Such assertions are held until the commit's retractions are known, so a commit without one pays nothing for it.
  • The spatial index keys a cell by subject, with no value, so its replay now resolves every entry at one (cell, subject, t) by the rule instead of taking the first one in sort order. The cell order on disk doesn't change.
  • ReasoningOverlay dropped a stored retraction a derived fact restated at the query's t, because under retract-wins it would have hidden the derived fact. Under the rule the derived assertion holds on its own, so that workaround is removed.

Two places that can't settle a pair by picking an op. Both read what the ledger holds instead:

  • A full rebuild's counts. Its first stats pass counted every commit-log record by the sign of its op, so a pair of a value absent before it counted 0, though the index holds the value. That's on main too, for a commit pulled verbatim or written before the staging check. The counts (graph, property, datatype, class) now come from the second pass's merge winners, one per fact the index holds, which is what an incremental build counts against. The first pass only feeds the sketches, last-modified t and the historical datatype tags.
  • A revert. Undoing a commit that holds a pair has to restore what held before it, and the commit alone can't say whether that was the value or nothing. Resolving the pair to its assertion made the revert keep the value either way. The undo's net change now reports those facts, and the revert reads each one at the commit's t - 1 (CurrentFacts::at) and writes that state: the fact asserted if it was present, retracted if it wasn't. As with any undo, that's a restatement when the head already agrees, and a real change when a later commit in the range changed the fact again (revert the pair's commit together with a later delete and the value comes back). That's one point read per pair, batched by t, and a range with no pair does no extra work.

Separately, since this touches spatial: geospatial.md described an idx:spatial query for complex geometries that no query surface parses (a query written that way returns nothing). The S2 section now says it isn't available yet, keeps what the index side does, and labels the query examples as the planned interface. It also corrects a SPARQL note that said geof:sfWithin evaluates as a filter: only geof:distance is implemented. The rest of that gap is #2152.

A staging invariant. A commit built here may not hold such a pair. build_commit checks the staged view with FactIdentity::same_t_pairs (#2109's identity: by term, or by index key for a value whose key can merge terms) and refuses one with a typed internal error that names the fact, TransactError::SameTPair (500). #2109 removes every producer I know of, so this is a regression guard. It's a fail-closed trade, fwiw: a staging lane that misses the identity now shows up as a 500 on that write, rather than as a pair kept quietly. I couldn't find one, and #2144's netting, merged since, keys by the same identity and stages nothing for a fact both retracted and asserted. The check walks the staged view's SPOT order once, passes over a view that doesn't both retract and assert, and computes keys only for the kinds of value that can merge terms, in slots holding both ops.

Commits that arrive whole (push, clone, restore, import) don't go through build_commit, so old ledgers still replicate. Rebase is the one local lane that replays an old commit's flakes, so it resolves a pair to its assertion before staging (resolve_same_t_pairs, the same detection), which is what the pair meant. It drops every retraction an assertion pairs with, so a big integer retracted under two subtypes at once (novelty can hold both) resolves too. Merge nets its range to one op per fact, and revert does too, reading a pair's fact before its commit as above.

Behavior changes

Case Before After
A same-t pair of a value the index holds absent live and after incremental builds, present after a full rebuild present on every path
A same-t pair of a value written since the last build present live, absent after the next incremental build, present after a full rebuild present on every path
Time travel at the pair's t and before it per lane, as above present at both (when the value existed before)
Ledger stats for the predicate follows the lane counts the value once
Full-rebuild stats for a pair of a value absent before it (a pulled commit, or one written before the staging check) 0 for it 1
A value an earlier incremental build already dropped this way absent until a full rebuild absent until a full rebuild (unchanged), present after
A subject whose rdf:type the overlay holds as a same-t pair, in the batched ref lookup class-based policy reads type not held, so a policy on that class didn't apply to the subject type held, so a policy on that class applies to it, as every read and index build already sees the type
A commit built here holding a pair written refused (500, internal error naming the fact)
Rebase of a commit holding a pair replayed verbatim replayed as its assertion
Revert of a commit holding a pair kept or removed, by the order the commit stores the two ops what held before that commit (absent if the value was absent, present if it was), also when a later commit in the reverted range changed it again

One counter-case to be aware of: a v4.2.3-era INSERT DATA x^^nonNeg ; DELETE DATA x^^integer (meant to remove the value) committed exactly the same flakes as DELETE DATA x^^integer ; INSERT DATA x^^nonNeg (meant to keep it). Nothing in the commit tells them apart, so with this PR that commit reads present everywhere, which is what a full rebuild already showed for it. main and v4.2.4 don't pair that shape.

Upgrade notes

  • Nothing on disk changes, and no index needs rebuilding for this to apply.
  • A ledger holding pairs answers present for them at once wherever they're still in novelty. A value an incremental build already dropped this way stays dropped in that index, and comes back at the next full rebuild (fluree reindex), the same moment it comes back today. A reindex is now a deliberate repair for these values rather than a surprise.
  • A local write that ever produced a pair now fails with an internal error instead of committing one. None should.

Tests

it_same_t_one_rule.rs (in grp_index) stages the pair the only way a current ledger can get one: as a pushed commit, rebuilt from an exported DELETE DATA commit with its flakes set to the pair. Then it requires the value present, once, on every path: live on the instance that took the push, reloaded, at t - 1 and t, in the ledger's stats, after an incremental build (the first build, for a ledger never indexed) and after a full rebuild. That's for a subtyped big integer and a dateTime, in the default and a named graph, with the value already indexed, in novelty only, in a graph new to the index, and on a ledger never indexed. Each runs with the pair stored retraction-first and assertion-first, since a fold that keeps whichever op it meets first passes one order by luck. Targets are file-backed with without_indexing(), so every build is the one the test asks for.

The fresh-graph case at t - 1 after an incremental build relies on #2118's lifecycle walk for the new graph's branch, which is on main now and merged here.

The same file covers the invariant (a hand-built view holding a pair is refused with the 500), the exemption (a pushed commit holding a pair is taken, as stored), and the rebase (a pair is replayed as its assertion). It also covers what a pushed pair can't reach:

  • Push refuses a retraction of an absent fact, so a pair of a value absent before it can't be pushed. a_pair_over_an_absent_value_counts_once_and_reverts_to_absent pulls one instead (import_commits_incremental), for a string and a big integer, in both orders, indexed and not. The value reads present and counts once in an incremental and a full-rebuild index, and reverting that commit leaves it absent. A control with the value present before reverts to present.
  • a_range_revert_from_a_pair_restores_what_held_before_it reverts the pair's commit together with a later delete of the value. A value present before comes back (a big integer and a dateTime, both orders, from novelty and from an index), and one absent before stays absent.
  • a_delete_of_an_indexed_big_integer_names_a_pair_novelty_holds deletes an indexed big integer while novelty holds a pair of it under two subtypes. Staging's read has to merge the index row and both ops by key to find what to retract.
  • a_restating_cypher_set_commits_nothing: a Cypher SET to the value a property already holds commits nothing, so it can't leave a pair for a revert to undo.

Below the api:

  • same_t_pairs_replay_alike_on_both_pipelines puts a same-t pair, in both stored orders, at every slot of every op chain up to three long, over both base states. It checks the incremental pipeline (dedup → leaf merge → sidecar → replay) and the rebuild against one reference at every boundary, for presence and row t.
  • Each lane has a unit test of its own tie, in both orders where the order used to matter. The fulltext novelty fold is one function now, so its test calls the production code rather than a copy of it.
  • resolving_pairs_drops_each_retraction_wherever_it_sits pins the positions rebase resolves pairs by (flakes out of SPOT order, a pair behind another value of its slot), and whole_graph_reads_as_of_to_t that CurrentFacts reads every shape as of an earlier t.
  • test_polygon_edited_within_its_cells_is_found builds a real spatial snapshot with a polygon, its retraction and a slightly edited polygon at one t, and queries it.

Against #2109's head (3ebb552b5), the matrix fails 43 cells (counted before the assertion-first cells went in): absent live, reloaded and after an incremental build on indexed values; absent after the incremental build for novelty-only values; a dateTime pair absent even on a ledger never indexed; stats counting 0. The local commit with a pair is written, and the rebase replays the pair verbatim. The spatial test fails there too: within finds nothing after the edit.

I also took each piece out on its own and watched its tests fail:

  • the build_commit check;
  • the rebase's resolution;
  • dedup_group dropping the same-t loser instead of keeping it as history (the property test reports the lost interval);
  • apply_commit's keep;
  • the overlay tie (12 matrix cells);
  • the overlay and core-range ties together, with the reasoning workaround removed (a_fact_retracted_at_the_query_t_is_still_derived fails, so it's the rule keeping that fact visible now).

And each of the 20 places the rule touches, flipped back on its own to what it did before (an env-gated patch, not committed), fails at least one committed test. The run covered it_same_t_one_rule, both reasoning tests and the lib tests of core, binary-index, novelty, indexer, transact, spatial, query and the api, 5,484 tests that all pass unflipped. 12 of the 20 fail it_same_t_one_rule. The other 8 fail their own unit tests: novelty's fact state, the merge/revert netting, spatial replay, the batched ref deltas, export, fulltext, merge_latest_ref_objects and the rebase's key pairing.

Perf

resolve_overlay_ops and NoveltyFactState::record sit on hot paths, so this was measured as instructions retired and allocations (the box was loaded), with interleaved passes of #2109's head against this PR before main was merged. The fixture is 20k subjects with 8 churn commits in novelty.

  • Queries: an overlay scan, point read and join, and the same on a ledger never indexed, all within ±0.5%. Allocations are identical.
  • Builds: an incremental build over the churn and a full rebuild, both within ±0.1%.
  • Writes: inserts and 400-flake upserts within ±0.1%, with 1–2 more allocations per upsert (the slot buffer).
  • The follow-ups (revert by presence, rebuild counts from the merge, pairing every retraction of a key), against this branch with them reverted, both after merging main: a full rebuild +0.10% and an incremental build +0.14%, inside run-to-run spread; inserts, integer upserts and 400-flake double upserts (which reach the key pairing) within ±0.1%, with the same allocations. A first cut of the rebuild counts cost +1.34% on the full rebuild, because the first stats pass still updated its count maps by zero; it doesn't touch them now.
  • The review round (the range-revert fix, pair positions carried through the staging check's walk, whole_graph reading as of to_t), against the merge just before it: inserts, integer and double upserts and a 20,000-flake upsert within ±0.5% in instructions, allocations the same.
  • The invariant alone, on staged views: 15.8K instructions for a 600-flake insert (just the op scan), 85K for a 400-flake upsert, and 3.6M for a 20,000-flake upsert, which is 0.16% of that write.

Criterion (query_hot_optional, query_hot_negation_count, query_hot_bsbm, reindex_incremental, run interleaved in both orders) moved more with the box's load than with the change: in the quieter round this PR was within ±4% and mostly faster, and in the loaded one #2109's head read slower. I'd treat that as no signal, and can rerun it on a quiet box if we want a wall-clock number.

Gates

All with --all-features, after merging main (eaa4c8e4b):

  • cargo fmt --all -- --check: pass.
  • clippy -D warnings on the touched crates --all-targets: pass.
  • The CI wasm32 clippy step: pass.
  • nextest on core, binary-index, novelty, indexer, query, transact, ledger and spatial: 4,423 passed.
  • The whole fluree-db-api suite: 5,345 passed, including the cross-path matrix in both stored orders, the absent-value, range-revert, delete and Cypher tests, and fix(transact): write fidelity, part 2 — one fact identity, microsecond temporals, value reads #2109's eight multi-op matrix tests.
  • cargo check --workspace --all-targets: pass.
  • mdbook build: pass.
  • Not run: testsuite-sparql (untouched).

aaj3f added 21 commits October 19, 2026 16:24
A commit written before the staging fix can retract and assert one fact
at one t (a restating write of a subtyped big integer or a dateTime past
the microsecond; a merge or revert before the net-change fold). Lanes
resolved the pair differently: the full rebuild, the annotation arena and
the history replay kept the assertion; the incremental dedup, the query
overlay, novelty's fact state, core range, the stats fold and the batched
ref deltas kept the retraction; others kept whichever op came first. So
an answer depended on the path that served it, and a full rebuild changed
answers the live view had shown since the write.

`fluree_db_core::same_t` owns the rule: the assertion holds. `op_order`
is the sort key a walk ends on the winner under, `supersedes` the
streaming fold. Every lane goes through one of them:

- index: `resolve_transitions`, lifecycle dedup (`dedup_group`, which now
  keeps the losing retraction as superseded history, so an incremental
  merge writes the row and sidecar a rebuild does), the k-way merge's
  dedup, the annotation arena's sorts and folds, the spatial replay (a
  tie-aware resolver; the cell order on disk is unchanged);
- reads: `resolve_overlay_ops`, core `remove_stale_flakes` (which the
  binary scan now calls instead of its own copy), the batched ref deltas,
  fulltext's de-stale, `merge_latest_ref_objects`, export's untranslated
  fold, the attachment overlay;
- novelty: `NoveltyFactState::record`, the stats fold, and the net-change
  accumulator merge and revert use (by rule, not by position in the
  commit). `apply_commit` keeps an assertion its own commit retracts, as
  `bulk_apply_commits` already does;
- transact: `CurrentFacts`' key merge.

The reasoning overlay no longer drops a stored retraction a derived fact
restates at the query's t: the derived assertion holds by the rule.

A commit built here may not hold such a pair: `build_commit` refuses one
with a typed internal error naming the fact (`TransactError::SameTPair`),
found by `FactIdentity::same_t_pairs` over the staged view's SPOT order.
A view without both ops is passed over. Pushed, cloned, restored and
imported commits don't pass through `build_commit`. Rebase replays a
commit's flakes, so it resolves a pair to its assertion first
(`resolve_same_t_pairs`).
Stages a pair as a pushed commit (the transactor no longer builds one)
and requires the value present, once, live on the instance that took the
push, reloaded, at t-1 and t, in the ledger's stats, after an incremental
build and after a full rebuild: for a subtyped big integer and a dateTime,
in the default and a named graph, with the value indexed, in novelty only,
in a graph new to the index, and on a ledger never indexed.

Also: a local commit holding a pair is refused with a typed internal
error, a pushed one is taken verbatim, and a rebase replays one as its
assertion.
# Conflicts:
#	fluree-db-api/src/branch_validation.rs
The S2 section described an `idx:spatial` query that no query surface
parses: JSON-LD, SPARQL and Cypher never build an S2 search, so a query
written that way is read as ordinary triple patterns and returns nothing.
It now says so, keeps what the index side does (incremental builds write
the S2 cell index; a full reindex doesn't rebuild it; values since the
last build aren't in it), and labels the query examples as the planned
interface. The SPARQL troubleshooting note said `geof:sfWithin` evaluates
as a filter; only `geof:distance` is implemented, and other `geof:`
functions are reported as unknown. The design doc gets a status note.
…arses it

Runs the `idx:spatial` query the geospatial docs plan (`within` and
`intersects` over a polygon, indexed and in novelty only) and expects the
polygon found. No query surface parses `idx:spatial` yet, so today every
case returns `[]` while a plain read of the polygon succeeds. Ignored,
with the reason, so whoever implements the query can un-ignore it.
A commit can retract one fact under two terms at one t: novelty can hold a
big integer under two integer subtypes, which share an index key. The key
pairing kept the first retraction of a key and ignored the rest, so
resolving a legacy pair on rebase dropped one retraction and left the other
paired with the assertion, and the staging check then refused the rebased
commit. Every retraction of a key now pairs with its assertion.
A commit written before the staging check could hold a retraction and an
assertion of one fact at one t. Either way it leaves the fact present, but
reverting it has to restore what held before it, and the commit alone can't
say whether that was the fact or nothing. The undo's net change resolved
the pair to its assertion, and the stored-state filter then dropped it as
already present, so reverting a pair over an absent fact kept the value.

The accumulator now reports, for an undo, the facts whose deciding commit
held such a pair, and the revert reads each one's presence at that commit's
t - 1 (`CurrentFacts::at`): present, nothing is written for it; absent, it's
retracted. One point read per pair, batched by t; a range with no pair does
no extra work. Replay (merge, rebase) is unchanged.
A full rebuild's first stats pass counted every commit-log record by the
sign of its op, so a same-t retraction and assertion of a fact absent
before them netted to zero though the index holds the fact, and a
retraction of a fact never asserted counted minus one. (Both predate the
same-t rule: a commit pulled from elsewhere, or written before the staging
check, can hold either.)

The first pass now only observes records, for the sketches, last-modified
t and historical datatype tags. The counts (graph, property, datatype,
class) come from the second pass's k-way merge winners, one per fact the
index holds, which is what an incremental build counts against. The
sketch upload and finalize move after that pass. No extra pass or read.
Each fold the same-t rule decides now has a test that fails when that fold
alone goes back to retract-wins or first-seen:

- the cross-path matrix runs each pair stored assertion-first as well as
  retraction-first, since a fold that keeps the first op it sees passes
  one order by luck;
- a pair over an absent value, pulled verbatim, reads present, counts once
  in an incremental and a full-rebuild index, and reverts to absent (a
  present-value control reverts to present);
- a DELETE of a big integer that novelty holds under two subtypes, over an
  indexed ledger, names the pair the staging index-key merge has to see;
- the fulltext novelty fold (now one function the test calls), the
  metadata reference fold and the export fold of untranslated facts each
  get a unit test of both orders;
- a restating Cypher SET commits nothing, so it can't leave a pair.
Pairing every retraction of a key gave each key a Vec, one allocation per
retracted key in every slot that retracts and asserts a value whose index
key can merge terms (a double or big-integer upsert). One retraction per
key is the usual case, so it's held inline in a SmallVec; a second one
spills.
finish_with_pairs returns finish()'s output when nothing paired, so a revert range without a pair does no per-fact lookup.
Observing a record for the sketches went through the counting path with a
delta of 0, so the first pass still updated the graph, datatype and class
count maps for every record, now for nothing. The record's monotone part
(sketches, last-modified t, historical tags) and its counted part are two
small functions on the property accumulator; observing takes the first,
counting a present fact the second, and the incremental path's signed
counting both, with the one property lookup it had.
…ndex

The positions of an undo's same-t pairs only mean something against the
flake vector the fold produced, so the two are one value now, NetChange,
in CollectedCommitData. stage_revert takes it whole instead of two
arguments that could come from different places (which also brings it
back under clippy's argument limit). Replay users read `net.flakes`.
@aaj3f aaj3f added the bug Something isn't working as expected label Oct 21, 2026
@aaj3f
aaj3f requested a review from bplatz October 21, 2026 01:18

@bplatz bplatz left a comment

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.

Approving. The one-rule consolidation is solid and well tested, and the spatial replay change also fixes a bug on main today (editing a polygon within its own cells dropped the subject).

There's one real bug inline (undo_same_t_pairs, range revert); the rest are smaller. @aaj3f please go through the inline feedback before merging.

Comment thread fluree-db-api/src/branch_validation.rs Outdated
let mut keep = vec![true; inverted.len()];
for (n, present) in present_before {
if present {
keep[n] = false;

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.

Bug: "present before → write nothing" assumes the head still holds the fact. Revert the pair commit together with a later commit that deleted the value and it stays absent; it should come back. Reproduced for big integer and dateTime, both stored orders.

Fix: assert it instead (inverted[n].op = present;, drop the keep/retain). Staging treats it as a restatement when the head still holds it, same as a non-pair undo. With that, the probe below, the same-t file and the grp_ledger revert tests pass.

Probe (it_same_t_one_rule.rs)
#[tokio::test]
async fn range_revert_over_a_present_pair() {
    for kind in [Kind::BigInt, Kind::DateTime] {
        for order in [Order::RetractFirst, Order::AssertFirst] {
            let dir = tempfile::tempdir().unwrap();
            let path = dir.path().to_string_lossy().to_string();
            let id = "it/same-t-range:main";
            let commits = source_commits(kind, Path::NeverIndexed, None, order).await;
            let pair = pulled(&path, id, commits).await;
            let fluree = open(&path);
            let delete = fluree.graph(id).transact()
                .sparql_update(&format!("{PFX}DELETE DATA {{ ex:s ex:p {} . }}", kind.literal()))
                .commit().await.unwrap().receipt.commit_id;
            fluree.revert_commits("it/same-t-range", "main",
                vec![CommitRef::Exact(pair), CommitRef::Exact(delete)],
                ConflictStrategy::TakeSource).await.unwrap();
            fluree.disconnect_ledger(id).await;
            assert_eq!(values(&open(&path), id, None, None).await,
                vec![kind.lexical().to_string()], "{kind:?} {order:?}");
        }
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you, that's a real one. "Present before → write nothing" quietly assumed the head still held the fact, and a later commit in the same range can take that away. Went with your fix in 0b57271cf: the undo now writes the state before the pair either way (inverted[n].op = present, keep/retain gone), and staging takes it as a restatement when the head already agrees, same as any other undo.

Your probe is in as a_range_revert_from_a_pair_restores_what_held_before_it, widened a bit: big integer and dateTime, both stored orders, reverted from novelty and from an index, plus the absent-before side (a string and a big integer), which has to stay absent. Before the fix all 8 present-before cells come back []; with it they pass, along with the rest of the same-t file and the grp_ledger revert tests.

// one fact at one `t`: staging cancels the two by fact identity, so a
// pair is a staging defect, refused rather than written. Commits that
// arrive whole (push, clone, restore, import) never pass through here.
check_no_same_t_pair(&view)?;

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.

Worth a sentence in the PR: any staging lane that misses the identity now shows up as a 500 on a user write instead of a quietly kept pair. I couldn't find one, and fail-closed seems right; just making the trade explicit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, and I think fail-closed is the right side of it too. Added a sentence under the staging invariant in the PR body making the trade explicit. fwiw I re-checked the lane that landed on main since (#2144's FlakeAccumulator netting) after merging it in: it keys by FactIdentity and stages nothing for a fact both retracted and asserted, so it agrees with the check.


/// Current facts of `ledger` as of `to_t` (at most `ledger.t()`): the
/// index read as of `to_t`, and novelty up to it.
pub fn at(ledger: &'l LedgerState, to_t: i64) -> Self {

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.

named_by and the slot reads honor to_t, but whole_graph still reads at head. Revert doesn't hit it; either honor to_t there or say so in the doc so the next caller doesn't trip on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair. Went with honoring it rather than documenting the gap (519b0234c): whole_graph passes to_t like the other reads now. At the head it's the same read as before, since range_with_opts fills to_t from the head when it's unset, so graph sync / CLEAR / DROP / COPY / MOVE don't change. whole_graph_reads_as_of_to_t pins it, and fails with the old options.

Comment thread fluree-db-transact/src/current_facts.rs Outdated
.iter()
.filter_map(|p| {
spot.iter()
.find(|(_, f)| std::ptr::eq(*f, p.retraction))

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.

A linear find per pair makes this O(pairs × n). Fine for restating-write pairs, but a legacy merge commit can hold a lot of them. Carrying positions through same_t_pairs (or using a pointer set) avoids it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, fair for a legacy merge commit. same_t_pairs now hands back each retraction's position in the sequence it walked (SameTPair::retraction_at), so resolve_same_t_pairs maps it back through spot with one lookup per pair (519b0234c). resolving_pairs_drops_each_retraction_wherever_it_sits covers flakes out of SPOT order with term and key pairs mixed in, one of them behind another value of its slot (d8b6cd8cf), and fails if the position isn't mapped back through the sort or the run offset is dropped. The walk only picked up a running counter, and it runs in the staging check on every write that both retracts and asserts, so I measured it: a 600-flake insert, 400-flake integer and double upserts and a 20,000-flake upsert are all within ±0.5% in instructions, with the same allocations.

Comment thread fluree-db-api/tests/it_spatial_query.rs Outdated
/// A polygon inside the query region is found by `within` and
/// `intersects`, whether the index or novelty holds it.
#[tokio::test]
#[ignore = "no query surface parses idx:spatial yet; see the S2 spatial-query issue"]

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.

Nit: this is an ignored test for a surface that doesn't exist yet. I'd park it in #2152 rather than land it here. The doc corrections are good to keep.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, dropped it here (e5699f576) and kept the doc corrections. Parked its content on #2152 (#2152 (comment)) so whoever picks up the query surface can start from it.

// flake the walk yields first, so this lane answers as
// `resolve_current_flakes`, `resolve_overlay_ops` and every
// index build do.
if supersedes((flake.t, flake.op), cur) {

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.

Nit: this lane decides class-based policy grants, so a same-t rdf:type pair now grants. That's consistent with every read path, so fine, but maybe name the policy effect in the behavior table.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, named it in the behavior table: a subject whose rdf:type the overlay holds as a same-t pair now has that type in the batched ref lookup, so a class-based policy on that class applies to it, the same way every read path already sees the type.

aaj3f added 2 commits October 26, 2026 12:28
# Conflicts:
#	fluree-db-novelty/src/lib.rs
#	fluree-db-transact/src/commit.rs
…ead holds

Undoing a commit that held a same-t pair wrote nothing for a fact that was
present before it, on the assumption that the head still held the fact.
Reverting the pair's commit together with a later commit that deleted
the value then left it absent instead of restoring it. The undo now
writes the state before the pair either way, asserted or retracted, and
staging takes it as a restatement when the head already agrees, as it
does for any other undo.
aaj3f added 4 commits October 26, 2026 13:04
It runs a query surface that doesn't exist yet. It belongs with the issue
that tracks that surface rather than in this branch; the geospatial doc
corrections stay.
resolve_same_t_pairs found each pair's retraction by a linear search of the
sorted references, O(pairs x n), and a legacy merge commit can hold many
pairs. same_t_pairs now names each retraction's position in the sequence
it walked (SameTPair::retraction_at), so the drop is one lookup per pair.

CurrentFacts::whole_graph read at the head while every other read there
honors to_t, so a CurrentFacts::at reader got the head's graph. It reads
as of to_t now; at the head that's the same read as before (range_with_opts
fills to_t from the head when it's unset).
Pins the run offset in same_t_pairs' positions: a pair in a slot's second run of equal objects.
Clippy's type_complexity on the positioned retractions map; a type alias, no change in behavior.
@aaj3f

aaj3f commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review! Went through all six:

  • the range revert: fixed and pinned (0b57271cf), details inline;
  • the 500-vs-quiet-pair trade: called out in the PR body;
  • whole_graph honors to_t now, and pair resolution carries positions instead of the linear find (519b0234c, d8b6cd8cf);
  • the ignored spatial test is out (e5699f576), the doc fixes stay, and its content is parked on S2 spatial queries (idx:spatial) aren't reachable from any query surface #2152;
  • the policy effect is named in the behavior table.

Also merged main (eaa4c8e4b) in c4f911b39. Two small conflicts, both resolved keeping both sides: commit.rs (#2112's index-loaded check next to the same-t check) and novelty's apply_commit (#2159's list predicates, which the restated assertions the commit keeps now register too). Local gates are green at the head (details in the PR body), and CI is running on it now.

@aaj3f
aaj3f merged commit 4ffb529 into main Oct 26, 2026
19 checks passed
@aaj3f
aaj3f deleted the fix/same-t-one-rule branch October 26, 2026 20:42
bplatz added a commit that referenced this pull request Oct 31, 2026
Brings #2217 (SPARQL reads list members as values; CONSTRUCT writes lists),
#2218 (schema writes judged by modify policy), #2208, #2169, #2168, #2153,
#2149 and #2148 into next.

Resolutions:
- Nameservice: branch_records is the one branch listing (strict, retracted
  branches kept for GC) on every backend, resolved through next's bindings;
  Fluree::list_branches filters retracted ones. The lifecycle conformance
  suite reads live branches through a helper. DynamoDB's narrow listing is
  wired into its trait impl.
- JSON-LD adapter: main's graph scoping (Walk, Scope, node_graph, selectors)
  with next's triple terms, @annotation, @reifies, blank-label and number
  datatype handling. to_graph_events writes a JSON-LD named graph under its
  @id and refuses a graph selector. main's f:reifiesGraph anchor is dropped:
  next writes an annotation as an rdf:reifies link in its graph.
  emit_quad_list_item takes (graph, index).
- Bulk import: an annotation's link is written to the graph its slots name,
  and a triple-term statement in a named graph is spooled under that graph
  (both landed in the default graph); emit_quad_reified_triple is
  implemented. resolve_object_value keeps main's vector refusals and next's
  term-table path.
- Ledger manager: a store that fails to load fails the load or keeps the
  reloaded ledger's state (main), over next's load_decoding_root and
  activation swap rule.
- Novelty keeps main's KeptEffects without the retired arena's reifies
  capture. The pool's resolve_events_at and compaction's split_lifecycles
  follow fluree_db_core::same_t.
- Retired annotation arena files stay deleted.
- Tests from main adapted to next: one Fluree per storage directory, async
  genesis_ledger, storage-namespace content stores, u32 graph ids, a store
  broken by hiding a dictionary branch (next has no disk cache), a refused
  import leaving no ledger. next's tests that pinned bulk import refusing
  @graph and SPARQL's RDF list view now check what main changed them to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants