Repository navigation
fix: branch-aware reads + opt-in default context - #1200
Merged
Merged
Conversation
zonotope
approved these changes
Apr 28, 2026
zonotope
left a comment
Contributor
There was a problem hiding this comment.
The code looks fine, but I think it could be consolidated. You can take or leave those suggestions as you see fit.
| @@ -0,0 +1,73 @@ | |||
| //! Internal helpers that compose the nameservice's branched store helpers | |||
Contributor
There was a problem hiding this comment.
I think the functions defined here would be better placed at fluree-db-nameservice::branched_store. This module only defines two functions and it already relies heavily on the nameservice crate to do its work, so I don't think the extra module is justified.
| /// branch ancestry on read miss. Uses the live `NsRecord` if the ledger | ||
| /// state's cached record is in sync, otherwise falls back to a lookup by id. | ||
| #[cfg(feature = "embedded-orchestrator")] | ||
| async fn build_post_commit_store( |
Contributor
There was a problem hiding this comment.
I think this function could also move to the branched_store module, perhaps with a different name to both generalize it and differentiate it from the other branched content store helpers that return a flat content store on lookup failure.
Perhaps:
content_store_for_record_or_id-> returns a flat content store as a fallback to avoid an ns lookupbranched_content_store_for_record_or_id-> always returns a branched store, even if more ns lookups are necessary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related cleanups in one PR — both started from observed bugs and both center on "what does the API quietly do that the caller didn't ask for".
backend.content_store(ledger_id)and 404'd on every pre-fork ancestor. Every branched ledger that received a transaction was unreadable from the first write forward — query cache refresh and indexer retried in a loop.LedgerState. Direct API consumers got silent prefix expansion they never asked for, with no clean way to express "no prefix". The intent was always opt-in at the boundary; the implementation had drifted.Branch-aware reads
The codebase already had
BranchedContentStoreandLedgerState::build_branched_store, but they were only used on the initial load / full reload path. Other call sites built a flat branch-scoped store and handed it to a function that walks history or loads index blobs.Helper added —
fluree-db-nameservice/src/branched_store.rs:branched_content_store_for_record(backend, ns, &record) -> Arc<dyn ContentStore>branched_content_store_for_id(backend, ns, ledger_id) -> Arc<dyn ContentStore>build_branched_store(backend, ns, &record) -> BranchedContentStore(the recursive ancestry walker, exposed sofluree-db-ledgercan delegate)For non-branched ledgers both helpers return the flat namespace store (single nameservice lookup in the
_for_idvariant). For branched ledgers they walkrecord.source_branchrecursively to assemble the parent fallback chain.Sits in
fluree-db-nameservice(notfluree-db-core) so the indexer'sBackgroundIndexerWorkercan reach it without taking afluree-db-ledgerdep.Default-context opt-in
Field removed —
LedgerState.default_contextandCachedLedgerState.default_contextare gone. The eager loads inFluree::ledger(),LedgerManager::load_and_attach_binary_store, andload_graph_db_implare removed.Opt-in surface preserved:
Fluree::db(id)returns aGraphDbwithdefault_context = None→ no auto-injectionFluree::db_with_default_context(id)anddb_at_with_default_context(id, spec)fetch the context via the branch-aware helper and attach it to the returnedGraphDbonlydb_with_default_context(already did; unchanged)db_with_policy → db()(was already on the no-default path; unchanged)NsRecord.default_contextCID,LedgerConfig.default_contextCID,Fluree::get_default_context/set_default_contextadmin API) unchangedBehavior changes for the leak readers (all now consistent with the boundary policy):
Fluree::query_graph_source/sparql_graph_source(R2RML query path) — no longer auto-inject; only consumed by integration tests in productionCommitBuilder::executeIRI compaction — no longer falls back to ledger default; only honorsuser_context; only consumed by API integration testsThe HTTP server's standard query endpoint never relied on the leak.
Regression tests
it_branch::branch_incremental_index_resolves_pre_fork_parent— verified to fail withIndexTimeout(15000)without the indexer fix; passes in 0.42s with itit_notify_incremental::notify_branch_catch_up_resolves_pre_fork_parent— verified to fail with the exact production error text ("load commit during catch-up: Storage error: Failed to read commit envelope … Not found") without the catch-up fixit_default_context::*(3 cases) — verified that test 2 fails when the opt-in gate is removed; all pass with it in placeDocs
docs/design/storage-traits.md— added section on the new helpers and the rule that any commit-chain or index-blob walker must use themdocs/getting-started/quickstart-ledger.md— corrected the "Setting Default Context" section (transactions never updated default context; only import + explicitset_default_contextdo; spelled out the API vs CLI/server distinction)