Skip to content

fix: preserve language-tagged literals that share a value (#1273) - #1291

Merged
bplatz merged 4 commits into
mainfrom
fix/langstring-novelty-dedup-1273
Jun 5, 2026
Merged

bplatz merged 4 commits into
mainfrom
fix/langstring-novelty-dedup-1273

Conversation

@bplatz

@bplatz bplatz commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Inserting a subject with several language-tagged values whose strings are
identical but whose @language tags differ — e.g. "animal"@en and
"animal"@fr — silently dropped all but one variant. Ingesting a multilingual
SKOS thesaurus lost hundreds of labels, hitting English hardest because EN and
FR share many literal forms.

The root cause is fact identity. A language-tagged literal's identity includes
its language tag, and a list member's includes its position, so both live in the
flake metadata m alongside (s, p, o, dt). The overlay-only read path
(range::remove_stale_flakes, used for committed-but-not-yet-indexed data and
genesis ledgers) keyed its set-semantics dedup on (s, p, o, dt) only and
dropped m. Two variants that shared a value therefore looked like one fact and
collapsed. The binary-scan path already keyed on the full identity; this just
brings the two into agreement with Flake's own equality.

Adding m to that key fixes three failure modes from the same omission:

  • distinct language variants sharing a value are preserved on insert;
  • deleting one language variant no longer over-cancels the others (a retraction
    matches only the variant it names);
  • @list members that repeat a value at different positions
    (["a", "b", "a"]) are no longer collapsed.

A second, related path is the binary overlay encoder. When a language tag has
not yet been added to the persisted language dictionary (a fresh tag in novelty
over an indexed ledger), it was encoded with a fixed fallback id, collapsing
every such tag to one value and mis-labelling the survivor. It now declines that
encoding and routes the flake through the raw-flake overlay path — which carries
the real metadata and dedups on full identity — mirroring how novelty-only
custom datatypes are already handled.

Finally, RDF export attaches the same novelty overlay so it can dump
committed-but-unindexed data. It previously discarded any flake it could not
encode into the columnar overlay (the new-tag language literals above, plus
vector/bigint/decimal and novelty-only custom datatypes), and it scanned with a
projection too narrow for the overlay merge. Export now emits those values
directly in every format (Turtle, N-Triples, N-Quads, JSON-LD), deriving the
language tag and datatype from the flake, and scans with the full identity
projection.

Closes #1273.

bplatz added 4 commits June 4, 2026 15:29
Language-tagged literals with the same string value but different
language tags (e.g. "animal"@en and "animal"@fr) were silently
deduplicated on insert, dropping all but one variant.

Two read paths collapsed distinct facts because they ignored the flake
metadata `m` (language tag and list index), which is part of RDF term
identity:

- range::remove_stale_flakes (overlay-only / genesis read path) keyed
  its fact dedup on (s, p, o, dt) only. Add `m` so the key matches the
  canonical Flake identity. This also fixes over-cancellation when
  deleting one language variant and the silent loss of @list members
  that repeat a value at different positions.

- value_to_otype_okey (binary-overlay encode path) fell back to a fixed
  lang_id=1 for a novelty-introduced tag not yet in the persisted
  language dictionary, collapsing every such tag to one OType. Return
  Unsupported instead so the flake is merged via the raw-flake path,
  which carries the real metadata and dedups on full identity, mirroring
  how novelty-only custom datatypes are already handled.

Adds regression tests for the genesis, indexed-overlay, delete, list
duplicate, and set-collapse scenarios, and documents that the language
tag is part of a value's identity.
RDF export attached the novelty overlay so it could see committed-but-
not-yet-indexed data, but two gaps dropped or corrupted that data:

- Overlay flakes that cannot be encoded into V3 ops (language-tagged
  literals whose tag is not yet in the persisted language dictionary,
  plus vector/bigint/decimal and novelty-only custom datatypes) were
  silently discarded. Switch the overlay translation to the
  with-untranslated variant and emit those raw flakes directly in every
  format (Turtle, N-Triples, N-Quads, JSON-LD), deriving the language
  tag from the flake metadata and the datatype from the flake datatype.
  Assert/retract set semantics are resolved over the untranslated set
  before emitting.

- The export cursor used a CORE column projection, but the overlay merge
  requires the full V3 identity (including the list index). Use the full
  projection so encoded novelty overlay rows merge correctly instead of
  reading missing columns as defaults.

Adds a multi-format export regression test for novelty-only language
tags.
Adversarial review raised a concern that export's raw-flake path resolves
subject/predicate IRIs via the immutable store without a novelty fallback,
which could drop facts in a namespace first introduced after the last
index. Add a regression test that exercises exactly that: a brand-new
namespace introduced by novelty over an indexed ledger, with both an
encoded value (integer) and a raw novelty-only langString.

It passes because the public export path loads the ledger fresh, syncing
the store's namespace codes with the snapshot's commit chain before
export, so both paths resolve the new namespace correctly.
Note that RDF fact identity is (s, p, o, dt, m) and any dedup/stale-removal
key omitting the FlakeMeta `m` collapses distinct language-tagged and list
facts, so future work in this area recalls it.
@bplatz
bplatz requested review from aaj3f and zonotope June 4, 2026 21:03

@zonotope zonotope 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.

🥼

@bplatz
bplatz merged commit e6ddd1b into main Jun 5, 2026
13 of 14 checks passed
@bplatz
bplatz deleted the fix/langstring-novelty-dedup-1273 branch June 5, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language-tagged literals with identical @value get deduplicated on insert, losing language variants

2 participants