Repository navigation
Description
Summary
Building an index replaces the values of xsd:date, xsd:dateTime, xsd:time, xsd:gYear
and xsd:long literals with wrong values. The commit files retain the correct data — only
indexed reads are affected, so a ledger looks perfectly healthy until its first index build,
at which point every temporal value in it becomes wrong.
Two properties make this worse than a normal read bug:
- It is silent. No error, no warning.
xsd:datereturns1970-01-01, which is a
plausible-looking date. Triple counts, graph counts, and every other datatype are
unaffected, so integrity checks pass. - The affected triples become un-retractable.
DELETE DATAwith the exact literal
returns success and removes nothing (see part 2 below), so the natural repair —
delete and re-insert — silently no-ops.
Verified on 4.1.4 and 4.2.1. Upgrading 4.1.4 → 4.2.1 did not fix it.
Reproduction (no server required)
fluree init --direct
fluree create --direct dt/x
fluree update --direct -l dt/x -e 'INSERT DATA {
<https://ex.org/a> <https://ex.org/d> "2026-09-08"^^<http://www.w3.org/2001/XMLSchema#date> }'
fluree query --direct -l dt/x -e 'SELECT ?o WHERE { ?s <https://ex.org/d> ?o }'
# 2026-09-08 <-- correct (novelty)
fluree index --direct dt/x
fluree query --direct -l dt/x -e 'SELECT ?o WHERE { ?s <https://ex.org/d> ?o }'
# 1970-01-01 <-- WRONG (indexed)fluree reindex (full replay from commit history) produces a byte-identical index root
to fluree index, so replaying from commits is not a workaround. The server-side
POST /v1/fluree/reindex endpoint is also affected.
Affected datatypes
One subject, twelve typed literals, read before and after fluree index on 4.2.1:
| datatype | before index | after index | |
|---|---|---|---|
xsd:date |
2026-09-08 |
1970-01-01 |
corrupted |
xsd:dateTime |
2026-09-08T12:34:56Z |
<dateTime -9223372036854775807> |
corrupted |
xsd:time |
12:34:56 |
00:00:00.000002 |
corrupted |
xsd:gYear |
2026 |
0003 |
corrupted |
xsd:long |
20705 |
-9223372036854775803 |
corrupted |
xsd:duration |
P3D |
P3D |
ok on 4.2.1; row vanished entirely on 4.1.4 |
xsd:string |
2026-09-08 |
2026-09-08 |
ok |
| plain literal | 2026-09-08 |
2026-09-08 |
ok |
xsd:integer |
20705 |
20705 |
ok |
xsd:decimal |
12.5 |
12.5 |
ok |
xsd:boolean |
true |
true |
ok |
"hello"@en |
hello |
hello |
ok |
Note xsd:integer survives while xsd:long does not.
Suspected cause
The corrupt values are small ordinals — 0003, 00:00:00.000002,
-9223372036854775803 (= i64::MIN + 5) — rather than arbitrary garbage. That looks like a
dictionary/reference ID being decoded as the target type instead of being resolved back to
its value. This is the same area as #1729 ("Indexed reads flatten non-xsd:string
string-dictionary datatypes", root-caused to object_binding.rs:105-112), which is already
fixed in 4.2.1 — so this appears to be a sibling gap on the temporal/long decode path
rather than the same defect.
Also closely related in shape: #1737 ("Numeric subtype leniency holds on novelty but not once
indexed"), which notes that testing covered novelty only and missed the index divergence.
That is exactly the failure class here, but #1737 explicitly scopes itself to numeric
subtypes and does not cover temporal types.
Part 2 — affected literals cannot be retracted
Once a temporal literal exists, DELETE DATA naming it exactly cannot remove it:
DELETE DATA { GRAPH <...> {
<...subject> <...date> "2026-09-22"^^<http://www.w3.org/2001/XMLSchema#date> . } }Returns success with a new t, removes nothing. Observed on a real 45-triple migration: 40
retracted, 5 did not; two identical passes missed the same 5. This happens with no index
present, so it is not a consequence of a corrupt index — literal matching for these
datatypes fails on its own. DELETE WHERE, DELETE {} WHERE {}, WITH … DELETE naming the
literal, and the JSON update delete clause all behave the same. Plain-string literals delete
normally.
Workaround that does work — bind the object as a variable and filter on datatype(),
never naming the literal:
WITH <https://example.org/graph/g1>
DELETE { ?s <https://example.org/date> ?d }
WHERE { ?s <https://example.org/date> ?d
FILTER(datatype(?d) = <http://www.w3.org/2001/XMLSchema#date>) }GRAPH ?g is rejected in SPARQL Update DELETE templates
(GRAPH ?g is not supported in SPARQL Update DELETE templates), so this needs one statement
per named graph.
Impact
A production knowledge ledger silently lost the correct value of every xsd:date it held.
It was only noticed because I recognised that 1970 dates were implausible. Recovery
required stopping the server, deleting the index directory and its nameservice root pointer
so the engine would serve from commits, dumping the true values, and migrating every date to
a plain string literal — because any future index build re-corrupts typed dates, and
reindex_min_bytes defaults to ~every commit.
Environment
- Fluree 4.1.4 and 4.2.1 (both affected)
- Linux x86_64
- File storage, single node, no Raft
- Reproduced both via the CLI with
--directand through the HTTP server
Activity
fix: keep typed literal values through the index (#1987)
bplatz commentedon Sep 29, 2026
Reproduced on v4.2.2 (
ba984c7f5, currentmain). Most of this starts on the write path: SPARQL UPDATE stores these literals as strings, and both parts of the report follow from that.Root cause: SPARQL UPDATE doesn't parse typed literals
SPARQL UPDATE turns a typed literal into a value with
coerce_typed_flake_value(fluree-db-transact/src/lower_sparql_update.rs:2133). It knows onlyxsd:integer,xsd:double,xsd:decimal,xsd:booleanandf:embeddingVector. Anything else falls back toFlakeValue::String(lexical)carrying the declared datatype, which is a string flake labeledxsd:date,xsd:long, and so on.Every other write path parses the lexical and stores a real
Date/DateTime/Long:value_convert::convert_string_literalfluree_db_core::coerce::coerce_string_valuelower_typed_literalThe TriG template path has a comment warning about exactly this (fluree-db-api/src/tx.rs:2445-2457).That is why the table in the report splits the way it does:
xsd:integer,xsd:decimalandxsd:booleansurvive because the SPARQL path parses them, andxsd:longdoesn't because it isn't on the list.Part 1 (index build): the indexer takes the object key from the value variant but the object type from the datatype. A
Stringpayload becomes(ObjKind::LEX_ID, string-dict id)(fluree-db-indexer/src/run_index/resolve/resolver.rs:885-891; the datatype argument is unused there).OTypeRegistry::resolvethen mapsLEX_IDthroughresolve_by_dt(fluree-db-core/src/o_type_registry.rs:106-112), which givesXSD_INT,XSD_DATE_TIMEand so on. The reader dispatches on that type alone (fluree-db-binary-index/src/read/binary_index_store.rs:1354), so a small dictionary id N is decoded as an int, a date or a time:i64::MIN + N1970-01-030007Plain
xsd:durationsurvives only because its decoder reads the string dictionary. The query-time novelty overlay builds the same(datatype type, string id)pair (value_to_otype_okey,fluree-db-query/src/binary_scan.rs:3765-3773). So once a ledger has any index, a newly written value reads back wrong immediately, with no rebuild. Novelty reads are correct only before the first index build.Part 2 (can't retract):
DELETE DATAbuilds its retraction the same way, as(String(lexical), xsd:date). That never matches a value stored as a realDate, which is anything written through Turtle, TriG or JSON-LD or computed byBIND. This happens with no index present, which matches what you saw:Same literal, SPARQL UPDATE vs Turtle
Written with
INSERT DATAand withfluree insert(Turtle), read withSTR()before and afterfluree index:xsd:integer,xsd:decimal,xsd:double,xsd:boolean,xsd:string,xsd:anyURI,xsd:tokenxsd:int/long/short/byte/nonNegativeInteger/unsignedInt4242-9223372036854775807xsd:float1.5E01.5NaNxsd:dateTime2026-01-01T09:15:00Z2026-01-01T09:15:00Z<dateTime -9223372036854775805>xsd:date2026-01-012026-01-011970-01-03xsd:time09:15:0009:15:0000:00:00.00001xsd:gYear202620260007xsd:gYearMonth2026-012026-011431655766-01xsd:dayTimeDurationPT1HPT1H-P106751991DT4H54.775804Sxsd:yearMonthDurationP1MP1MP11Mxsd:durationP1DP1DP1D(
STR()is itself unbound on the gYear/duration types, #1994, so those rows were read directly.)Even before the first index build, the string-stored values already behave differently:
?s ex:d "…"^^xsd:dateTimemisses them.FILTER(?n > 3)misses anxsd:int.HOURS()is unbound.DELETE DATAwritten in SPARQL won't retract a Turtle- or JSON-LD-written value, as above.After indexing,
FILTER(?d > …)andFILTER(?d = …)stop matching rows they matched before, with no write in between.Turtle isn't entirely safe either. An invalid lexical such as
"not-a-date"^^xsd:dateTimeis accepted as a string with that datatype by Turtle insert as well as SPARQL UPDATE (JSON-LD rejects it), and it is corrupted the same way at index time.What a fix needs
coerce_typed_flake_valueshould callcoerce_string_value, astx.rs:2452does. Its WHERE-side twincoerce_typed_valuefalls back the same way, but the query lowering re-coerces that side (fluree-db-query/src/parse/lower.rs:602), which is whyDELETE WHEREpatterns match canonically.reindexreplays commits, so (1) alone won't repair them. That matches your finding thatreindexgives a byte-identical root. The index side should also refuse to decode a string payload as a native type. Options:LEX_IDarm ofOTypeRegistry::resolveandvalue_to_otype_okeycould coerce the lexical, or fall back to a string-dictionary type.validate_value_dt_pair(fluree-db-transact/src/generate/flakes.rs:512), whichcoerce.rscalls the single bottleneck for value/datatype rules, could rejectStringpaired with a natively encoded datatype on new writes. That doesn't help commits already on disk, though.Workarounds until then
Checked on v4.2.2 with an index built. The
BINDinsert keepsxsd:date,xsd:dateTime,xsd:longandxsd:intcorrectly typed through indexing:BIND, which goes through the query-side lowering:FILTER(datatype(?d) = …)form works for the same reason.Related: #1974, where
xsd:intis indexed under a custom datatype during an in-flight index build. It has a different trigger but the same kind of dictionary-id-read-as-value symptom.Revert "fix(transact): a DELETE can name a stored ill-typed literal"
docs(concepts): a stored ill-typed literal is removed through a variable