Skip to content

fix(transact): a property keeps one vector length per graph - #2112

Merged
aaj3f merged 32 commits into
mainfrom
fix/vector-lengths
Oct 26, 2026
Merged

aaj3f merged 32 commits into
mainfrom
fix/vector-lengths

Conversation

@aaj3f

@aaj3f aaj3f commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The index stores each property's f:embeddingVector values in each graph at one length, and a vector has at most 65,535 elements. Writes now apply that rule before they commit: a vector whose length differs from the vectors its property already holds in that graph, or with more than 65,535 elements, is refused with Invalid vector (HTTP 422), and nothing in the write is committed. One function states the rule, and the index applies that same function when it stores a vector, so the two can't drift apart.

A ledger whose binary index store fails to load is no longer cached without it. The load fails with its own error (HTTP 500), requests within a short window get that error without loading again, and the next request after the window loads again, so the ledger heals once its store can load, with no restart. A write on a state that still lacks the index this process needs (one whose attached index is older than the ledger's, or one a caller built without the store) is refused before its first read with err:db/IndexNotLoaded (HTTP 503, Retry-After).

What changes

  • One rule. fluree_db_core::vector::check_vector decides whether a vector can be stored: 1 to 65,535 elements, each a finite f32, and the length the property already has in that graph. The first vector a property receives in a graph sets the length; retracting vectors does not reset it, since the index keeps history. A vector over 65,535 elements is TooLong whatever length the property holds. The vector arena applies this function when it stores a vector.
  • Where writes check it. Every path that creates commits checks before the write; these are the same paths that check the datatype limit:
    • build_commit: transactions on every surface (JSON-LD insert, upsert and update; SPARQL UPDATE; Turtle and TriG), graph sync, merge, rebase and revert. Each vector is checked against the length in the index (read from the arena manifest, no shard loaded), else the first vector asserted since the index, else the first earlier in the same commit. A commit lands only on the base it was checked against: the handle path holds the write lock, and commit() checks that the base is the published head (verify_sequencing) and publishes with a compare-and-set on that head.
    • Push: each pushed commit, against the ledger and the earlier commits of the push.
    • Bulk import (fluree create --from, the server's import upload; the Cypher and CSV imports feed it as JSON-LD): the import's vector pool applies the rule as it reads, and the import stops with the same Invalid vector refusal a transaction gets, naming the property and graph. Like an import that stops for any reason, it keeps what it published at its last checkpoint (one every 50 chunks by default).
    • Flake generation refuses an empty vector as before, and now also one longer than 65,535 elements or with a non-finite element, before any commit work.
  • Paths that bring data in without checking, and why. Pull, clone and restore from a .flpack archive (the server's /import, Python's restore_ledger, the CLI's create --from <file>.flpack) create no commits: they copy a ledger's existing commits, and its index, byte for byte. The copy holds what its source holds and refuses what its source refuses, and a ledger an earlier release left with two lengths still restores, which its move to one length by export and import needs when the source is gone. A ref moved through the nameservice sync endpoints points at commits a writer with access to the ledger's storage built through its own commit path; the server reads none of them. Raft followers apply what the leader built.
  • A ledger whose store fails to load. A ledger with an index can be neither read nor checked without its binary store: every range read fails, and the checks that need the index can't decide (without it, the datatypes the index holds aren't counted, so a write could take the ledger past its datatype limit, after which it can never be indexed). It used to be cached anyway (ledger_manager logged "continuing without"), and nothing loaded the store again: no nameservice notification plans a change, and a retrying client keeps the entry from going idle, so only a restart, a new index, or half an hour without access healed it. Now there are two layers.
    • The ledger manager doesn't cache a ledger without its store. When the store fails to load, get_or_load fails with the load's own error. For LedgerManagerConfig::store_load_retry (default 5 s) requests get that error without loading again, so a lasting failure costs one load per window rather than one per request (concurrent requests already share one load). The first request after the window loads again. A reload that can't load the store keeps the state and store the ledger has, rather than swapping in one without a store. A ledger-state failure (not found, say) isn't remembered and fails as before.
    • check_index_loaded stays as the backstop. TransactError::IndexNotLoaded: the ledger has an index, but no range provider is attached, or the binary store attached is older than it. That covers a state a caller built without the store and an install that left an older store attached. check_index_loaded decides it from the snapshot in O(1), and each write lane calls it before its first read: build_transact_policy_context (the committers, push, Cypher, GraphQL), stage_with_graph_delta, stage_flakes, build_commit, and CurrentFacts. The vector check's refusal of an index it can't read lengths from is the same variant.
  • Errors.
    • TransactError::InvalidVector, answered with 422 / err:db/InvalidTransaction: a well-formed request whose value breaks a constraint the ledger holds, the class the datatype limit's 422 is in. A 422 already carries that type when the committer flattens an error to its status, so the direct and replicated paths agree, and the Raft commit worker now poisons a 422 at once, as it does a 400, instead of staging it again (this also applies to the datatype limit). No Retry-After. The message names the property, and the graph when it is a named graph: Invalid vector: <http://example.org/embedding> in graph <http://example.org/g1>: vector dims mismatch: expected 3, got 2.
    • A store that fails to load answers with the load's own error: 500, err:system/InternalError, for example failed to load binary index: .... Through the committer it's an Execution { status: 500 }, which is settled, so a keyed retry re-executes; the Raft commit worker treats a failed load as transient.
    • TransactError::IndexNotLoaded, answered with 503 / err:db/IndexNotLoaded and Retry-After, on the direct path and through the committer (SubmissionError::IndexNotLoaded, settled, so a keyed retry re-executes). It joins RETRYABLE_503_TYPES. The Raft commit worker treats it as transient, as any 503, and refreshes before retrying. A Raft client sees a 422 "submission poisoned" after its retries, as it did for the 400 this replaces.
    • Bulk import carries a refusal typed: ImportError::Invalid holds the InvalidVector (or DatatypeLimitExceeded) a transaction gets. Python raises it as InvalidRequestError with status 422.

Behavior changes

Before After
A ledger whose binary store fails to load cached without its store until a restart, a new index, or half an hour without access; nothing loaded the store again the load fails with its own error (500); requests within store_load_retry (5 s) get it without loading again; the next request after loads again and the ledger heals; a reload that can't load the store keeps the ledger it has
Writes to such a ledger one that reads the index (an upsert, an update with a where) failed inside that read with 400 err:db/InvalidTransaction, which the Raft commit worker poisons at once; one that reads nothing from it (an insert with no SHACL config) committed without the checks that need the index the load's error (500); Raft retries a failed load as transient
A write adding a datatype past the limit, on such a ledger committed (the datatypes the index holds are not counted), and the ledger could never be indexed again: datatype dict overflow (dt_id=16384 exceeds the maximum of 16383) refused: the load's error through the ledger manager, 503 err:db/IndexNotLoaded on a state built without the store; the ledger still indexes
Reads of such a ledger a query loaded the store itself, per query; a commit's detail and a query at an earlier t answered the load's error (500), as writes get; ledger-exists and the default context still answer; ledger info and export failed before too
A write on a state whose attached index is older than the ledger's only a vector write refused, with a core error (400) every write refused, 503 err:db/IndexNotLoaded
A vector of more than 65,535 elements on a property whose length is known (push) vector dims mismatch: expected 3, got 65536 vector dims 65536 exceeds the maximum of 65535
A bulk import holding a vector the ledger cannot store, or a datatype past the limit transact: flake encode error: ..., naming neither property nor graph ImportError::Invalid: Invalid vector: <property> [in graph <graph>]: ..., or the datatype-limit refusal; Python raises InvalidRequestError (422) instead of FlureeError

Compatibility

  • Persisted formats: unchanged. No commit, index, nameservice or content-identity format changes; the arena's on-disk length field is the same u16. Existing ledgers load and index as before.
  • A ledger written by an earlier release may hold vectors of more than one length on a property. Writes to it refuse any further length, and its data moves to a new ledger by export, keeping one length per property (or moving the others to another property), and import. tests/fixtures/vector-lengths-4.2.3, a ledger the v4.2.3 CLI wrote (the same fixture fix(index): every xsd:double value is indexable #2044 uses), pins that path, and the same ledger restored from an archive behaves as its source.
  • Rust API: LedgerManagerConfig gains store_load_retry (a struct literal with ..Default::default() is unaffected); TransactError gains InvalidVector and IndexNotLoaded; SubmissionError gains IndexNotLoaded; ImportError gains Invalid; fluree_db_transact::check_index_loaded is new; BinaryIndexStore gains vector_dims; fluree_db_core::vector is new; VectorArena::insert_f32/insert_f64 and SharedVectorArenaPool::insert_f32/insert_f64 return VectorError instead of String. The vector arena's error strings are unchanged except the too-long one, which now reads vector dims N exceeds the maximum of 65535, and the arena checks a vector's length before its elements.
  • Solo, at the pin bump that brings this in:
    • its submission classifier matches SubmissionError without a wildcard, so it needs an arm for IndexNotLoaded (transient), as it does for fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009's ConfigUnavailable;
    • its transactor answers a failed ledger load with a terminal error, so a storage failure loading a ledger's store needs to be retried there, as a failed cache refresh already is;
    • its transactor classifier needs TransactError::IndexNotLoaded in its transient arm, since an unlisted Transact(_) is deterministic there.
    • InvalidVector and ImportError::Invalid need nothing.

Performance

Non-vector writes pay one pass over the commit's flakes to find vectors, beside the existing size pass. Vector writes add, per distinct property and graph, one length lookup that is in memory by construction: the arena manifest, which the store loads with the index, or else one seek in novelty. There's also one pass over each vector's elements; no I/O is added. Measured against main at 745736a04, before this branch was rebased onto current main, both CLIs built with the dev-fast profile, one process per insert into a new ledger, runs interleaved, medians:

main this branch ratio
Turtle insert, 100k triples, no vectors (20 runs) 0.330 s 0.333 s 1.01
JSON-LD insert, 90k flakes, no vectors (20 runs) 0.423 s 0.424 s 1.00
Turtle insert, 4,000 vectors of 768 elements (12 runs) 0.167 s 0.167 s 1.00

A first 12-run pass read 0.99 and 1.02 for the two non-vector rows, so both were re-measured at 20 runs (above).

Steady state, counted in instructions retired per commit (dev-fast, in-memory ledger, no background indexer, against main at ba694ee79, 3 interleaved runs of 200 commits, medians). The ledger holds 20,000 indexed vectors of 128 elements on one property and 2,000 more in novelty:

commit main this branch ratio
5 vectors of 128 elements 1,204,427 1,232,196 1.023
5 triples, no vectors 893,969 893,718 1.000

What the vector commit pays for is the checks on its five vectors (their elements are read twice, once when the flake is generated and once at commit) and one length lookup in the index.

The later changes on the write path:

  • check_index_loaded is O(1): a t comparison, an Option check, a type comparison and the store's max_t. A write runs it a few times.
  • The import's typed refusal changes only the error types on its success path.
  • A ledger's store load, which now fails rather than continuing without the store, isn't a per-write cost.

Counted in instructions retired (dev-fast, in-memory ledger without background indexing, holding 20,000 indexed vectors of 128 elements and 2,000 more in novelty; 5 interleaved runs, medians):

without the change with it ratio
commit, 5 triples (per commit, 3,000 commits) 1,067,230 1,065,904 0.999
commit, 5 vectors of 128 elements (per commit, 3,000 commits) 1,531,835 1,526,735 0.997
bulk import, 4,000 vectors of 768 elements (whole run) 6,100,186,373 6,106,448,369 1.001

For commits, "without" is this branch with check_index_loaded made a no-op; for the import, it's the commits before and after the typed import (20fccad5f, a33eb40af). Runs varied by about ±1.5% from round to round, so the commit rows show no measurable change.

Tests

  • it_vector_lengths (grp_index), where every refusal is checked to be InvalidVector with status 422:
    • a property keeps the length of its first vector, read from novelty, from the index, and from novelty over the index; a refused write commits nothing;
    • one transaction holds one length per property;
    • each named graph keeps its own length, written by SPARQL and by TriG;
    • retracting the vectors keeps the length;
    • 65,535 elements is the most, and that vector reads back whole from the index;
    • every write surface: JSON-LD insert, upsert and update, SPARQL INSERT DATA and INSERT … WHERE, Turtle insert and upsert; also graph sync, merge, rebase, push (a length set earlier in the same push, in novelty, or in the index, and a vector too long once the length is known, with its exact refusal);
    • bulk import of Turtle, of a TriG named graph and of JSON-LD, each with its exact refusal naming property and graph, and a vector too long; a refused import leaves no commits;
    • every ledger is indexed afterwards, by full rebuild and incrementally;
    • a ledger the v4.2.3 CLI wrote with two lengths on one property: writes refuse any other length, and its data moves to a new ledger by export and import once one length is kept; restored from an archive, the copy holds the source's vectors and refuses a further length.
  • it_store_load_failure (grp_index); a store fails to load there because its cache directory is a file:
    • the next request after a failed load loads again, and the ledger heals with no restart; no handle without the store is served meanwhile;
    • within store_load_retry every request gets the remembered failure without loading again, even once the store could load, and the first after the window loads;
    • a reload that can't load the store keeps the ledger it has;
    • a query, a commit's detail and a query at an earlier t get the load's error;
    • a datatype past the limit is refused in every state, never certified: with the store (422), through the ledger manager when the store fails to load (the load's error), and on a state built without the store (503); nothing commits and the ledger still indexes.
  • it_vector_lengths, a state built without the store (LedgerState::load_with_store: no range provider, no store, dictionaries seeded from novelty alone): insert, upsert, update and a vector insert, and the policy context the committers build first, are each refused with IndexNotLoaded and status 503, and nothing commits; with an older store attached, a write with and without vectors is refused the same way.
  • Consensus: the Raft commit worker poisons a 422 at once, both for the status alone and for the two refusals that carry it, and treats IndexNotLoaded as transient; the committer flattens IndexNotLoaded to its own SubmissionError, which is settled, and a keyed retry after it re-executes.
  • Server: the typed refusal and its flattened (committer) form answer 422 with err:db/InvalidTransaction and no Retry-After; IndexNotLoaded in both forms answers 503 with err:db/IndexNotLoaded and Retry-After, in the 503 allowlist and the exhaustive SubmissionError classification.
  • Python: a bulk import holding two lengths raises InvalidRequestError with status 422, naming the property.
  • Unit tests: the rule (fluree_db_core::vector, including a vector too long when the length is known), the refusal when the index isn't loaded (vector_dims, CurrentFacts, build_commit on a view built without staging), flake generation's refusal of a vector longer than 65,535 elements, the novelty lookup of a property's first vector (other values of the property, retractions, neighbouring properties, another graph), and the import spool's typed datatype-limit refusal.

Commits

  1. feat(core): one rule for the vectors a ledger can store.
  2. fix(transact): refuse a vector the ledger cannot store.
  3. test(api): vector lengths on every write path.
  4. docs: the length of a vector.
  5. Merge of main (fix(index): every xsd:double value is indexable #2044 and fix(server): query routes read a request's dataset the way the engine does #2019): both register a test module in grp_index.rs; the shared fixture is the same bytes.
  6. fix(api): refuse an unstorable vector with 422.
  7. fix(consensus): the Raft commit worker poisons a 422 refusal at once.
  8. fix(transact): a vector check that cannot read the index is not an InvalidVector.
  9. test(api): the two-length fixture test pins the migration only.
  10. fix(transact): refuse a vector when the attached index is older than the ledger's.
  11. Merges of main (07b424738, ac59bd9ed); no conflicts.
  12. 8ebc25448 fix(core): a vector too long to store is TooLong when its length is known.
  13. aef692057 docs(transact): how a commit lands only on the base its vectors were checked against.
  14. 20fccad5f fix(transact): refuse a write on an index this process has not loaded with a typed 503.
  15. a33eb40af fix(import): an import refuses a vector as a transaction does, naming its property and graph.
  16. 6af5b318e docs: pull, clone and restore copy a ledger as it is.
  17. f00eb71df test(transact): build_commit refuses a base whose index is not loaded.
  18. 590defe61 Merge of main (fix: JSON-LD graph scoping, config integrity and explicit-only SHACL #2009): ApiError::status_code/error_type and the submission weigher keep both ConfigUnavailable (500, err:storage/ReadFailure) and IndexNotLoaded (503). On a ledger whose index is not loaded, IndexNotLoaded is decided first, before the config read.
  19. 9d33c0f1c test(python): a bulk import refused for a vector raises InvalidRequestError.
  20. 22b02c648 test(api): the not-loaded state as a failed store load leaves it; a datatype past the limit.
  21. 2cc21c89b fix(api): a ledger whose binary store fails to load is not cached without it.
  22. e65ed7e46 test(api): a store that fails to load; a datatype past the limit in every state.
  23. 0cd67be0a test(api): a reload that cannot load the store keeps the ledger it has.
  24. 46c9218bb Merge of main (perf(binary-index): resolve a persisted subject's Sid without a reverse lookup #2119); no conflicts.
  25. 97e039302 style(api): parse_ttl_chunk returns its parse directly.
  26. 099459cb7 Merge of main (fix(indexer): a fact deleted before an incremental build stays deleted in a graph new to the index #2118, fix(transact): write fidelity, part 2 — one fact identity, microsecond temporals, value reads #2109): in push_commits the push's vector check stays ahead of the retraction check, which now reads through the evolving state.
  27. e2cc61a22 fix(transact): CurrentFacts refuses an index it has not loaded where it reads it, so the two readers main added (named_by, all_named_by) are covered too.

aaj3f added 10 commits October 12, 2026 10:31
`fluree_db_core::vector::check_vector` states which `f:embeddingVector`
values the index can hold: 1 to 65,535 elements, each a finite f32, and
the same length as the vectors the property already holds in that graph.
The vector arena now applies it when it stores a vector, so the write
paths can apply the same rule before they commit one.

`BinaryIndexStore::vector_dims` reads a property's vector length from the
arena manifest without loading a shard.
Every path that creates commits now checks its `f:embeddingVector` values
against `check_vector` before the write, as it checks the datatype limit:

- `build_commit` (transactions on every surface, merge, rebase, revert,
  graph sync) checks each vector against the length its property holds
  in that graph: the index's, else the first vector asserted since, else
  the first in the same commit.
- Push checks each pushed commit the same way, against the ledger and
  the earlier commits of the push.
- Bulk import stops with an error when its vector pool refuses a vector.
- Flake generation refuses an empty vector, as before, and now also one
  longer than 65,535 elements or with a non-finite element.

A refused write fails with `TransactError::InvalidVector` (HTTP 400) and
commits nothing.
`it_vector_lengths` (grp_index): a property keeps the length of its first
vector in novelty, in the index and in novelty over the index; one
transaction holds one length per property; each named graph keeps its
own; retracting the vectors keeps the length; 65,535 elements is the
most. Covered on JSON-LD insert, upsert and update, SPARQL INSERT DATA
and INSERT WHERE, Turtle insert and upsert, graph sync, merge, rebase,
push and bulk import. Each ledger is indexed afterwards, by full rebuild
and incrementally.

`tests/fixtures/vector-lengths-4.2.3` is a ledger the v4.2.3 CLI wrote
with two vector lengths on one property. The test pins that writes to it
refuse any other length, and that its data moves to a new ledger by
export and import once one length is kept.
A vector has 1 to 65,535 elements, and in each graph all the vectors of
one property have the same length, retractions included. Embeddings of
two lengths go on two properties or in two graphs.
Both branches register a test module in fluree-db-api/tests/grp_index.rs; both are kept.
A vector the index cannot store is a well-formed request whose value
breaks a constraint the ledger holds, the class the datatype limit is
in, so it now answers 422 rather than 400. The error type stays
`err:db/InvalidTransaction`, the type a 422 already has when the
committer flattens an error to its status, so the direct and replicated
paths agree.

Tests: the server maps the typed error and its flattened form to 422
with no `Retry-After`; every refusal in `it_vector_lengths` is 422.
`build_commit_failure` poisoned only a 400 or a 413 at once and staged
anything else again, so a 422 (the datatype limit, or a vector the index
cannot store) was staged three times, with back-off and a ledger refresh
between attempts, before it failed with the same status. A 422 is a value
that breaks a constraint the ledger holds; a lagging view can only miss
such a constraint, never invent one, so the refusal stands after a
refresh. It now poisons at once, like a 400.

The test adds 422 to the statuses that poison, and both 422 refusals as
`build_commit` returns them.
…nvalidVector`

When a ledger has an index but this process has no binary store attached,
the vector check cannot read the stored length, and it refuses the write
rather than certify it. That refusal is about the process's state, not
the request, so it is now a core error instead of `InvalidVector`.
`InvalidVector` then means only a value that breaks the rule.

A unit test covers the refusal, and that a ledger with no index takes
the first vector.
The test of the v4.2.3 ledger that holds two vector lengths now covers
what this change does with it: writes refuse any other length, and the
data moves to a new ledger by export and import once one length is kept.
…the ledger's

The vector check reads a property's stored length from the attached index
store, and otherwise from novelty. If the store attached is older than the
index the ledger's novelty starts from, a length indexed in between is in
neither, and the check would take any length. It now refuses the write in
that case, as it does when no store is attached at all.

The test indexes a ledger twice, gives a second property its first length
in the second index, then leaves the first index's store attached and
expects a vector write on that property to be refused.
@aaj3f aaj3f added bug Something isn't working as expected area:transact Staging, commit, import/bulk-import, novelty, retraction semantics labels Oct 13, 2026
@aaj3f
aaj3f requested a review from bplatz October 13, 2026 18:30
aaj3f added 3 commits October 14, 2026 05:59
Conflicts in fluree-db-api/src/error.rs and fluree-db-server/src/error.rs:
main's single status table (`ApiError::status_code`, `ApiError::error_type`)
kept, and the server's own table dropped as main drops it. `InvalidVector`
joins the datatype limit in the 422 arm and reads `err:db/InvalidTransaction`
in the `@type` table, with a row in the every-variant test. The server test
for a refused vector is kept.
…e-store test

The test left the older store attached but cleared the range provider. With
`shacl` enabled, staging reads the schema hierarchy through the provider, so
the write was refused by "no range_provider attached" before the vector check
ran, and the test failed under --all-features. It now attaches the older
index's provider alongside its store, a consistent stale state that staging
can read, so the refusal it expects comes from the vector check.

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. Please review the inline feedback before merging. One general note: restore is also unchecked (the server's /import, Python's restore_ledger and the CLI's create --from), while the description lists only pull and clone.

Comment thread fluree-db-transact/src/vector_dims.rs Outdated
store: Option<&'s BinaryIndexStore>,
) -> Result<Option<&'s BinaryIndexStore>> {
let refuse = |why: &str| {
Err(TransactError::Core(fluree_db_core::Error::other(format!(

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.

This refusal is a TransactError::Core, which maps to 400 InvalidTransaction, and Raft's build_commit_failure poisons a 400 as BodyMalformed. A binary store that failed to load (ledger_manager logs "continuing without" and keeps index_t > 0) therefore turns every vector write into a permanent 400 with no retry. Since this is the process's state, not the request's, a typed variant mapped to 503 with Retry-After, treated as transient in Raft, seems right; the stale-store test could then assert the status.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, and pulling on this went further than the status. On a ledger whose store failed to load, writes that read the index (an upsert, an update with a where) failed inside that read as a TransactError::Core, so a 400 that Raft poisons. Writes that read nothing from it committed without the checks that need the index, and that includes one that takes the ledger past its datatype limit, after which it can never be indexed. Nothing re-attempted the store load either: notify plans Noop, and a retrying client keeps the handle from going idle, so it stayed broken until a restart or a new index.

So it's two layers now:

  • 2cc21c8 stops the ledger manager from caching a ledger without its store. The load fails with its own error, a 500. Requests within store_load_retry (5 s) get that error without loading again, so a lasting failure is one load per window rather than one per request. The next request after the window loads again, and a reload that can't load the store keeps the ledger it had.
  • Your typed variant stays as the backstop, for a state whose attached store is older than the ledger's index or one a caller built without it. 20fccad adds TransactError::IndexNotLoaded and one O(1) check_index_loaded that each write lane calls before its first read; the vector check uses the same thing. It answers 503 + err:db/IndexNotLoaded + Retry-After on both the direct and committer paths: a new SubmissionError::IndexNotLoaded, settled so a keyed retry re-executes, and in RETRYABLE_503_TYPES.

On Raft both are transient. Worth knowing, though: a Raft client sees the 422 "submission poisoned" after three attempts either way, same as it did for the 400.

e65ed7e and 0cd67be cover a store that fails once and then heals, the retry window, the reload, and the datatype limit in every state.

Comment thread fluree-db-transact/src/vector_dims.rs Outdated
/// Refuse a commit on `base` that holds a vector the ledger cannot store.
///
/// `graph_ids` maps each named graph `base` holds to its id; `iri` names a
/// property or graph in the refusal. Runs under the ledger's write lock

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.

The non-handle commit() path holds no write lock. It's still race-free through verify_sequencing and the CAS publish, so the comment could say that instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, that comment was only right for the handle path. aef6920 rewords it: the handle path holds the write lock, and commit(), which holds none, lands only on the base it checked because of verify_sequencing plus the compare-and-set publish on that same head.

Comment thread fluree-db-core/src/vector.rs Outdated
return Err(VectorError::Empty);
}
let dims = match dims {
Some(expected) if usize::from(expected) != len => {

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.

When the length is already known, a vector over 65,535 elements reports LengthMismatch ("expected 3, got 65536") rather than TooLong. Only push reaches this, since flake generation catches it first for local writes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. 8ebc254 checks the u16 bound before comparing against the stored length, so a 65,536-element vector is TooLong whatever the property already holds, and the push test now asserts the exact refusal (… vector dims 65536 exceeds the maximum of 65535) with a length of 3 already set.

Comment thread fluree-db-transact/src/import_sink.rs Outdated
let handle = self
.vector_pool
.insert_f64(self.g_id, p_id, v)
.map_err(|e| CommitCodecError::InvalidOp(format!("invalid vector: {e}")))?;

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.

Import refuses with an untyped CommitCodecError string that doesn't name the property or graph. The docs say a write that breaks the rule is refused with Invalid vector (422), so either carry the type and IRI here or qualify the docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went with carrying the type rather than qualifying the docs. In a33eb40 the vector arena and the import's shared pool return VectorError, the spool refuses with the same InvalidVector a transaction gets (worded by one vector_dims::invalid_vector, so it names the property, and the graph when it's named), and ImportError::Invalid carries it out; the datatype limit rides the same route, since it had the same flattening. Tests cover Turtle, a TriG named graph and JSON-LD with exact messages. While in there I noticed the docs' "nothing in it is committed" isn't quite true for a large import, since import publishes a checkpoint every 50 chunks, so the docs now say what an import that stops keeps.

aaj3f added 13 commits October 19, 2026 08:29
…nown

`check_vector` compared a vector's length with the property's before
checking that the length fits a `u16`, so a vector of 65,536 elements on a
property of length 3 read "vector dims mismatch: expected 3, got 65536". No
stored length can admit it, so it is now `TooLong` whatever the property
holds. Only push reached this: flake generation refuses such a vector
first on a local write.

The push test now checks the exact refusal.
…checked against

The comment on `vector_dims::check_commit` said it runs under the ledger's
write lock. The handle path does; `commit()` holds none, and is race-free
because it checks that the base is the published head
(`verify_sequencing`) and publishes with a compare-and-set on that head.
… with a typed 503

A ledger whose binary store failed to load keeps its index `t` with no
range provider, so every read of it fails. Writes failed inside their
first read, with a core error that answered 400 `InvalidTransaction`, and
the Raft commit worker poisons a 400 at once. The vector check refused the
same state with a core error too. So a store that failed to load turned
every write into a permanent 400.

`TransactError::IndexNotLoaded` now names that state: the ledger has an
index, but no range provider is attached, or the binary store attached is
older than it. `check_index_loaded` decides it from the snapshot, in
O(1), and every write lane calls it before its first read:
`build_transact_policy_context` (the committers, push, Cypher, GraphQL),
`stage_with_graph_delta` (before the graph-management dispatch),
`stage_flakes`, `build_commit` (merge, rebase and revert reach it without
staging), and `CurrentFacts`, which merge and rebase read first. The
vector check's own refusal of an index it cannot read uses the same
function and variant.

It answers 503 with `err:db/IndexNotLoaded` and `Retry-After`, on the
direct path and through the committer: `SubmissionError::IndexNotLoaded`
carries it (settled, so a keyed retry re-executes) and the server
reconstructs it; the code joins `RETRYABLE_503_TYPES`. The Raft commit
worker treats it as transient, as it does any 503, and refreshes before
retrying.

Tests: the not-loaded and older-store states on every write lane through
the API, the policy context and `CurrentFacts`; the status tables, the
committer flattening, settlement, a keyed retry, and the Raft
classification.
… its property and graph

Bulk import refused a vector the ledger cannot store with an untyped
string: the vector arena's error became a `CommitCodecError`, then
"flake encode error: ...", then `ImportError::Transact(String)`, without
the property or the graph. The datatype limit took the same route.

The type now survives the whole way. The vector arena and the import's
shared pool return `VectorError`; the spool refuses with the same
`InvalidVector` a transaction gets, worded by the one
`vector_dims::invalid_vector` (property, and graph when it is named),
and the datatype limit stays `DatatypeLimitExceeded`. The sink's deferred
error is a `TransactError` (`encode_failure` keeps the old text for real
encode failures), the parse workers' channels carry `ImportError`, and
`ImportError::Invalid` holds a refusal, displayed as the refusal itself.
Python raises it as the transaction's refusal would be raised
(`InvalidRequestError`, status 422); the CLI and the server's import job
print it.

The docs now say what an import does: it stops with the same error and,
like an import that stops for any reason, keeps what it published at its
last checkpoint.

Tests: two lengths in Turtle, in a TriG named graph and in JSON-LD (the
lane Cypher and CSV imports feed), and a vector too long, each with its
exact refusal; a refused import leaves no commits.
Restore (the server's `/import`, Python's `restore_ledger`, the CLI's
`create --from <file>.flpack`) does not check vector lengths, like pull
and clone, and the module doc and the docs now say so and why. None of
them creates a commit: they copy a ledger's existing commits, and its
index, byte for byte, so the copy holds what its source holds and refuses
what its source refuses. A ledger an earlier release left with two
lengths still restores, which its move to one length by export and import
needs when the source is gone.

The new test restores the v4.2.3 two-length fixture from an archive and
checks that the copy holds the source's vectors and refuses a further
length.
Merge, rebase and revert reach build_commit without staging, so its own
check is the one that refuses them; every lane the API test drives meets
an earlier one.
# Conflicts:
#	fluree-db-api/src/error.rs
#	fluree-db-consensus/src/caching.rs
…tError

The import's refusal reaches Python as the transaction's would: status 422,
the message naming the property.
…atatype past the limit

The not-loaded tests now load the ledger without its store
(`LedgerState::load_with_store`), as `ledger_manager` holds it after a
store fails to load: no range provider, no store, and dictionaries seeded
from novelty alone. Stripping the store from a loaded ledger kept
dictionaries seeded from the index, which hid the datatype case.

In that state the datatypes the index holds cannot be counted, so a write
adding one past the limit would commit and leave a ledger that can never
be indexed. The new test checks it is refused and that the ledger still
indexes.
…hout it

When `load_and_attach_binary_store` failed, `get_or_load` logged
"continuing without" and cached a `Ready` handle with no store at the
index's `t`. Every range read of it fails, the checks that need the index
cannot decide (a write could take the ledger past its datatype limit, and
then it can never be indexed), each query loaded the store again on its
own, and nothing loaded it again for the handle: no notify plans a change,
and a retrying client keeps the entry from going idle. Only a restart, a
new index, or an idle half hour healed it.

Now the failure fails the load. The request gets the load's own error (a
500), and so do requests for `LedgerManagerConfig::store_load_retry`
(default 5 s), without loading again: the `Failed` entry bounds a lasting
failure to one load per window. The next request after it loads again. A
reload that cannot load the store keeps the state and store the handle
has, rather than swapping in one without a store. A ledger-state failure
(not found, say) is not remembered; it fails as before.
…very state

A store fails to load here because its cache directory is a file, which
fails every load the same way and is put right by making it a directory.

- The next request after a failed load loads again: no handle without the
  store is served meanwhile, and the ledger heals with no restart.
- Within `store_load_retry` every request gets the remembered failure
  without loading again, even once the store could load; the first after
  the window loads.
- Reads a ledger cached without its store still answered (a query, a
  commit's detail, a query at an earlier `t`) get the load's error.
- A datatype past the limit is refused with the store (422), through the
  ledger manager when the store fails to load (the load's error) and on a
  state built without the store (503); nothing commits and the ledger still
  indexes. It replaces the test of the last state alone.
aaj3f and others added 5 commits October 19, 2026 16:00
# Conflicts:
#	fluree-db-api/src/commit_transfer.rs
…it reads it

`main` added two readers (`named_by`, `all_named_by`) that read the index
without the check `of_slots` and `of_subject` made. The check now runs in
`base`, the one place every reader that reads the index reads it, so a
reader added later cannot skip it; `whole_graph`, which reads through its
own scan, keeps its own. The unit test covers the two new readers.
# Conflicts:
#	fluree-db-api/src/commit_transfer.rs
#	fluree-db-api/src/error.rs
@aaj3f

aaj3f commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging main in. Heads up: I have your review items (the 503 for an index this process hasn't loaded, the commit-path comment, the TooLong ordering, the typed import refusal, and the restore paths) addressed locally, plus a fix so a ledger whose index fails to load isn't cached without it. I'm merging your d300e8b25 into that now and will push shortly, so it may be worth holding the merge until then.

…tor-lengths

# Conflicts:
#	fluree-db-api/src/error.rs
@aaj3f

aaj3f commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Agreed the description was incomplete there. I looked at enforcing it on restore, but restore, like pull and clone, creates no commits: it copies the archive's commits and index byte for byte. So I think the right call is the exemption, stated precisely: the copy holds what its source holds and refuses what its source refuses, and refusing the restore would leave a ledger an earlier release wrote with two lengths unrestorable, which is exactly when the export → import move needs a loadable copy. 6af5b31 says that in the module doc and the docs and adds a test that restores the v4.2.3 two-length fixture from an archive and checks the copy refuses a further length. The description now lists every path that brings data in and which of them check. If you'd rather restore refuse outright, happy to talk it through.

@aaj3f
aaj3f merged commit eaa4c8e into main Oct 26, 2026
19 checks passed
@aaj3f
aaj3f deleted the fix/vector-lengths branch October 26, 2026 16:12
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