Repository navigation
Seal named-graph annotations, and recover arenas fluree index left unsealed - #1887
Conversation
Two subsystems held different conventions about where a flake's graph
lives, and they met at a check that reads the disagreement as forgery.
The base-index range decoder does not put a graph on the rows it decodes
— the graph rides on the query's `g_id`, not the row, so every `Flake` it
builds has `g: None`. `EdgeKey::from_reifies_facts` cross-checks the
`f:reifiesGraph` object against the bundle's flake-level `g` and treats
disagreement as a tampered bundle. A named-graph bundle read from the
base index therefore says "I reify g1" on one axis and "I live in the
default graph" on the other, and was rejected as `GraphMismatch`.
The scan was never blind to named graphs: it reads the bundle in full.
Instrumenting it shows one row for each of the four reifies predicates at
the named graph's `g_id`. The loss was entirely in the decode that
follows, behind a `let Ok(..) else { continue }`.
The scan knows which graph it asked for, so it now stamps that graph onto
the rows the reader left bare, before decoding. Doing it at the caller
rather than in the decoder keeps the cost on this scan instead of on
every flake of every query, and leaves the tamper check intact: a bundle
whose `f:reifiesGraph` names a different graph than the one it was read
from still fails.
Also stops that arm discarding a genuine signal. Every `EdgeKeyDecodeError`
means "malformed or tampered", and the scan swallowed it without a word,
which is how this defect stayed invisible for as long as it did. It is
now logged with the annotation and the reason. A guard whose rejection is
discarded is not a guard.
This is what closed the remaining gap in #1859: with the forward lookup
seeing named-graph bundles, export represents them like any other.
`fluree index` resolved no attachment-event coverage and sealed no arena, while root assembly set the sticky `had_annotation_arena` bit regardless — and that bit is what gates the base-index bootstrap, so the ledger could never recover. Measured on the reported repro: after `insert` + `index` the ledger sits at `has_annotations=true, annotation_index=None, had_annotation_arena=true`, and two further `reindex` passes leave it exactly there. The cause is that the attachment-events provider reads from a running `LedgerManager`. A one-shot CLI process has none, so `attachment_events_provider()` returns `None` and the resolution branch never runs at all. `Fluree::reindex` already handles this by falling back to coverage derived from the loaded ledger state, which is why `reindex`-first seals an arena and `index`-first never does. `fluree index` now makes the same call, through a shared `Fluree::attachment_coverage_from_state` rather than a second copy of the logic. On the repro the ledger reaches `annotation_index=Some` on the first pass. This stops ledgers entering the unrecoverable state. It does not recover ledgers already in it: that needs a way past the sticky bit, which is deliberately conservative because a live-only rebuild cannot see retraction history, and is not part of this change.
Item 1 stops ledgers entering the state where `has_annotations = true`, `annotation_index = None` and the sticky `had_annotation_arena` bit is set. It does nothing for ledgers already in it, and until now nothing could: the bit is coerced to `true` by every indexer-produced root with annotations — `IncrementalRootBuilder::build()` and root assembly's `encode_and_write_root_v6` both do it — so no later pass clears it and the base-index bootstrap that would rebuild the arena never runs again. The only existing way past that gate was `FLUREE_FORCE_ANNOTATION_BOOTSTRAP`, an env var marked EXPERIMENTAL whose own documentation said it was "not a substitute for fixing the bit to track actual seals/retracts". That fix is not possible. A retracted `f:reifies*` row leaves no trace in the index — not even an `op=false` row, measured on an assert-then-retract-then-reindex fixture — so no pass can distinguish a ledger whose arena was never sealed from one whose arena was sealed and then dropped. Only the first is safe to rebuild from currently-live bundles, and that is the original defect restated: the bit is one boolean covering two states that cannot be told apart after the fact. So the operator acknowledges the hazard rather than the code detecting it. `--rebuild-annotations` requires `--force`, refusing rather than prompting because the people who need it are recovering a stuck ledger from a script. `--force` is this CLI's existing confirmation idiom, the same flag and the same refuse-don't-prompt behaviour `fluree drop` uses. The refusal names the condition of safe use as well as the hazard: a user who knows their arena was never sealed is the entire population this flag is for. The gate is a CLI concern. `ReindexOptions::with_rebuild_annotations(true)` takes the flag at face value — a programmatic caller setting a typed option has already made the decision, and a library that refuses its own option is an annoyance rather than a safeguard. The doc comment says so, so nobody later "fixes" the API to match the CLI. Asking for it against a remote is refused rather than ignored: the remote reindex API does not carry the flag, and a repair that reports success without repairing anything is the worst of the three outcomes.
`encode_iri` returns the split form whenever a namespace prefix is registered. The write path does not always store that form: `NamespaceRegistry::sid_for_iri` allocates a code per prefix and, once the namespace table overflows, stores the graph as `Sid::new(OVERFLOW, iri)` with the full IRI as the name. `ensure_code` documents OVERFLOW as a sentinel that is never registered, so the read side finds no prefix and falls to `Sid::new(EMPTY, iri)`. Same name, different namespace code. The result is a seek key that lands on the wrong span under the derived `Ord` and reports "no annotations" rather than failing — the exact silent mode `ExportResolver::resolve_subject_sid` warns about, which is why that function tries `find_subject_sid` first and only then falls back. Both graph-Sid sites now do the same. The store is reachable at each: `BinaryRangeProvider::store()` is public and this crate already performs the downcast in `ledger_manager`, so this needed no core API change. Reported in review as a latent risk. Five deliberately varied graph IRIs — http, urn:uuid, deep path, fragment, tag: — all agreed between the two derivations, because every namespace in that fixture was allocated a real code; nothing about IRI *shape* reaches this, since the trigger is table pressure. The mechanism was confirmed by reading the write path rather than by reproducing the symptom, and the fix is correct whether or not a fixture exists. Not fixed here, and filed separately: `LedgerSnapshot::build_reverse_graph` has the same mismatch on the novelty routing path, where an overflowed graph would be keyed `(EMPTY, iri)` against a stored `(OVERFLOW, iri)`. Its `ok_or_else` error branch is also dead, because `encode_iri` returns `Some` unconditionally. Unmeasured, outside this surface, and a core question that should not be settled inside an export change.
The base moved 75 commits (main merged into it, plus the review remediation). One conflict, in `fluree-db-cli/tests/integration.rs`, and it was semantic rather than textual — a mechanical "keep both sides" spliced mid-function and broke the build. Two tests arrive from the base that this branch's fix invalidates, and each is resolved on its merits: `export_reports_annotations_it_could_not_resolve` asserts the named-graph defect. This branch repairs it, so the assertion had to invert rather than disappear; that conversion already exists here as `a_named_graph_annotation_exports_with_its_marker`, and the base's stale copy is dropped in its favour. `the_unresolved_counter_still_fires_when_it_should` used the named-graph fixture as its `MustFire`, and this branch is precisely what makes that fixture resolve. The canary expired on schedule — its own doc comment on the base predicted this and said the replacement wanted was a bundle the decoder rejects outright. No such replacement can be written, and that is a finding rather than a gap. `EdgeKey::to_reifies_facts` emits the flake-level graph and the `f:reifiesGraph` object from the same `self.g`, so the two views `from_reifies_facts` cross-checks are written from one value and cannot disagree: `GraphMismatch` is unconstructible from any legitimate write, not merely hard to construct. Every write surface also rejects hand-written `f:reifies*`. So the counter is not dead code — it is a corruption guard whose remaining triggers are tampered or partial bundles, and being unreachable through supported APIs is that guard working rather than failing. The determination is recorded where it will be read, on `unresolved_count` itself, together with the reason there is deliberately no test driving it above zero. What stays tested is that it remains silent on every path that should resolve, which is the assertion that would break if the accounting were removed along with the defect.
One conflict, in `fluree-db-cli/tests/integration.rs`, resolved by taking main's file and re-applying the five tests that exist only here — computed by name rather than remembered, since a textual "keep both" on this file spliced mid-function last time. Two tests arrive from main that this branch's fix invalidates, and both are removed for the same reason as the previous merge: `export_reports_annotations_it_could_not_resolve` asserts the named-graph defect that this branch repairs, and its converted form already lives here as `a_named_graph_annotation_exports_with_its_marker`. The canary `the_unresolved_counter_still_fires_when_it_should` used the named-graph fixture as its `MustFire`, and this branch is what makes that fixture resolve — the expiry its own doc comment predicted. `fluree-db-api/src/indexer_attachment_provider.rs` and `export_annotations.rs` auto-merged, which is not a semantic guarantee: main brought the caller-owned `to_t`, the hoisted arena reader and the value-parsing scan flag into the same functions this branch stamps the graph `Sid` in. `cargo check --workspace --all-targets` is clean on the result.
| rebuild: RebuildAnnotations, | ||
| ) -> CliResult<()> { | ||
| let rebuild_annotations = rebuild.resolve()?; | ||
| if rebuild_annotations && remote_flag.is_some() { |
There was a problem hiding this comment.
This only catches an explicit --remote. Without --direct, try_server_route below routes to a running local server, and client.reindex does not carry the flag.
Repro: with fluree server start running, fluree reindex s --rebuild-annotations --force on a stuck ledger prints Reindexed s:main to t=1 …, exits 0, and the arena is still unsealed (arena=false, had_annotation_arena=true).
Suggest refusing when the resolved mode is LedgerMode::Tracked (covers both paths), pointing at --direct.
| /// And with the acknowledgement it runs. `--force` is this CLI's existing | ||
| /// confirmation idiom, the same flag `fluree drop` requires. | ||
| #[test] | ||
| fn rebuild_annotations_proceeds_once_acknowledged() { |
There was a problem hiding this comment.
This does not exercise the flag. The fixture never runs fluree index first, so had_annotation_arena is unset and reindex seals via the snapshot.t == 0 branch without consulting force_rebuild.
Removing force_rebuild || from the gate in attachment_events_from_state leaves all four rebuild/index tests passing, and removing the index fallback kills nothing either (M15). So neither #1882 fix is pinned.
Suggest asserting annotation_index.is_some() directly: an api test beside post_defensive_drop_stays_in_scan_fallback for with_rebuild_annotations(true), and a CLI unit test calling index_ledger. Worth including the case of a sealed arena followed by a non-annotation commit + fluree index, which drops the arena permanently on main and is fixed here, but untested.
| // seals an arena and `index`-first never does. Same call | ||
| // `reindex` makes, so the two paths now agree. See #1882. | ||
| if config.attachment_events.is_none() { | ||
| config.attachment_events = fluree.attachment_coverage_from_state(ledger_id).await; |
There was a problem hiding this comment.
In the one-shot CLI there is no LedgerManager, so ledger_cached above is a full ledger() load, and attachment_coverage_from_state loads the ledger again. fluree index now does one extra load for every ledger and two for annotated ones; fluree doc reaches this via index_ledger too.
Measured on 100k triples of novelty (debug build): main 4.5s; this branch 6.3s unannotated, 8.1s annotated.
Suggest passing the already-loaded state (handle.snapshot().await.to_ledger_state()) instead of the ledger id, which drops the second load.
|
A few further observations:
|
bplatz
left a comment
There was a problem hiding this comment.
Approving: both issues reproduce on current main, and this branch fixes them. Verified with the issue repros, recovery of a ledger stuck by main's fluree index, and the new CLI tests on the branch merged with main.
Merge with main conflicts in two files, both from the typed LedgerId refactor on main; the resolution is mechanical:
fluree-db-api/src/admin.rs(reindex): take main'slet ledger_id = LedgerId::parse(ledger_id)?;and keeplet rebuild_annotations = opts.rebuild_annotations;.fluree-db-cli/src/commands/index.rs(index_ledger): keep this branch's block, withprovider.attachment_events(handle.id())as on main.
With that resolution the workspace type-checks and the export/rebuild CLI tests pass (30/30).
Please address the review feedback before merging: the three inline comments (rebuild flag dropped on server auto-route, #1882 fixes not pinned by a test, extra ledger loads in fluree index) and the follow-up observations.
# Conflicts: # fluree-db-api/src/admin.rs # fluree-db-api/src/indexer_attachment_provider.rs # fluree-db-cli/src/commands/index.rs
With named-graph bundles decoding on every source, a ledger whose arena was never sealed exports and queries the same as one whose arena was: the scan fallback answers correctly, only slower. Rebuilding past the sticky had_annotation_arena bit therefore buys speed alone, at the cost of discarding retraction history in the case it cannot detect, and the bit and the arena it guards are gone in the next major's storage format. This removes the flag, its --force acknowledgement, the ReindexOptions::rebuild_annotations option and its tests. FLUREE_FORCE_ANNOTATION_BOOTSTRAP stays as the operator override it was.
…verage fluree index loaded the ledger through ledger_cached, which in a one-shot CLI process is a full load, to read the annotation gate, and attachment_coverage_from_state then loaded it again. Without a LedgerManager it now loads once and derives coverage from that state; attachment_coverage_from_state takes the state rather than an id. The provider path, taken when a LedgerManager exists, is as it was. The CLI test now asserts the arena itself: sealed by the first fluree index, and still there after a later one with no new annotations. Export reads the same with or without the arena, so it could not tell.
docs/cli/export.md is a reference page: it now says named-graph annotations export like any other, without the decoder internals or a release number, which 4.2.0 through 4.2.2 contradict. The test comments cite #1859, the issue the named-graph fix closes, and drop the release number too.
fluree index resolved annotation coverage by loading the ledger before every build: the build streams commits and never holds the novelty the coverage is read from, so each run decoded its unindexed commits twice, on every ledger, annotated or not. What that bought was the annotation arena on CLI-indexed ledgers, a speed-up only: with named-graph bundles decoding on the base-index scan, a ledger without an arena reads and exports the same. Annotations are rare, and the next major replaces the arena with links its own index build derives, so the cost lands on every ledger for a gain that is about to go away. fluree index and the design notes are as on main again.
|
Pushed changes to get this ready for the next 4.x release. This PR now fixes #1859 only.
Why the #1882 half is out. Sealing the arena from The #1859 fix costs ledgers without annotations nothing: the scan returns before the new code when the snapshot has no annotations. The body's |
Brings #2201, #2383, #1887 and the v4.2.8 release. - Release: next keeps its 5.0.0-alpha.3 version lines and lockfiles; the lockfiles gain only #2383's hashbrown. - #1887 (named-graph annotations on the base-index seal scan) does not apply: next has no annotation arena, seal scan or scan source. next's files are kept, and main's CLI test, which expects f:reifies* output under --raw-reifies, is dropped; export_resolves_named_graph_annotations covers the case. - #2201 applies: next's vector arena keys each stored fact by its own handle too. The fast-count guards take main's checks on next's call shapes; the export list keeps next's GraphTree and drops SharedLeafBytes, which next removed. The store tests write shards to next's content store. - #2383: the collection fold is main's linear walk with next's reifier, triple-term and graph-name rules, and the shared set is consulted rather than cloned per graph. The JSON-LD @type dedup keeps next's IRI-or-blank test. list_view.rs is next's, with an of_predicates for the planner test; the batch-at-a-time list read is ported in the next commit.
Edge annotations written inside a named graph were dropped by the seal scan and never reached the annotation arena, so
fluree exportcould not represent them. Andfluree indexleft an annotated ledger's arena permanently unsealed, with no way back. This fixes both, and addsfluree reindex --rebuild-annotations --forceto recover ledgers already stuck.Fixes #1859
Fixes #1882
#1875 has merged and this PR auto-retargeted to
main. BothFixeslines are therefore live. GitHub computes a PR's closing set when the body is saved and does not recompute it on a retarget, so the keywords registered as empty until this body was re-saved;closingIssuesReferencesis asserted by value rather than read off the text below. Seedocs/contributing/issue-linking.md.1. Named-graph annotations — two conventions meeting at a forgery check
Two subsystems held different conventions about where a flake's graph lives, and they met at a check that reads the disagreement as forgery.
The base-index range decoder does not put a graph on the rows it decodes: the graph rides on the query's
g_id, not the row, sofluree-db-query/src/binary_range.rsbuilds everyFlakewithg: None.EdgeKey::from_reifies_factscross-checks thef:reifiesGraphobject against the bundle's flake-levelgand treats disagreement as a tampered bundle. A named-graph bundle read from the base index therefore claims to reifyg1on one axis and to live in the default graph on the other, and was rejected asGraphMismatch.The issue guessed at two causes — the PSOT order not being built per named graph, or the range being scoped wrong. Both were wrong. Instrumenting the scan shows the range returning one row for each of the four reifies predicates at the named graph's
g_id. The scan reads the bundle in full; the loss was entirely in the decode that follows, behind alet Ok(..) else { continue }.The fix stamps the graph at the caller. The scan already loops per
g_idand knows exactly which graph it asked for, so it fills in what the reader left bare before decoding. Doing it there rather than in the decoder keeps the cost on this scan instead of on every flake of every query, and leaves the tamper check intact: a bundle whosef:reifiesGraphnames a different graph than the one it was read from still fails.That single fact retrodicts every previously-confusing observation: the default graph worked because
None == None; the novelty overlay worked because its flakes carry a real graph; a sealed arena worked because it was sealed from novelty; and only the base-index scan failed, because it is the one source yieldingg: None. It also exonerates the arena builder, which was under suspicion.The same line also stopped discarding a real signal. Every
EdgeKeyDecodeErrormeans "malformed or tampered", and the scan swallowed it without a word — which is how this defect stayed invisible. It is now logged with the annotation and the reason. A guard whose rejection is discarded is not a guard.2.
fluree indexleft the arena permanently unsealedThe attachment-events provider reads from a running
LedgerManager. A one-shot CLI process has none, soattachment_events_provider()returnsNoneand the resolution branch never ran at all.fluree indexhanded the indexer no coverage and sealed nothing, while root assembly set the stickyhad_annotation_arenabit regardless — and that bit is what gates the base-index bootstrap.Fluree::reindexalready had a fallback for exactly this, which is whyreindex-first sealed an arena andindex-first never did.fluree indexnow makes the same call through a sharedFluree::attachment_coverage_from_state. Measured on the issue's repro:has_annotations=true, annotation_index=None, had_annotation_arena=truebefore,annotation_index=Someon the first pass after.3. Recovering ledgers already stuck, and why it needs an acknowledgement
Three prescriptions for this half were wrong, two of them mine. The reasons are the useful part, because they are the three most obvious ideas and the next person will reach for all of them.
fluree indexleaves an annotated ledger's arena permanently unsealed, andfluree reindexcan't recover it #1882's own option 2 — "don't set the bit on a pass that sealed nothing". It assumed sealed nothing implies consumed nothing. A pass that consumed annotation retract events and sealed no arena leaves the base index unable to reproduce them, so this would have reintroduced the exact data loss the bit exists to prevent.root_assembly.rs:340initialises the bit tofalseand the two seal-sites set it only on a real seal — butroot_assembly.rs:504coerces it back totrueon any annotated ledger. This read an initialiser and stopped sixty lines short of the coercion.The root-cause fix the env var's own doc prescribes — "fixing the bit to track actual seals/retracts" — is impossible, and this was measured rather than argued. On an assert → by-
@idretract → reindex fixture, the seal scan runs and finds zerof:reifies*rows in every graph: not even anop=falserow. The retraction leaves no trace in the index. So no pass can distinguish a ledger whose arena was never sealed from one whose arena was sealed and then dropped, and only the first is safe to rebuild from currently-live bundles. That is the original defect restated — one boolean covering two states that cannot be told apart after the fact — and it is precisely why an acknowledgement replaces an automatic guard.So
fluree reindex --rebuild-annotationsrequires--force, and refuses rather than prompting, because the people who need it are recovering a stuck ledger from a script.--forceis this CLI's existing confirmation idiom, the same flag and the same refuse-don't-prompt behaviourfluree dropuses ("Required flag to confirm deletion"). The refusal names the condition of safe use as well as the hazard, because a user who knows their arena was never sealed is the entire population the flag is for.The gate is a CLI concern.
ReindexOptions::with_rebuild_annotations(true)takes the flag at face value — a programmatic caller setting a typed option has already decided, and a library that refuses its own option is an annoyance rather than a safeguard. The doc comment says so, so nobody later "fixes" the API to match. Asking for it against a remote is refused rather than ignored: the remote reindex API does not carry the flag, and a repair that reports success without repairing anything is the worst of the three outcomes.Verification
Mutation testing, run against post-
fmtsource and restored green afterwards:index's coverage fallbackM15 is reported rather than papered over. After the named-graph fix, a sealed arena and an unsealed one produce identical export output, so
fluree index's remaining effect is which source answers and how fast — not what comes out. It is verified by direct measurement on the issue's repro, but no test fails without it. The only way to pin it is a user-visible signal fromfluree index, whichcreate --fromhas ("Annotation arena sealed.") andindexdoes not; #1882 calls that out separately and it is not taken here.Tests added at both levels, which fail for different reasons and do not substitute for each other:
fluree-db-cli/tests/integration.rscovers the named-graph export, the insert-then-index round trip, and all three branches of the acknowledgement gate;fluree-db-server/tests/export_scan_source.rsdrives the same fix over a realPOST /exportthrough the kill switch, which is the only way to select the scan source.Gates:
cargo fmt --all --checkclean;cargo clippy --all-targets -- -D warningsclean onfluree-db-api,fluree-db-cli,fluree-db-server;cargo check --workspace --all-targetsclean; 4138 tests passed, 0 failed across the three crates.Documentation corrected, including two sentences from #1875
docs/cli/export.mdsaid named-graph annotations "are dropped when export falls back to the base-index scan, which is blind to them", and that the two annotation sources "agree except on annotations inside a named graph". Both were true when written and are wrong as of this fix; the kill-switch note returns to its original wording, which is true again.docs/design/edge-annotations.mdsaid a stuck ledger stays in scan-fallback "until the next provider-backed reindex re-seals" — it never does, and that paragraph now says why and names the flag.