Skip to content

fix(transact): write fidelity, part 2 — one fact identity, microsecond temporals, value reads - #2109

Merged
aaj3f merged 52 commits into
mainfrom
fix/write-fidelity-part2
Oct 20, 2026
Merged

aaj3f merged 52 commits into
mainfrom
fix/write-fidelity-part2

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

#2008 merged from its first-round head plus 007aa2983. This PR brings the rest of its review rounds, reconciled with 007aa2983. It fixes a class of silent value loss that the merge left on main, and it removes a per-delete cost that #2008 added.

Partially addresses #2087: a delete naming a few values of a wide slot now reads just those values. The constant-object DELETE over many subjects still reads one slot per subject.
Partially addresses #2090: an identical re-upsert or re-sync keeps a value stored with less detail than written, and a dateTime or time is held to the microsecond, query constants included, for equality and ordering alike. 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.

Why: what main loses today

On main (c5874d586), a write that retracts a stored value and asserts the same value commits both, if the index keeps less of the value than the write carries:

  • a big integer with an XSD subtype;
  • a dateTime or time past the microsecond.

They commit at one t, and storage resolves them as the retraction. The value is gone after the write and stays gone after the next index build.

This hits DELETE { x } INSERT { x } WHERE {}, its JSON-LD twin, Transaction delete-then-insert, and DELETE DATA x ; INSERT DATA x, on indexed and partly indexed ledgers. It also hits an identical upsert or sync of such a value. Measured with a 420-case probe of restating writes (lanes × value kinds × index states × graphs):

Three more operations lose a big integer with an XSD subtype the same way: COPY and MOVE onto a graph that holds it in its index, from a graph that holds it since the last build; and a revert or a non-fast-forward merge of a range that deletes it under one subtype and writes it under another, on an indexed ledger (a revert at once, a merge at the next build; checked on main at 57bf7a944).

A DELETE DATA of a sub-µs dateTime or time on a ledger never indexed does nothing once the ledger has been reloaded. Before #2008 it deleted.

A delete naming one value of a wide slot reads the whole slot: 3.9 / 16 / 65 / 127 ms at 1k / 5k / 20k / 40k values (debug build).

What changes

Area Commits What
One fact identity f7151f883, 4f7550181, 7423627e6, 233d0941b, bb24623e4, f240eb7fd, a3596467d, 1ea595170, af53c8110, ddd9bbee9, 8960668d1, 59e86424b, f0ee77742, a89bf9e30 FactIdentity is the one rule for when two facts are the same, and it is how storage keeps them. A big integer is one fact per value and list position. A kind whose index key can merge terms is one fact per key and list position. Every other value is its term. It is used in seven places: the accumulator of an operation that both retracts and asserts; the multi-operation fold; the DELETE resolver, which names the stored fact a DELETE DATA or template constant retracts; CurrentFacts::named_by; ADD/COPY/MOVE, which compare the source's facts with the destination's by identity in the destination graph (FactIdentity::in_graph); merge and revert, which net a range of commits with a big integer keyed by value and then name the net change as the target stores it; and a write-verb policy's check that a retract-only subject is fully removed. So a restating write commits nothing and keeps the value; an identical upsert or sync is a no-op; INSERT x ; DELETE x deletes; and a transfer leaves a fact both graphs hold in place. In the fold, a fact whose first and last ops are both retractions keeps its first retraction, which was staged against the base and names the fact as stored. A DELETE names a fact by its identity whichever op of it survived, read from the index or from novelty, a big integer by value whether indexed or not (f0ee77742); novelty holds the subtypes of one big integer apart until the next build, so a retraction of the fact retracts every term the base holds of it, in the resolver, the fold and merge/revert (a89bf9e30, CurrentFacts::all_named_by). The write-verb check (59e86424b) closes a regression from earlier rounds of this branch, not one on main: once a retraction names a fact as storage holds it, comparing it with the pre-state read by term called a full removal on an indexed ledger an update.
Temporal precision 18c200200, 140717905, 26d2be888, 1c3740dbc, b70bee8cc, dfaaa858e, 25cdfe4d4 A dateTime or time is held to the microsecond the commit writes and the index keys, from the moment it is read: every write lane, a query constant, deserialization. A query constant past the microsecond compares as the value written with it, for equality and ordering alike, so exactly one of <, = and > holds against a stored value, a constant inline answers as one bound through BIND or VALUES, and >= on a timestamp a client wrote with nine digits finds its record. A plain string compared with a temporal value is read to the microsecond too. It is not value-equal to one, as on main, so the docs state that trichotomy for typed temporal operands only. (dfaaa858e replaces 26d2be888's every-digit ordering, as decided in review.) Iceberg nanosecond timestamps round down to the microsecond. A table timestamp before 1970 renders on its own day.
Push validation ba07c214d A pushed commit may retract a value the target holds in its index: in a named graph, or a big integer under its subtype. Both were refused with "retract targets non-existent assertion".
Value reads b146d1098, 3eace56c1, b65e4a63b, dab422f84, d01072aeb A delete naming a few strings or references of a wide slot reads just those values (one seek each) instead of the slot. The bound, a sixteenth of the slot's expected width, is fitted over every count it admits.
Stored-fact read 73e28b254, cf4522b22, 79fa40f00 Ops sharing an index key are one stored fact, newest wins, in the read every retraction comes from. DELETE intents resolve in time linear in the slot. A witnessed row is retracted as decoded only when the decode is the stored term. A double's decode always is, now that #2044 keys ±INF and NaN, so novelty holding one no longer makes a delete read its slot. This replaces 007aa2983's SlotMatcher; see Reconciliation.
RDF text a8bd0cfbb, 40f481de4 An upsert's blank-node scope hashes its statements as stored: 1 and "1"^^xsd:integer are one statement, a tag in any case is one, and a statement written twice counts once. A GRAPH <urn:default> block gets the urn:default refusal on every lane.
Call 2 aa1b3e6be, e4fd65f67, 3ebb552b5 It reverts "a DELETE can name a stored ill-typed literal" to #1988's strict refusal, as ruled in the review. 3ebb552b5 adds the JSON-LD twin of SPARQL's test for it.
Smaller 9b7cc1a0e, 44d5f4bef, 4984d1d6b, e3de4b1ac The txn-meta resolver's debug assertion accepts f:reverts, f:message and f:author; an index build over such a commit panicked in debug builds. upsert.md shows how to replace one language. FactIdentity resolves a fact's graph only for a value with an index key, so the fold no longer decodes the graph of every string and reference. e3de4b1ac names every term of a fact without allocating a vector per identity key or per item.
Tests only 898b2ccbb, ce9e6c197, edea2bdf5, 8698db279, 7e0b63aae, 2446d0fca, 43c2bb253, 18369233e Retained from the review rounds; each still passes against main's code where main has the fix. 43c2bb253 makes the index state at every read of this PR's file-backed tests the test's own (see Tests). 18369233e splits the multi-op matrix into one test per base state and value kind, so they run in parallel.

Reconciliation with 007aa2983

007aa2983 answered the same first-round review items independently. Per item:

Item Kept Why
Unclosed bracket in a graph block main's Same fix, same test.
fluree sync fallback on the v4.2.0/4.2.1 400 main's Same fix.
ADD/COPY/MOVE restatement under a policy main's Same behavior. This PR adds a MOVE case (add_copy_and_move_are_refused_regardless_of_destination_contents).
A delete naming a new graph main's Same behavior. main's keeps the routing consistent, which this PR's per-graph SHACL test (shacl_per_graph_mode_reaches_a_new_graph_beside_one_only_deleted_from) confirms.
it_join_batched_overlay main's Same change.
Stored-fact read: ghost fact after a revert, wide-slot indexing, identical list entries this PR's The identity, the value reads and the witness flag are built on this resolver. Every test 007aa2983 added passes against it unchanged: a_reverted_indexed_big_integer_can_be_written_again, a_where_driven_delete_removes_every_identical_list_entry, a_delete_in_a_new_graph_commits_nothing and the transfer tests. A witnessed row comes from one stored fact, so rows and facts match one to one; a repeated row retracts each fact once.
Blank-node identity spelling this PR's main documents a spelling-sensitive identity. This makes it spelling-insensitive, which changes which documents re-mint (see Upgrade notes).
Call 2, ill-typed literal in DELETE DATA the revert main keeps the first-round behavior and documents it in datatypes.md; the review's ruling on call 2 was the strict refusal, so this PR reverts it and datatypes.md shows the removal through a variable.
A doc comment in it_delete_stored_facts.rs fixed 007aa2983 placed the transfer test's doc paragraph under restating_a_viewable_value_commits_nothing_without_modify.

Behavior changes against main

Case main This PR
DELETE { x } INSERT { x } (SPARQL, JSON-LD, Transaction) or DELETE DATA x ; INSERT DATA x, where x is a big integer with an XSD subtype or a dateTime/time past the µs, on an indexed ledger value lost nothing committed, value kept
Identical upsert or sync of such a value value lost nothing committed
COPY/MOVE where the destination holds a subtyped big integer in its index and the source holds it since the last build value lost from the destination kept
ADD where the source holds a subtyped big integer in its index and the destination holds it since the last build a second term asserted beside it nothing asserted
Revert or non-fast-forward merge of a range that deletes a big integer under one subtype and writes it under another, on an indexed ledger value lost (a revert at once, a merge at the next build) the range's last op on that value applies
INSERT x ; DELETE x of such a value, the two spelled alike or under different subtypes value kept (not deleted) deleted, retracted as stored
DELETE DATA of a big integer under one subtype where the ledger holds it under another, not yet indexed or indexed with a later subtype in novelty nothing deleted deleted
A delete of a big integer novelty holds under two subtypes one term retracted: present until the next build, absent after every term retracted
A write that changes only a big integer's XSD subtype value lost when indexed; lost at the next build when not yet in the index nothing committed, value kept
DELETE DATA of a sub-µs dateTime or time after a reload no-op deletes it
A dateTime or time written past the microsecond held as written until a reload or index, six digits after six digits everywhere
A query constant past the microsecond = never matches a stored value; <, > order by every digit =, <, > (and <=, >=, VALUES, a pattern's object) compare against the value held to the µs
A plain string compared with a dateTime/time constant past the microsecond ordered by every digit ordered as the value it reads as, held to the µs
Push retracting a value the target holds in an indexed named graph, or a big integer under its subtype refused accepted
A delete naming a few strings or references of a wide slot reads the slot, linear in its width one seek per value
Blank-node identity of an RDF-text upsert depends on spelling statements as stored
DELETE DATA of an ill-typed literal names a stored one refused, as #1988 had it

Upgrade notes

  • A dateTime or time with more than six fractional digits reads back, and compares, with six. That includes a query constant: >= the nine-digit constant a value was written with now finds it. Applications that need more should store it as its own property.
  • Turtle or TriG upserts with blank nodes whose spelling differs from what is stored (1 against "1"^^xsd:integer, tag case, a statement written twice) mint their blank nodes once more on the first upsert after upgrading; later upserts of the same document commit nothing. The orphan query in turtle.md lists the earlier nodes.

Tests, non-vacuity, gates

Tests (new, besides those 007aa2983 added, which pass unchanged):

  • a_write_that_restates_a_stored_value_keeps_it: seven lanes (SPARQL and JSON-LD delete-and-insert in the default and a named graph, JSON-LD and Turtle upsert, graph sync) × five values × index-only and index-plus-novelty slots, read after the write and after the next index build.
  • a_multi_op_update_ends_where_its_last_op_leaves_a_value and its seven siblings (one test per base state and value kind, through multi_op_last_op_matrix): every one- and two-op sequence over the stored spelling and another, every three-op sequence whose first and last ops spell the value differently, and the longer ones, × five base states (the value absent, in novelty, indexed, held in novelty under two subtypes, and indexed with a later subtype in novelty) × a subtyped big integer and (on the first three bases) a dateTime past the microsecond; the one- and two-op sequences also run as one request per op. Each case is read in process, reloaded, after an incremental build and after a full rebuild.
  • a_transfer_keeps_a_value_both_graphs_hold: ADD, COPY and MOVE × a big integer under the same and another subtype, a dateTime past the microsecond and a string × an indexed destination with a novelty source and the reverse × a named and the default graph. The destination is read in process, reloaded, after an incremental build and after a full rebuild; the source reloaded and after the full rebuild, and after the incremental build wherever an incremental build can't bring back a deleted fact (not after a MOVE out of a graph first written since the base; that is fixed separately in fix(indexer): a fact deleted before an incremental build stays deleted in a graph new to the index #2118).
  • merge_and_revert_keep_a_big_integer_written_under_another_subtype: revert and a non-fast-forward merge, on an indexed and a never-indexed ledger, and a revert of both writes of a value novelty holds under two subtypes, read after the write and after the next build.
  • a_full_removal_is_a_delete_whichever_term_names_a_fact: a write-verb policy with a delete-only and an update-only grant, a full removal on SPARQL and JSON-LD, indexed and never indexed, with a language-tagged value and a list beside the big integer.
  • multi_op_reversal_nets_a_value_the_index_keeps_less_of, changing_a_big_integers_subtype_keeps_it (four index states × three lanes), a_write_retracting_a_value_a_list_holds_twice_retracts_both_entries, the two identical re-upsert tests (un-ignored), and named_by unit tests.
  • a_push_retracts_values_the_target_holds_in_its_index (a named graph, a subtyped big integer).
  • jsonld_transactions_reject_ill_typed_literal: a JSON-LD insert, delete, and delete with a where refuse an ill-typed literal, beside SPARQL's sparql_update_rejects_ill_typed_literal.
  • it_temporal_storage_precision: every write lane (JSON-LD, SPARQL, Turtle and TriG insert and upsert, graph sync, Cypher, Transaction, push, bulk import) before and after a reload; a DELETE DATA as written; query constants in process, reloaded and indexed; <, <=, =, >=, > against constants at, past and either side of the stored microsecond, inline, cast, on the left and through BIND/VALUES (SPARQL), as a string and through values (JSON-LD), and as Cypher datetime()/time(), including >= on the nine-digit constant the value was written with; a plain string against a constant past the microsecond, both ways round.
  • it_delete_point_reads: value reads stamped by DELETE_POINT_READ_SITE and checked against the slot read.
  • Units for deserialization, the lexical ordering (a_lexical_is_ordered_as_the_value_it_is_held_as), net-change keying (a_big_integer_nets_by_value_across_subtypes), both Iceberg readers, the R2RML timestamp rendering, and a double's index key (no_double_loses_detail_to_its_index_key, and a_lossy_term_assertion_sets_the_flag over ±INF and NaN). A transact_delete_wide_slot bench.

This PR's file-backed tests run without the background indexer and build the index themselves (43c2bb253), so the index state at each read is the test's: CI's red run of the transfer test at ddd9bbee9 was the background indexer's incremental build reviving the MOVE source between the transfer and the read. A full rebuild that follows an incremental one is published through Fluree::reindex, since publish_index keeps an index whose t is not newer.

Non-vacuity. Each fix was undone and its tests run (--all-features); every one failed for the fix's reason. A mutation counts as caught only when a test fails; a build that never ran is not counted. Rows marked † were run in this round; the rest at the heads that added them.

Mutation (undone) Tests that fail
Staging attaches no fact identity a_write_that_restates_a_stored_value_keeps_it, an_identical_reupsert_keeps_an_indexed_big_integer_subtype, changing_a_big_integers_subtype_keeps_it
The accumulator ignores the identity the same three
The multi-operation fold keys by term multi_op_reversal_nets_a_value_the_index_keeps_less_of, changing_a_big_integers_subtype_keeps_it
† The fold keeps the last op's retraction when the first and last ops both retract (af53c8110) a_multi_op_update_ends_where_its_last_op_leaves_a_value (the review's case reads 1, 1, 0, 0 where 0 is expected throughout)
† ADD/COPY/MOVE compare facts by term (ddd9bbee9) a_transfer_keeps_a_value_both_graphs_hold: its 12 big-integer cases
† Merge and revert as on main (all of 8960668d1) merge_and_revert_keep_a_big_integer_written_under_another_subtype: revert and merge on the indexed ledger
† Merge and revert net by term, naming kept the same test: revert on both ledgers
† Merge and revert don't name the net change as stored the same test: revert on the never-indexed ledger (two rows until the next build)
† A write-verb policy's full-removal check by term (59e86424b) a_full_removal_is_a_delete_whichever_term_names_a_fact: the four indexed attempts
† The DELETE resolver, the fold and merge/revert as at 3ebb552b5 the multi-op matrix: 72 cases in its five big-integer tests, among them INSERT DATA x^^nonNegativeInteger ; DELETE DATA x^^integer on the indexed base, as one request and as two; merge_and_revert_…: the revert of both subtypes
† A DELETE names a fact by key only when its surviving op was read from the index the matrix (before its two extra bases): 29 cases
† A DELETE names a big integer only through a key the index holds the matrix (before its two extra bases): 19 cases, on the bases without an index
† A DELETE retracts only the term it names the matrix (before its two extra bases): 2 cases (novelty holding two subtypes, one request per op)
† The fold retracts one term of a fact the base holds under two the matrix: 17 cases on the two-subtype base
† Merge and revert retract one term of such a fact merge_and_revert_…: the revert of both subtypes
† A JSON-LD delete reads an ill-typed literal leniently (main's parser) jsonld_transactions_reject_ill_typed_literal (the delete retracts the stored literal)
named_by matches by term only a_push_retracts_values_the_target_holds_in_its_index, multi_op_reversal_nets_a_value_the_index_keeps_less_of
named_by matches every item against the first slot named_by_names_a_stored_fact_and_nothing_else
The identity key drops the list position a_write_retracting_a_value_a_list_holds_twice_retracts_both_entries
A big integer keyed only through the index's arena changing_a_big_integers_subtype_keeps_it, named_by_names_a_big_integer_by_value_its_own_term_first
named_by matches by key before term named_by_names_a_big_integer_by_value_its_own_term_first
No microsecond truncation; dateTime alone; time alone it_temporal_storage_precision (up to nine tests), the restate, fold and re-upsert tests
† The every-digit ordering restored (dfaaa858e's code undone) a_constant_is_held_to_the_microsecond_for_ordering_too, a_cypher_constant_is_held_to_the_microsecond_for_ordering_too, a_string_is_ordered_against_a_temporal_at_the_microsecond
DateTime / Time deserialized without truncation a_deserialized_temporal_is_held_to_the_microsecond
Iceberg nanoseconds rounded toward zero int96_rounds_down_to_the_microsecond, nanosecond_timestamps_round_down_to_the_microsecond
The truncating timestamp render a_timestamp_before_1970_renders_on_its_own_day
A non-finite double counted as losing detail to its key no_double_loses_detail_to_its_index_key, a_lossy_term_assertion_sets_the_flag

On main (57bf7a944), the same multi-op matrix fails 172 cases: the big-integer ones on every base, and 79 dateTime ones, whose spellings main keeps apart.

Doubles and nulls in merge and revert. The net change keys only a big integer by value; a double or a null is netted by term and then named against the target. For a double nothing is lost: FlakeValue's equality and hash treat ±0 and every NaN as one value, as the index key's encode_f64 does, and the key's type follows the datatype, so the term is the key. Revert and merge of 0.0/-0.0 both ways and of NaN keep the value on main (57bf7a944) and on this branch, indexed and not. Nulls share one key whatever their datatype, but no write lane produces one: JSON-LD null and Cypher NULL are refused at parse, and SPARQL has no null literal.

Perf against 3ebb552b5, in release, measuring retired instructions and allocations per write over 7 runs in each of 2 interleaved rounds. All of these are within run-to-run spread:

  • the two transact_delete_wide_slot scenarios at 1k, 5k, 20k and 40k values;
  • a DELETE DATA of one indexed big integer, under its own subtype and under another;
  • a three-operation delete of 600 strings and references;
  • a fold reversing 300 strings or 300 doubles (each allocates about 21 KB less);
  • an insert-only control.

The first measurement found two costs, which e3de4b1ac removes: the multi-operation delete allocated 33.6 KB more, because SlotFacts was larger for every slot read, and the double fold made 301 more allocations, a vector per identity key.

Gates at e3de4b1ac, with all features (local, mirroring CI): cargo fmt --all -- --check; clippy -D warnings on transact and api (all targets); a workspace cargo check --all-targets --all-features at the merge 8ef028c82; the whole fluree-db-api suite (5,121 passed, 28 skipped), including grp_transact (349), grp_query (531), grp_query_sparql (513), grp_misc (395) and grp_policy (143). At 18369233e, grp_transact ran 5 more times in full, and the eight multi-op matrix tests 20 more times, the first five alongside the full runs, without a failure; the slowest matrix test took 237 s under that load (about 33 s on a quiet machine), within nextest's 360 s limit. Ran at 3ebb552b5 and not re-run here, since this round changed only transact and api: clippy on query, sparql, cypher and novelty, those crates' library tests, and the W3C suites. Not run locally: the default-features clippy, the server with no optional features, the CLI, doc tests, the other crates' suites and the wasm32 jobs; CI runs them.

Merges with main

287357987 merges main at ba694ee79 (#2019, #2044) into this branch as a merge commit, so the commits above keep their SHAs. One file conflicted, fluree-db-query/src/eval/compare.rs: #2044's ordering of doubles is kept as it is, and a temporal compared with a string goes through fluree_db_core::temporal::cmp_with_lexical, as on this branch, inside #2044's ValueOrder. Against ba694ee79 that file differs only by this branch's change. The 420-case probe answers as it did before the merge in every case, at the merge and at the head. Run over five doubles (INF, -INF, NaN, 1.5, -0.0), its 210 cases answer as a string does, except that a -0.0 written since the last index build reads back as 0.0 after the next one; that is the -0.0 item of #2090 listed above.

Against main. The 420-case probe that finds the 36 losses on main finds none on this branch, and neither do the delete-after-reload and subtype-change probes. Across these probes this branch answers as the reviewed rounds did, except for one datatype read before a reindex (the value is there either way) and a push the big-integer keying now accepts, where the target holds the value under another subtype.

d7059102e merges 5b23362d6 (#2046, #2048, #2049, #2052, #2053, #2056, #2068). It merged without conflicts beyond #2056's txn-meta allowlist, which is kept as is, and the P1 probe's 420 cases are byte-identical to the run at 79fa40f00.

451eff0d7 merges f3c3b00ec (#2010, #2096, #2097, #2098, #2101, #2102, #2108) without conflicts. #2010 changes how the query side compares an encoded binding with a decoded term; this branch's temporal and big-integer tests, and #2010's own it_query_optional_encoded_bindings and it_novelty_encoded_equality, pass together.

6208e94f0 merges 57bf7a944 (#2120, #2009). Two files conflicted:

8ef028c82 merges 1d06ae2ef (#2119) without conflicts.

Solo lockstep

No solo change is needed.

  • Values solo writes from chrono::Utc::now().to_rfc3339() (nine digits on Linux) read back with six.
  • The one temporal range filter in solo's queries is the identity store's keyset paging (fluree-lambda-identity, store.rs:2508: FILTER(?at < "{at}" …)). Its cursor is a value read back from the ledger, so it has at most six fractional digits, and the comparison answers the same whether the string is read to the microsecond or by every digit.

aaj3f added 30 commits October 12, 2026 09:00
This reverts 987a937, "fix(transact): a DELETE can name a stored ill-typed
literal", as pushed for review round 1.

DELETE DATA and DELETE templates refuse an ill-typed literal
("abc"^^xsd:integer) again, as #1988 left them, so a DELETE template
agrees with DELETE WHERE, with a WHERE constant and with a query
constant. #1987's test is back as it was.

The reverted message overstated what it changed. It said DELETE WHERE
templates could name such a literal, but the WHERE half of a DELETE
WHERE still lowered strictly and refused it, so a DELETE WHERE naming
one failed before that commit and after it. Only DELETE DATA and a
DELETE template over an empty WHERE had become lenient.

A stored ill-typed literal is removed through a bound variable
(FILTER(STR(?o) = "abc")), or replaced by an upsert or a graph sync.
datatypes.md said JSON-LD transactions and SPARQL UPDATE reject a literal
that is not a value of its datatype, and that Turtle keeps one. It did
not say how to remove one that is stored. A DELETE cannot name it as a
constant; it binds it through a variable, with FILTER(STR(?o) = …), or
an upsert or a graph sync replaces the property's values.

#1987's ill_typed_literals_keep_their_lexical_form already deletes one
through a bound variable over an index; a new test replaces one with an
upsert, over novelty and once indexed.
…slot

One subject holds n values of one predicate (1k/5k/10k/20k by scale) in a
bulk-imported ledger, and the measured transaction deletes all of them:
a JSON-LD delete naming each value, and a WHERE-witnessed delete on a
ledger that stores one list elsewhere, so every row reads its slot for a
list position. The other delete and upsert benches put one value in each
slot, so a cost that grows with a slot's values times the intents naming
it does not show in them. Setup asserts the fixture is indexed and on the
intended side of the list gate; each measured delete asserts it retracted
all n values.
The binary scan decodes every big number with dt_id = DECIMAL, because it
cannot tell an overflow integer from a decimal without decoding. Since
#2012, materialize_one_binding takes an overflow integer's datatype from
the decoded value (resolve_dt_id_sid_for_value), so a DELETE WHERE over an
indexed big integer stages its retraction with the xsd:integer the value
is stored with, not as (BigInt, xsd:decimal).

That matters to the resolver as well as to the commit. Storage merges ops
by index key, so a decimal-typed retraction did remove the value from
queries, but the resolver compared it by term and still read the indexed
xsd:integer fact as current: an upsert of the same value afterwards
restated it and committed nothing. Tests: that DELETE WHERE and upsert,
and the datatype the retraction records.
…cts as storage does

folded index rows with novelty ops by term. 007aa29 indexed each slot
once (SlotMatcher), dropped an index row whose key a novelty op holds, and
retracts every list entry holding a witnessed row's term. This replaces
that resolver with the one the rest of this PR builds on: the shared fact
identity, the value reads and the witness flag. 007aa29's tests pass
against it unchanged.

- The read merges ops the way storage does before the term fold: per
  predicate, index key and list position, the newest op wins, and on one
  t the retraction, for index rows and novelty ops alike (queries over
  novelty merge by key too, in resolve_overlay_ops). Keys are computed
  only for the kinds of value whose key two terms can share, named by an
  exhaustive match beside the key encoding; a read of strings, IRIs or
  integers computes none.
- One DeleteResolver per transaction. A slot with more than 16 facts is
  read once and grouped once: by term (value, datatype and lowercased
  tag, hashed; a collision compares terms), by index key when an intent
  first needs one, and list entries by position. Each intent or row is a
  lookup. Slots of 16 facts or fewer are scanned.
- A witnessed row is matched to the stored facts its decode can be: list
  entries in slot order, then the plain value, by index key for a kind
  whose key can merge terms. The k-th identical row of a slot, counted
  across WHERE batches, takes the k-th of them. A WHERE yields one row per
  stored fact it matches, so each fact is retracted once, as 007aa29
  does; a row past them, from a join repeating rows, takes the last again
  and the accumulator collapses it. Intents a WHERE does not witness keep
  their contract: one list entry per distinct DELETE row.

Tests: a revert of an indexed big integer written with a subtype, then
an upsert that must write it again; an ignored test for what remains
between two novelty ops of a sub-microsecond dateTime (closed by the
microsecond precision later in this PR); identical rows over
["v", "v", "w"] in one batch and across batches; a value stored as an
entry and plain; the first-entry rule for intents not witnessed; the
indexed path answering as the scan on a mixed slot and with every term
colliding in one hash group; and through the API, a WHERE-matched delete
of both shapes empties the slot on SPARQL and JSON-LD, over novelty and
indexed.
007aa29 made ADD, COPY and MOVE judge a destination fact the transfer
restates as a restatement, so whether a transfer into a graph the
identity cannot view succeeds no longer depends on what that graph
holds. These tests pin it beyond its own ADD and COPY case: MOVE as well,
with the source holding a value the identity may change beside one it
may not; and a restated fact the identity can view commits nothing
without modify permission, and as root.
An upsert of RDF text scopes its blank nodes by the document's content,
so the same document upserted again addresses the same nodes. The
identity hashed literals as spelled: `1` and "1"^^xsd:integer, `true` and
"true"^^xsd:boolean, @en-us and @en-us, and 1.0 and 1.00 each gave two
identities, and a statement written twice counted twice. A re-upsert
spelled another way minted new blank nodes and left the old ones.

A literal is now hashed as it is stored, on both of the sink's literal
paths: its value, its datatype, and its language tag lowercased, as tags
compare. A decimal is hashed by value without its trailing zeros, with
no allocation when its mantissa fits an i64. A statement written twice
counts once. IRIs were already hashed in full however written. Renaming
a blank-node label still gives new nodes: making that canonical needs RDF
dataset canonicalization, a follow-up. upsert.md and turtle.md say what
the identity covers.

The identity is computed only where it is used: by an upsert with no
caller-supplied skolem scope (parse_rdf_text takes a ContentIdentity),
and only for a document with a blank node, the one thing it scopes.
Every other lane — insert, sync, the Graph Store routes, the TriG insert
fallback — now hashes nothing while it parses.

Parse cost, instructions retired over 15 parses of a 220,000-statement
document (dev-fast, three interleaved rounds, against the head before
this commit):
- an upsert of a document with blank nodes: +1.8%, the repeat-once
  dedup (a sort of one u128 per statement) being most of it;
- an upsert of a document without: +0.35%;
- every other lane: -12%.
insert_formats/upsert_turtle end to end shows no difference within its
run-to-run spread (instructions retired over the bench's six cells,
three interleaved rounds).

Tests: the identity ignores each spelling of a stored literal, a prefixed
or full IRI, and a statement written twice, and tells apart another term
and a renamed blank-node label; only an upsert computes it, and not for a
document without blank nodes.
…eside a new graph

007aa29 stopped a DELETE that names only a graph the ledger lacks from
registering it. These tests pin each DELETE form over such a graph
(DELETE DATA, WITH, a GRAPH ?g bound to a new IRI), over novelty and
indexed; INSERT DATA, CREATE GRAPH and a DELETE/INSERT of the same new
graph still register it; and a DELETE-only new graph that sorts first
does not shift the id of the graph the same transaction writes, whose
value reads back and whose per-graph Reject-mode SHACL override still
refuses a violating write (it_config_graph, shacl feature).
retractions.md says a DELETE naming a graph the ledger lacks commits
nothing.
urn:default names the default graph, so a write naming a graph by it is
refused (TransactError::DefaultGraphNameAsGraph). Staging refuses it as a
write graph or a sync target, which covers the TriG insert and upsert
lanes. The sync and Graph Store routes check a TriG body's blocks against
the graph the request targets before staging, and refused a urn:default
block as naming another graph than the target, a different message for
the same write.

The RDF text reader now refuses a block labeled urn:default itself, with
the same error, whatever the lane and its target.

Test: a TriG insert, a sync payload with the block, a sync targeting
urn:default, and a Graph Store insert with the block are each refused
with that error and leave the ledger as it was, with no graph registered
under that name.
An upsert replaces every value of a (graph, subject, predicate), all
languages together: the documented unit. A client that writes one
language at a time, such as one prefLabel per language, accumulated
languages when a tagged upsert retracted nothing; it now replaces the
others with each upsert. upsert.md's language bullet pointed at a FILTER
on lang() without showing one.

A new "Replacing One Language" section gives the update that does it:
DELETE the stored values in one language, INSERT the new one, with the
WHERE in an OPTIONAL so the insert happens when that language is not
stored yet.

Test: the update, read from upsert.md, replaces the French name and keeps
the English one, with and without a French name stored, over novelty and
indexed.
…s the stored term

A DELETE whose template a WHERE triple witnesses retracts each row as the
WHERE decoded it, with no read, on a ledger that stores no list position.
That row is the stored fact, except for a term in novelty whose index key
keeps less than the term: an integer too large for 64 bits written with an
XSD subtype, a dateTime or time past the microsecond, or a double with no
order-preserving encoding. A query over novelty reads such a term through
its key, so the row is the key's decode. Retracted as decoded, it shares
the stored term's key: storage merged the two and the value read as gone,
but novelty's set-semantics dedup, which compares terms, still held the
stored term as asserted and dropped its next assertion. An upsert or
insert of the value committed and the value stayed gone until the next
index build.

Novelty now records whether an assertion it holds keeps less in its key
than the term (has_lossy_index_terms, sticky like has_list_meta; checked
per assertion as it is applied). While it does, a witnessed row of a kind
whose key can merge terms reads its slot, as on a list-bearing ledger,
and retracts the stored term its key names. Every other row keeps the
fast path. The predicates live in fluree-db-core beside each other:
FlakeValue::index_key_loses_detail for a term and
FlakeValue::index_key_may_merge_terms for a kind, the latter replacing the
query crate's key_may_merge_terms and narrowed to the kinds whose key holds
less than the term (big integers, doubles, nulls, dateTimes, times). A key
for a kind that needs no predicate id is computed for a predicate the
index does not have yet, as queries over novelty key it.

Tests: a sub-microsecond dateTime and time, a subtyped big integer whose
value the index already holds, and a sub-microsecond dateTime under a
predicate the index does not have, matched by a WHERE that binds the
predicate, each deleted through its WHERE row and upserted again,
survive, before and after the next index build; the predicates' unit
tests; novelty sets the flag for a lossy assertion on both apply paths,
and not for a retraction or an exact term.
…ay carry

The resolver asserts, in debug builds, that a txn-meta entry in a reserved
namespace is one the system writes, and its list held f:identity and
db:receivedAt. A commit can also carry f:reverts, one per commit a revert
undid, and the user claims f:message and f:author, which extract_txn_meta
admits in that namespace. An index build over any of them panicked in a
debug build. Release builds skip the assertion and index the entries as
they should.

The list now names all five.

Tests: an index build after a revert keeps its f:reverts entry, and one
after a commit with f:message and f:author keeps both, each queryable in
the txn-meta graph; each panicked in a debug build before this change.
The revert test of an indexed big integer now also builds the index after
the revert.
The DeleteResolver made a DELETE over a wide slot linear again, but a
JSON-LD delete naming every value of one k-value slot still cost 1.20x
main's instructions at 5k to 20k values. It reads the slot's stored
facts so that each retraction names one, which main never did, and it
paid per-fact work around that read. Four cuts:

- A slot read from the index alone skips the term fold. Its rows are
  the index's current facts, one row each in SPOT order, as a range read
  returns them (whole_graph relies on the same); the fold, a sort and a
  hashed pass over every fact, runs only when novelty ops join them.
- Grouping a wide slot by term no longer compares each group's first
  fact with itself.
- A DELETE intent that names a stored fact by a value written as stored
  (a string, IRI, integer or boolean) becomes the retraction, taking the
  fact's graph, datatype, tag and list position, so the stored value is
  not copied. Other values, which can equal the stored one in another
  form (a decimal's scale, an instant's offset), still copy the fact.
- Consecutive intents of one slot reuse its place without hashing its
  key again.

Instructions in the measured transaction (dev-fast, read in-process,
median of 5 fixtures, two interleaved rounds), against main:
- a JSON-LD delete of every value of one slot, 5k/10k/20k: 1.20 to 1.11;
- a WHERE-matched delete over one slot on a ledger that stores a list:
  1.04 to 0.98;
- one value per slot, 20k subjects: a WHERE-matched delete unchanged
  (within 0.5%), an upsert replacing each value 1.7% fewer, from the
  skipped fold.

What remains of the 11% is the read itself: the index scan and each
value's decode (about half), grouping the facts by term, and matching
each intent.

Tests: retract_named gives the stored fact's retraction, from an intent
written alike (keeping the stored tag's case and list position) and
from a decimal written at another scale; an upsert over an indexed value
and a novelty term of its index key retracts one fact, which pins the
fold to reads that novelty ops join.
…nteger

The transaction WHERE decodes its rows through its single resolved
USING/WITH/from graph (6a03e83). The witnessed DELETE lane relies on
it twice: it retracts a decoded row in the graph its template writes,
and a row of a kind whose key can merge terms is matched to the stored
term by its index key in that graph.

Both graphs hold an integer too large for 64 bits under one predicate,
at the same per-graph arena handle. The first delete reads the named
graph's value from the index alone, so the WHERE decodes it. The named
graph then gets the value written with an XSD subtype in novelty, which
the WHERE reads through the index's key, and a second delete removes it.
Through WITH, USING, and JSON-LD graph and from, the test checks that
the witnessed lane ran, that the named graph's values are gone and the
default graph's is kept, and that an upsert writes the subtyped value
again, before and after the next index build.
…es once from text

Earlier versions upserted Turtle by converting it to JSON-LD and scoped
its blank nodes by the converted document; RDF text is now scoped by its
parsed statements. The test upserts a document the earlier way, then
from text: the first upsert from text mints the blank nodes again and the
same upsert after it commits nothing. The documented orphan query lists
the earlier nodes, whose ids share one scope the current nodes do not,
and deleting each by its stable id leaves the current nodes intact.
…t those values

A DELETE intent is matched against the stored facts of its slot, so
naming one value of a k-value slot read and decoded all k facts: one
value of a 20,000-value slot cost 1.82x main's instructions.

A slot whose intents in a batch are plain strings or references, none of
them witnessed, is now read only for the values they name when the slot
is wide enough for that to pay: per value, the index rows of
(s, p, value) and the novelty ops in its bounds. The index keys those
kinds by one dictionary id per term (IRI_REF, which blank nodes share,
and XSD_STRING), so the read returns exactly the facts that hold the
value, in slot order, and matching names what reading the slot would.
Facts read this way are not the slot and are not kept as a wide slot for
later batches. Tagged and otherwise typed strings, numbers, the kinds
whose index key can merge terms, and witnessed rows read the slot as
before.

A value read costs a dictionary lookup and a seek, about what reading
ten facts of a slot costs (measured over deletes naming 1 to 32 values
of slots of 1 to 20,000 values). So a slot is read by value when its
intents times 10 is at most its expected width: the predicate's current
facts over its distinct subjects, from the index's statistics for the
graph. With no index row of the predicate possible, a value read is a
narrower seek into novelty, and one intent takes it; with an index but
no statistics, the slot is read. A batch that reads a slot stamps
`delete_point_read`.

Instructions in the measured transaction (dev-fast, median of 5
fixtures, two interleaved rounds, load 5 to 8), against main and against
the head before this commit:
- one value of a slot of 1k, 5k and 20k values: 1.09x main (1.34x, 1.65x
  and 1.85x before);
- 8 and 32 values of a 20k-value slot: 1.09x and 1.11x main (1.86x and
  1.85x before);
- deletes that still read the slot (one or more values of each of 2,000
  slots of 1 to 16 values, more values than a slot's bound): within
  0.35% of before;
- a delete of every value of a wide slot, a WHERE-matched delete on a
  ledger that stores a list, and the narrow delete and upsert: within
  0.4% of before.

Tests: over novelty, read by one walk and by seeks, value reads answer
as slot reads do (a tagged and a typed twin, list repeats, retracted and
restored values, references, a blank node, a named graph, absent values;
every batching, and a slot held as wide by an earlier batch), and are
not kept as the slot; witnessed rows read their slot even when one row
names it. On indexed and novelty-over-index ledgers, deleting each of
those values alone and beside four absent values leaves the same facts.
The routing stamp proceeds for a few values of a wide slot and falls
back for more values, a tagged value and a narrow slot.
…index

A push checks each retraction in a pushed commit against the target's
current state and rejects the commit when one names no stored fact. The
check range-read the slot and kept the rows whose graph equalled the
retraction's, but index rows come back without their graph, so once a
target had indexed a named graph, every retraction in it was rejected
("retract targets non-existent assertion"). It also compared datatypes
exactly, so once indexed, a big integer written with an XSD subtype,
which the index stores without it, could not be retracted by a push.

The check now reads the slot through CurrentFacts, which stamps the
graph, and accepts a retraction that names a current fact by its term
and metadata or, for a kind whose index key can merge terms, by that key
and list position, which storage resolves as the same fact
(CurrentFacts::holds).

Tests: on a target that indexed the first of two pushed commits, the
second commit's retraction is accepted and replaces the value, in a
named graph and for a subtyped big integer; both fail before the change.
holds names a stored fact by its term and metadata, and not an absent or
retracted value, nor a stored one under another tag or list position.
… a rollback

A Transaction stages its operations again on a rollback. A Turtle upsert
names its blank nodes from the document's statements, so staging it again,
and committing it, keeps the nodes the caller already read, as
a_rollback_keeps_the_blank_nodes_staged_before_it pins for a JSON-LD insert.
…eeps

A ';'-separated update (and a Cypher sequential write, and a Transaction)
folds its operations' flakes per fact and drops a fact a later operation
reversed. The fold told facts apart by term, but storage tells a value
whose index key can merge terms (a big integer with an XSD subtype, a
dateTime past the microsecond) by that key and list position, so on an
indexed ledger:

- DELETE x ; INSERT x retracted the term the index stores and asserted the
  term as written: two facts to the fold, one key to storage, which
  resolves the pair on one t as the retraction. The value was lost.
- INSERT x ; DELETE x asked whether the base held the written term, got no
  (the index holds the value with less detail), and dropped the
  retraction. The value stayed.

The fold now keys such a value by its index key and list position, the
reversal check asks the base through CurrentFacts::named_by by the same
identity, and a retraction that stays names the fact as stored. Other
values fold by term as before, and single-operation staging is unchanged.
Storage tells a value whose index key can merge terms (a big integer with
an XSD subtype, a dateTime or time past the microsecond) apart by that key
and list position, and resolves a retraction and an assertion of one fact
at one t as the retraction. A DELETE names such a value as the index
stores it, so on an indexed ledger one write that deleted it and wrote it
again as written (DELETE { x } INSERT { x } WHERE {}, its JSON-LD twin, an
identical upsert or graph sync) staged a retraction of the stored term and
an assertion of the written one. The accumulator cancelled by term, both
committed, and the value was lost.

FactIdentity (and FactTerm) is now the one rule for when two facts are the
same: an operation that both retracts and asserts keys such a value in its
accumulator by index key and list position, the sequential fold keys by
it, and CurrentFacts::named_by matches by it. Other values are told apart
by term as before. The graph-id and slot lookups move into transact
(graph_id_in, Slot::in_ledger).
Push validation asked CurrentFacts whether each retraction of a pushed
commit names a stored fact, one call per retraction, and each call read
the retraction's whole (subject, predicate) slot: a commit retracting k
values of one n-value slot cost k slot reads, O(k·n). The multi-operation
fold's reversal check did the same for each fact a later operation
reversed.

CurrentFacts::named_by now takes every (slot, flake) at once, reads each
distinct slot once and matches each item against the slot's facts by hash
on its FactIdentity: one read per slot and O(k + n) matching. Push
validation and the fold ask it once. CurrentFacts::holds is gone.
point_values kept each slot's distinct values with Vec::contains, which is
quadratic in the values one slot is named by. The bound lets that reach a
tenth of the slot's width, so a delete naming 100k values of a 1M-value
slot compared values 5 billion times. A set of (slot, value) keeps the
first-seen order at one hash probe per intent.
…mits

A DELETE naming m values of a slot whose expected width is k read them by
value when m * 10 <= k. The constant was fitted on m <= 32. Measured over
m up to k / 2 with each read forced, value reads cost as much as the slot
read at m = k / 12.2 to k / 13.5 when the values lie close together in the
slot (k from 1,000 to 100,000, in instructions and wall time alike), and
at k / 19 to k / 21 when they are spread over it (every seventh value,
wall time). Near the old bound they cost up to 10% more than the slot
read. At m * 16 <= k they cost 6 to 7% less when the values lie together
and 5 to 7% more when spread; 20 would make the spread case even and cost
up to 12% on the other.

The bound's width is the predicate's average over its subjects; the doc
now says so, and that a wrong guess costs time, never results.
…no-op

Since an operation tells facts apart the way storage does, an upsert or a
graph sync that restates a big integer written with an XSD subtype, or a
dateTime or time past the microsecond, cancels against its stored fact on
an indexed ledger, and DELETE { x } INSERT { x } WHERE {} of one commits
nothing, as retractions.md says of any present value. upsert.md drops the
exception for those values. One remains, for a sub-microsecond temporal
re-upserted after a ledger that was never indexed is reloaded.
… less detail

The two tests that documented this as a known exception, ignored until a
fix landed, now pass: an indexed big integer typed with an XSD subtype and
a dateTime past the microsecond survive an identical re-upsert, since the
upsert's retraction of the stored value and its assertion of the written
one are one fact to the operation, as to storage.
Its unit test named facts of one slot only. It now interleaves items of a
second slot: a value of that slot is named, and a value only the first
slot holds is not.
A commit writes a dateTime or time with six fractional digits and the
index keys microseconds, but a value read with more kept them in memory:
in the novelty of the process that wrote it, in a DELETE intent and in a
query constant. So one literal named one value before a reload and
another after. On a ledger never indexed, a DELETE DATA naming such a
value as written committed nothing after a restart, and an identical
re-upsert after a restart read as gone until the next index build; a
query constant written past the microsecond never matched the stored
value.

DateTime::from_instant and Time::from_naive, which every constructor goes
through, now drop the digits past the microsecond as the commit and the
index do. The value written is then the value stored on every write lane,
and a query constant is read the same way. A dateTime or time no longer
holds more than its index key, so index_key_may_merge_terms and
index_key_loses_detail drop them. datatypes.md and compatibility.md say
so, and upsert.md's last exception goes.
The shared fact identity keyed a big integer by its persisted index key,
which exists only once the `(graph, predicate)` arena holds the value. A
value first written since the last index build was told apart by term,
but the next build gives it a handle by value, whatever its XSD subtype.
So one operation that retracted it under one subtype and asserted it
under another committed both flakes at one `t`, and the build resolved
them as one fact, retracted.

An integer too large for 64 bits is now keyed by its value and list
position (`FactKey::BigInt`), which is a function of the term: the
accumulator, the multi-op fold and `named_by` agree with the index
before it has seen the value, and on a ledger with no index yet. Other
kinds keep their persisted key (`FactKey::Index`). `named_by` matches
an item by term first, so of two terms of one value that novelty holds
side by side, an item naming one exactly names that one.
The shared fact identity keys a double or a big integer by key and list
position. A list holding one such value twice, indexed or not, loses
both entries to one write that retracts the value and asserts something
else, and keeps the third entry through the next index build.
`DateTime` and `Time` derived `Deserialize`, which built the field
directly and was the one way in that skipped `from_instant` /
`from_naive`. Both now read their serialized form through those
constructors, so every value is held to the microsecond however it is
made. The serialized form is unchanged.
aaj3f added 9 commits October 14, 2026 10:10
…ex key

`FactIdentity::of_flake` resolved the flake's graph (for a named graph a
`decode_sid`, a string build and a registry lookup) before asking whether
the value has an index key at all. The multi-operation fold calls it for
every flake of every operation, strings and references included. The
graph is now resolved lazily, after the kind check, and not for a big
integer either, which is keyed by value. Behavior is unchanged.
The graph-transfer verbs compared the source's facts with the
destination's by term (`flake_content`). A big integer is one fact per
value to storage, whatever XSD subtype it carries, and the index decodes
it under another term than novelty holds. So when the destination held
the value in its index and the source held it since the last build, COPY
and MOVE retracted the destination's term and asserted the source's at
one `t`, storage kept the retraction, and the destination lost the
value, after the write and after the next index build. ADD in the other
direction asserted a second term beside the stored one.

The transfer now keys every fact it compares (destination contents,
re-homed source facts, the restatements judged under a policy, and the
edge-annotation signatures) by subject, predicate and `FactIdentity` in
the destination graph, through a new `FactIdentity::in_graph`. A fact
both graphs hold is left in place.

`a_transfer_keeps_a_value_both_graphs_hold`: ADD, COPY and MOVE of a
subtyped big integer (same and different subtype), a dateTime past the
microsecond and a string, indexed destination with a novelty source and
the reverse, into a named graph and the default graph, read in process,
reloaded and after the next index build.
…ng too

A dateTime or time constant past the microsecond was held to it for
equality but ordered by every digit, through a rewrite of the comparison
in the SPARQL and Cypher lowerings (`Function::against_digits_past_micros`)
and an every-digit ordering of a plain string (`cmp_lexical`). Two rules
could then disagree: a stored value was `=` a constant and `<` it, a
client that wrote a nine-digit timestamp and paged with `>=` on it missed
its own record, a constant bound through `BIND` or `VALUES` answered
differently from the same constant inline, and the rewrite assumed the
other operand sat on a microsecond, which a plain string ordered against
the constant does not.

A constant is now held to the microsecond like every value, for ordering
as well as equality, so exactly one of `<`, `=` and `>` holds. The
rewrite, its two call sites, `digits_past_micros`, `against_every_digit`
and `cmp_lexical` are removed; `cmp_with_lexical` reads a string as a
value of the temporal's kind, as it already did for dates and the
Gregorian kinds.

Tests replace the every-digit ones: `<`, `<=`, `=`, `>=`, `>` against
constants at, past and either side of the stored microsecond, as a typed
literal, a cast, on the left, through `BIND` and `VALUES` (SPARQL), as a
string and through `values` (JSON-LD), and as Cypher `datetime()` and
`time()`, including a constant equal to the value written ("…123456789Z")
under `>=`; a plain string against a constant past the microsecond, both
ways round. compatibility.md and datatypes.md describe the one rule.
Merge and revert fold a range of commits into one net change per fact
(`NetChangeAccumulator`), keyed by term. An integer too large for 64 bits
is one stored fact whatever XSD subtype it is written with, so a range
that deleted it under one subtype and wrote it under another replayed as
a retraction of one term and an assertion of the other at one `t`, and
storage kept the retraction: reverting `DELETE x^^integer` and
`INSERT x^^nonNegativeInteger` lost the value on an indexed ledger, and
merging a branch that ended by writing it lost it at the next index
build. `main` loses it in both.

The net change is now keyed by value for such an integer
(`FlakeValue::index_keys_by_value`, which `FactIdentity` uses too), so
the range nets to that fact's last op. The change is then named as the
target stores it, for the kinds of value whose index key two terms can
share: an assertion of a fact the target holds is dropped as a
restatement, and a retraction is renamed to the stored fact, or dropped
when the target holds none.

`merge_and_revert_keep_a_big_integer_written_under_another_subtype`:
revert and non-fast-forward merge, on an indexed and a never-indexed
ledger, read after the write and after the next build.
A write-verb policy (`f:create` / `f:update` / `f:delete`) classifies a
subject that a transaction only retracts from as deleted when every fact
the pre-state read returns is retracted. That check compared each
pre-state fact with the retractions by term. But a retraction names a
fact as the stored-fact read resolves it, which can be another term of
the same stored fact than the raw pre-state read returns: on an indexed
ledger holding `x^^xsd:integer`, with `x^^xsd:nonNegativeInteger`
written since the build, the read returns the `integer` term and the
removal retracts the `nonNegativeInteger` one. So removing every fact
of the subject was classified as an update: a delete-only grant refused
it, and an update-only grant let it through.

The check now compares by predicate and `FactIdentity`, in the graph the
subject is classified in, as the accumulator, the fold, `named_by` and
ADD/COPY/MOVE do. The retractions are a set, so the check is linear in
the subject's facts rather than their product.

`a_full_removal_is_a_delete_whichever_term_names_a_fact`: SPARQL and
JSON-LD, indexed and never indexed, under a delete-only and an
update-only grant, with a language-tagged value and a list beside the
big integer.
`a_transfer_keeps_a_value_both_graphs_hold` failed in CI on a MOVE whose
source was written since the destination's build: the source read back
its moved value after a reload. `FlureeBuilder::file` starts a
background indexer, which can run an incremental build between the
transfer and the read, and an incremental build brings back a fact
inserted and retracted since its base in a graph the base holds nothing
for (#2118, a separate fix). The read before any build is right.

Every instance in this PR's file-backed transfer, merge/revert,
multi-op and temporal-ordering tests is now built `without_indexing()`,
and the tests build the index themselves. The transfer test reads with
no build since the transfer, after an incremental build, and after a
full rebuild. After the incremental build it reads the source only
where #2118 cannot reach it (any verb but a MOVE out of a graph written
since the base), and after the full rebuild it reads both.

The full rebuild after an incremental one is published through
`Fluree::reindex`. `publish_index` declines an index whose `t` is not
newer than the published one, so the rebuild the multi-op test ran
after its incremental build was never published, and its "after a
rebuild" read repeated the incremental one.
…ands

A plain string compared with a temporal value is ordered as the temporal
it reads as, held to the microsecond, but it is not value-equal to one,
as on earlier versions. So a string that orders equal to a temporal
satisfies `<=` and `>=` but need not satisfy `=`, and the paragraph now
states its trichotomy for typed temporal operands only.
Brings in 57bf7a9 (#2120, #2009). Two conflicts:

- fluree-db-api/src/commit_transfer.rs: #2009 routes a push's graphs to
  the ids the ledger's graph registry gives them. The push's retraction
  check reads its slots through that routing as it is; only the routing
  struct's doc comment conflicted, and main's is kept.
- fluree-db-transact/src/parse/jsonld.rs: #2009 reworks JSON-LD graph
  scoping, and carries the delete templates' `ill_typed_as_stored` that
  this branch reverts (call 2, aa1b3e6). Main's file is kept and the
  revert applied to it again: a delete template refuses an ill-typed
  literal, as #1988 had it.
Call 2 reverted the delete templates' lenient reading of an ill-typed
literal (aa1b3e6), and `sparql_update_rejects_ill_typed_literal` pins
the refusal on SPARQL. Nothing pinned it on JSON-LD, where `main` still
carries the lenient reading: a merge that kept it would have passed
every test.

`jsonld_transactions_reject_ill_typed_literal`: a JSON-LD insert, a
delete, and a delete with a `where` each refuse `"1990-00-00"^^xsd:date`
written as a constant, with a Turtle write having stored that literal.
With `main`'s parser the delete retracts it instead.
@aaj3f

aaj3f commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for this one too. COPY/MOVE reproduced on main and on this branch: with <g2> holding the big integer in its index and <g1> holding it in novelty, COPY <g1> TO <g2> and MOVE left <g2> with no value, after the write and after the next build. ADD had the mirror image: with the source indexed and the destination in novelty, it asserted a second term next to the stored one, so it read as two rows until the next build. I folded it in as ddd9bbee9: the transfer now keys every fact it compares (destination contents, re-homed source facts, the restatements judged under a policy, and the edge-annotation signatures) by subject, predicate and FactIdentity in the destination graph, via a new FactIdentity::in_graph, instead of the term flake_content compared before. a_transfer_keeps_a_value_both_graphs_hold covers ADD/COPY/MOVE × same and different subtype, a dateTime past the µs, and a string, both directions, into a named graph and into DEFAULT, read in process, reloaded, after an incremental build and after a full rebuild. With the term keying back, its 12 big-integer cases fail.

That test was also why CI went red on ddd9bbee9: FlureeBuilder::file starts the background indexer, and an incremental build of a graph new to the index brings back a fact deleted since its base, which is the MOVE source here. That's the separate bug #2118 fixes. In 43c2bb253 this PR's file-backed tests run without the background indexer and build the index themselves, and the transfer test reads the source after the incremental build only where that bug can't reach it. Along the way it turned out the multi-op test's "full rebuild" after its incremental build was never published (publish_index keeps an index of the same t), so the full rebuilds go through Fluree::reindex now.

I also went back through the other term comparisons on the write side. The class turned out to have a fifth site, merge and revert, which net a range of commits per fact by term (NetChangeAccumulator). A range that deletes a big integer under one subtype and writes it under another replayed as a retraction and an assertion at one t. On main (checked at 57bf7a944) that loses the value on an indexed ledger, at once for a revert and at the next build for a non-fast-forward merge; never indexed, both keep it. In 8960668d1 the net change keys such an integer by value, and stage_merge/stage_revert then name it against the target through named_by. merge_and_revert_keep_a_big_integer_written_under_another_subtype pins both halves: undoing the keying fails the reverts, and undoing the naming leaves two rows on the never-indexed revert until the next build.

On the kinds that need the target's index there: doubles don't lose anything, since FlakeValue's equality and hash treat ±0 and every NaN as one value, exactly as the key's encode_f64 does, and the key's type follows the datatype, so the term already is the key. Revert and merge of ±0 and NaN keep the value on main too (the -0.0 reading back as 0.0 after a build is #2090's item). Nulls all share one key whatever their datatype, so netting by term would split them, but I couldn't find a way to write one: JSON-LD null and Cypher NULL are refused at parse and SPARQL has no null literal, so a null fact could only come from a commit that already holds one.

The last one was classify_subject_lifecycle, the write-verb policy's check that a retract-only subject is fully removed. It compared the pre-state read with the retractions by term, and that is reachable: on an indexed ledger holding x^^integer, with x^^nonNegativeInteger written since the build, the read returns the integer term while the removal retracts the newer one, so removing every fact of the subject was called an update. That isn't on main (the same test passes there); it came from this branch naming a retraction as storage holds it. 59e86424b compares by FactIdentity there too, and a_full_removal_is_a_delete_whichever_term_names_a_fact checks it on SPARQL and JSON-LD under a delete-only and an update-only grant. The annotation-metadata cascade and its retraction dedup compare retractions with stored facts, both read from storage, so I left those as they are.

aaj3f added 5 commits October 19, 2026 13:40
…every term of it

A DELETE intent (a `DELETE DATA` or template constant) names the stored
fact of its slot by term, else by index key. The key fallback named only a
fact whose surviving op was read from the index, and only through a key the
persisted index holds. Both disagree with `FactIdentity`, which every other
part of staging names a fact by: a big integer is one fact per value,
whatever XSD subtype each term carries, indexed or not.

So, for an integer too large for 64 bits:
- with the index holding `x^^xsd:integer` and novelty a later
  `x^^xsd:nonNegativeInteger`, the two merge into one stored fact whose
  surviving op came from novelty, and `DELETE DATA x^^xsd:integer` named
  nothing. `INSERT DATA x^^nonNegativeInteger ; DELETE DATA x^^integer`
  kept the value, as one request or as two;
- on a ledger never indexed, a delete under one subtype of a value novelty
  holds under another named nothing: `INSERT DATA x^^integer ; DELETE DATA
  x^^nonNegativeInteger` kept it even after the next build;
- novelty holds the subtypes of one value apart until the next build, and a
  delete retracted only the term it named, so the value read as present
  until the build and absent after it.

`SlotFacts::named` now names a big integer by value and any other kind
whose key can merge terms by its persisted key, whichever op of the fact
survived, as `CurrentFacts::named_by` and witnessed rows do. The intent
retracts the fact it names and every other term novelty holds of it at the
same list position.

`a_multi_op_update_ends_where_its_last_op_leaves_a_value` now covers every
one- and two-op sequence over the stored spelling and another, every
three-op sequence whose first and last ops spell the value differently,
and the longer ones it had, each for a base without the value, with it in
novelty and with it indexed, for a subtyped big integer and a dateTime
past the microsecond. The one- and two-op sequences also run as one
request per op. Each case is read in process, reloaded, after an
incremental build and after a full rebuild.
… of a fact

Novelty holds the XSD subtypes of one big integer apart until the next
index build: on a ledger never indexed, `x^^xsd:integer` and a later
`x^^xsd:nonNegativeInteger` are both current terms of one stored fact.
Two places named such a fact through `CurrentFacts::named_by`, which
answers one term, and retracted only that one:
- the multi-operation fold, which keys facts by identity and so folds the
  retractions of several terms into one entry. `INSERT DATA x^^integer ;
  DELETE DATA x^^nonNegativeInteger` over such a base retracted one term,
  and the value read as present until the next build and absent after it;
- merge and revert (`as_stored`), whose net retraction of such a value
  retracted one term the same way.

`CurrentFacts::all_named_by` answers every current term of each item's
fact, its own term first; `named_by` is its first answer. The fold asks it
for every fact whose first and last ops differ, and for every retraction
of a big integer, and retracts each term the base holds; merge and revert
retract each term the target holds.

`a_multi_op_update_ends_where_its_last_op_leaves_a_value` also starts from
a ledger whose novelty holds the value under two subtypes and from one
whose index holds it and whose novelty holds a later subtype.
`merge_and_revert_keep_a_big_integer_written_under_another_subtype`
reverts both writes of a value novelty holds under two subtypes.
The extended `a_multi_op_update_ends_where_its_last_op_leaves_a_value`
ran about 590 cases in one test, 158–326 s on a loaded machine, against
nextest's 360 s terminate-after. It is now one test per base state and
value kind (eight, each about 60 cases) through
`multi_op_last_op_matrix(base, kind)`, so they run in parallel. The
dateTime kind runs on the three bases that hold one spelling: its
spellings are one term once read, so the two bases holding a second
spelling repeat them.
… per item

`a89bf9e30` made `CurrentFacts::named_by` the first answer of
`all_named_by`, which indexed each slot's facts by identity key with a
vector per key. So every fact of a kind whose key can merge terms (a
double, a big integer) cost one more allocation whenever its slot was
named, and `named_by`, which push validation runs for every pushed
retraction, went through it. `f0ee77742` also grew `SlotFacts` by an
inline `Groups` that most slots never build, and every slot a DELETE
batch reads carries it.

Each slot is now indexed by its first fact per key, with a chain to the
next, allocated only when two terms of one fact are current (novelty
holding one big integer under two subtypes). `named_by` answers from that
without collecting, and `all_named_by` walks the chain. `SlotFacts` boxes
its by-value groups.

Against `3ebb552b5` (release; retired instructions and allocations per
write, 7 runs in each of 2 interleaved rounds): a multi-operation delete
of 600 strings and references over 600 slots allocated 33.6 KB more
before this and is at parity after; one reversing 300 doubles made 301
more allocations before and is at parity after.
@aaj3f

aaj3f commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

A gap turned up after this went up for review, so I've folded in a fix: the fold's cross-spelling case. INSERT DATA x^^xsd:nonNegativeInteger ; DELETE DATA x^^xsd:integer, with the value indexed as integer, kept the value, so the body's "INSERT x ; DELETE x … deleted" row only held when both ops spelled the value the same way. The cause turned out not to be the fold itself. A DELETE named its stored fact by index key only when the fact's surviving op had been read from the index, and here the later novelty op survived the merge, so the delete named nothing (it reproduced as two separate requests too).

Widening the test turned up the rest of that class. On a ledger with no index, a big integer had no key to be named by at all. And novelty holds two subtypes of one value apart until the next build, so a delete that retracted only the term it named left the value present until the build and gone after it.

  • f0ee77742: a DELETE names the fact by FactIdentity, whichever op of it survived (a big integer by value, indexed or not), and retracts every term novelty holds of it.
  • a89bf9e30: the multi-op fold and merge/revert do the same, through a new CurrentFacts::all_named_by.

The multi-op test, now eight tests under a_multi_op_update_ends_where_its_last_op_leaves_a_value and its siblings, enumerates every one- and two-op sequence over two spellings, the three-op ones whose first and last spellings differ, and five base states, including two subtypes held in novelty and an indexed value with a later subtype in novelty. The short sequences also run as separate requests. With the fix undone, 72 of its cases fail; on main it's 172. I also A/B'd it against 3ebb552b5 for instructions and allocations. The wide-slot deletes, big-integer deletes, a delete-heavy multi-op and an insert-only control all come out flat. The first pass did show two allocation costs (a bigger SlotFacts per slot read, and a vector per identity key), and e3de4b1ac takes those back out. The body's updated to match.

@aaj3f
aaj3f merged commit 4a0d14a into main Oct 20, 2026
29 of 30 checks passed
@aaj3f
aaj3f deleted the fix/write-fidelity-part2 branch October 20, 2026 12:24
aaj3f added a commit that referenced this pull request Oct 20, 2026
…ferences

Brings in #2137, #2118 and #2109. The one conflict is stage.rs's
fluree_db_core import: #2109 dropped `FlakeMeta` from it, and this branch
added the dataset-reference types. #2109's FactIdentity DELETE naming and
fold, and this branch's typed graph resolution for USING / WITH and the
write table, sit in separate hunks and merge as both wrote them.
bplatz added a commit that referenced this pull request Oct 20, 2026
Brings main since 1888006 onto next, #2109 and #2118 among it. Resolved:

- template_sink: main's statement hashes for the content identity, with
  next's rdf:reifies link and its datatype check; no bundle templates.
- incremental: main's Phase2Route (a leafless branch is built fresh, the
  fresh builder keeps in-window history, an empty fresh branch is not
  published) on next's storage handle, without cache_dir.
- build_from_commits tests: main's helpers with next's term fields.
- commit_transfer, rebase: the imports both sides still use.
- test support: main's publish_built_index, publishing allow-equal under
  the ledger's fence; its callers take main's side.

Ported to next:

- index_key_may_merge_terms answers for a triple term: its key merges
  two terms only through its object's.
- The SPARQL triple-term literal drops IllTyped, which main removed; it
  refuses an ill-typed literal, as it did.
- Main's new tests read a ledger's store through its storage namespace,
  await the async genesis_ledger, and the ill-typed upsert test names a
  ledger per iteration rather than a branch.
aaj3f added a commit that referenced this pull request Oct 30, 2026
The parent now carries main 4a0d14a (#2109, #2118, #2133). Four files
conflicted:

- temporal.rs: main's `cmp_with_lexical` body is the one this branch
  already had (#2109's); the two docs are merged, so it says both that a
  dateTime or time lexical is held to the microsecond and that the
  evaluator and the bounds pass it only a plain xsd:string.
  `lexical_as_kind_of` stays, over the same parse functions.
- query_bounds.rs: this branch's string-vs-temporal arm (the plain-string
  guard and the per-kind parse cache) replaces main's simplified one, which
  called `cmp_with_lexical` with no guard. `string_bound_otypes` stays.
- eval/compare.rs: the plain-string guard stays on the evaluator's
  coercion.
- binary_history.rs: main's shared object check (#2133) is kept, with the
  term-aware `matches(&f.o, &f.dt)`; this branch's separate bound test in
  the novelty walk is dropped, as the shared check covers both lanes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:transact Staging, commit, import/bulk-import, novelty, retraction semantics bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants