Skip to content

fix(config): a branch or a copy reads its source's ledger config - #2249

Merged
bplatz merged 15 commits into
mainfrom
fix/config-graph-across-ledgers
Nov 6, 2026
Merged

bplatz merged 15 commits into
mainfrom
fix/config-graph-across-ledgers

Conversation

@bplatz

@bplatz bplatz commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

A branch or a copy reads its source's ledger config

A commit lists the graphs it writes by full IRI, and a ledger's config graph IRI names the ledger: urn:fluree:mydb:main#config. A ledger replaying commits written under another name registered that IRI as an ordinary graph and read its own, empty, config slot. Two cases on main:

Fix

  • In replayed history, any ledger's config graph IRI names the config graph. The graph registry routes it to the config slot without allocating a user graph, so a branch, or a copy under another name, replays its source's config writes into its own config graph. A commit lists one config graph IRI: a merge carrying config under two moves the flakes to one. Bulk import refuses any config graph IRI, as it already refused the ledger's own.
  • Index roots carry the building ledger's system graph IRIs. An incremental build accepts any ledger's txn-meta IRI at slot 0 and relabels slots 0 and 1, so a copy's root, or one a branch adopted from its source, is relabelled by its next build instead of falling back to a full rebuild.
  • Merges, rebases and reverts name the config graph one way before folding. One setting under two config IRIs (the parent's, merged in or from before the fork, and the branch's own) otherwise counts as two facts: TakeSource/TakeBranch left both values and the operation was refused (409), and a revert holding the retraction under one IRI and the assertion under the other lost the setting.
  • Push routes every config graph IRI it carries. A branch's history holds config under its source's IRI before the fork and its own after. Push kept one graph Sid per graph id, so the other's flakes were unroutable and the push failed.
  • Each branch names its own system graphs. A query or write naming the config or txn-meta graph IRI of another ledger, or of another branch of this one, names that one, not this branch's: a dataset (FROM, FROM NAMED, a JSON-LD from member) refuses it (400) with a message naming the endpoint's own graph IRI, an update's WHERE reads it as no graph, and a write or bulk-import block is refused (400), also when wrapped as L#<g>. A connection query reads the branch the IRI names. The IRI is judged as written, before the registry canonicalizes it, so config and txn-meta still reach slots labelled with a source's inherited IRIs, as does the branch's own IRI.
  • The full-text indexer finds config under any config graph IRI. Background and CLI index builds skip the config read when no commit registered the config graph; they looked for the ledger's own IRI only, so a branch or copy that inherited f:fullTextDefaults indexed none of its configured properties.
  • Reserved-graph guards recognize any ledger's config graph IRI. A cross-ledger f:graphSelector naming one, or one the model ledger's registry reads as its txn-meta or config graph, is refused (ReservedGraphSelected), and the Graph Store route refuses one (400), as each already refused the ledger's own. Before, another ledger's config graph IRI passed both guards: the selector read the model ledger's config graph as policy, and a Graph Store POST wrote this ledger's config.
  • A general merge refuses a target that moved under it. Its diff and conflicts are the target's as of the head it read first, but it staged on the head it locked, so a commit landing in between was never checked against the source's changes: an abort-strategy merge went through over a conflicting commit. It is now refused (409), as a fast-forward that loses the race is. The target's write lock is taken after the source fold again, so the target's writers do not wait while the merge reads the source's history.

Behavior changes

  • Merging from a branch the target was created from now carries that branch's config changes since the fork, as the fork carried the earlier ones. A setting both changed is a conflict the merge's strategy resolves. Config written on a branch still does not merge into its parent or a sibling (409). A branch's config stays its own after the fork: later config changes on its parent reach it only through such a merge.
  • A target that adopted another branch's index (older direct fast-forward merges) reads its config again without a reindex; its next build relabels the graphs. The cookbook's repair section is replaced accordingly.
  • A push, a pull or an archive restore from a ledger of another name now changes the receiver's config, as it already did between ledgers of the same name.
  • A general merge whose target takes a commit while the merge is prepared fails with 409; re-run it.
  • A branch names its system graphs as config and txn-meta or by its own IRIs, not by its source branch's. On main, a branch of an indexed ledger also read its config and txn-meta graphs by the source's IRIs, which its slots held until the next index build relabelled them; that is now a 400. A write naming another ledger's or branch's config graph IRI, which went to this ledger's config, and one naming another's txn-meta graph IRI, which created an ordinary graph by that name, are refused (400).

Breaking changes

For embedders of fluree-db-* crates:

  • StageOptions::{graph_sids, with_graph_sids} are now {graph_ids, with_graph_ids}, and the map is inverted: HashMap<Sid, GraphId>, so several Sids can name one graph.
  • fluree_db_core::first_t_where_graph_registered takes a predicate on the graph IRI (impl Fn(&str) -> bool) instead of one IRI.
  • SharedResolverState::from_index_root takes the id of the ledger being built, whose system graph IRIs the resolver uses.
  • GraphRegistry::graph_id_for_iri answers CONFIG_GRAPH_ID for any ledger's config graph IRI, registered or not.
  • fluree_db_core::TargetError and GraphPosition gain an OtherLedgersSystemGraph variant, and TransactError gains OtherLedgersConfigGraph and OtherLedgersTxnMetaGraph; an exhaustive match needs an arm.

Upgrade

An index built before this change can hold another ledger's config graph as an ordinary graph: a branch created before its source's first index build, or a copy under another name, then indexed. Such a ledger is left as it is: it reads that graph as an ordinary graph, as before, so its source's config does not apply to it, and incremental index builds keep that layout. Nothing is refused and nothing is rebuilt unasked. fluree reindex <ledger> rebuilds the index from the commits, after which the source's config applies; the reindex reads the configured full-text properties from the commits too, so one reindex restores both.

Tests

a_branch_of_an_unindexed_ledger_applies_its_config (#2069) and a_copy_under_another_name_applies_its_sources_config (#2179, through an archive restore, with and without its index) fail on main. Each of these fails with its fix reverted:

  • a_push_carrying_config_under_two_iris_applies_both: a branch's history pushed to a ledger of another name, read as pushed and after a reload.
  • a_branch_or_copy_indexes_its_sources_full_text_property: a branch and a copy through a first and a second index build.
  • an_index_holding_a_config_graph_as_an_ordinary_graph_keeps_it_until_reindexed: served as before, kept by an incremental build, and one reindex restores the config and the configured full-text property.
  • a_merge_into_an_index_holding_a_config_graph_as_an_ordinary_graph_keeps_it: a merge from the source lands its config changes where that index reads them.
  • a_sources_policy_governs_its_branch_and_copy: on a branch of an unindexed source, indexed and not, and on a copy, a request with no policy of its own sees only what the source's policy allows and writes the one property it may modify, while its writes to the config, by the keyword or by its own config graph IRI, and to the policy rules are refused (403).
  • a_branch_reads_config_by_its_own_urn_and_urn_named_graphs_stay_graphs: on a branch of an unindexed and of an indexed main, main's config URN is refused on the branch's view (FROM, FROM NAMED) and through query_from(), naming the branch's own, and a connection query naming it reads main's config; main's txn-meta URN is refused too, and the indexed branch holds both of main's URNs at its slots.
  • an_updates_where_reads_another_branchs_config_graph_iri_as_no_graph and an_updates_where_reads_the_sources_txn_meta_graph_iri_as_no_graph.
  • a_write_to_another_ledgers_system_graph_iri_is_refused (config graph IRIs in TriG, JSON-LD and SPARQL, txn-meta graph IRIs, each also wrapped as L#<g>) and a_branch_cannot_write_under_its_sources_system_graph_iris.
  • a_config_graph_selector_is_refused_in_any_ledgers_name and a_selector_the_registry_reads_as_a_system_graph_is_refused: a cross-ledger selector naming the model's config graph by its own IRI or another ledger's.
  • graph_store_http::request_errors: GET, PUT and POST of the ledger's own and another ledger's config graph IRI.
  • general_merge_loses_race_to_a_target_commit_during_its_preparation: a conflicting commit on the target after the merge reads its head, through a nameservice that pauses after that lookup.

Three it_branch_shacl tests relied on #2069: each forked a branch from a never-indexed main and had it write a value main's uniqueness or SHACL config forbids, which the branch accepted only because it read no config. The branch now refuses it, so the general merge collides two values each branch took on its own, the fast-forward case commits the value without the check (as history from before it would), and the config-carry case expects the refusal naming main's config graph.

Also: a merge carrying config under two IRIs, config merged from a parent and refused from a sibling, an adopted index relabelled by the next build, a setting both branches changed under each strategy (merge, preview and rebase), and a revert across two config IRIs.

Follow-up: #2251 — its replay of drop records is to skip reserved graphs, so a record naming a config graph IRI never drops the config graph.

Fixes #2069
Fixes #2179

A ledger restored under another name, or a branch of a ledger that had
no index when it was created, replays commits that wrote the source's
config graph (`urn:fluree:<source>#config`). Those IRIs were registered
as ordinary graphs, so the copy or branch read no config: configured
policy failed open and uniqueness went unenforced (#2179, #2069).

Any ledger's config graph IRI now names the config graph. The graph
registry routes it to the config slot without allocating a user graph,
on replay and when an index root lists it. A write naming another
ledger's config graph IRI is stored under the ledger's own (TriG,
JSON-LD and SPARQL). A commit lists one config graph IRI: a merge
carrying config under two moves the flakes to one. Bulk import refuses
any config graph IRI, as it refuses the ledger's own.

An index root takes the building ledger's system graph IRIs: an
incremental build accepts any ledger's txn-meta IRI at slot 0 and
relabels slots 0 and 1, so a copy's or an adopted branch's root is
relabelled by its next build instead of falling back to a full rebuild.
A root that lists a config graph IRI as a user graph is rebuilt.

A merge from a branch the target was created from now carries that
branch's later config changes into the target, as the fork carried the
earlier ones; before, on a branch of an unindexed ledger, it landed in
an unread graph. Config written on a branch still does not merge into
its parent or a sibling (409).

Tests: a_branch_of_an_unindexed_ledger_applies_its_config,
a_copy_under_another_name_applies_its_sources_config,
a_write_to_another_ledgers_config_graph_iri_writes_the_config_graph,
a_merge_of_config_under_two_config_graph_iris_commits_one,
a_merge_carrying_config_written_on_another_branch_is_refused (parent
config merges into the branch, fast-forward and general),
adopted_branch_index_is_relabelled_by_the_next_cycle.
Any ledger's config graph IRI names the config graph, so a branch's
history can hold one setting under several IRIs: its parent's, merged
in or from before the fork, and its own. Merges, rebases and reverts
folded and compared facts by graph Sid, so one setting under two IRIs
counted as two:

- A setting both branches changed was no conflict, so TakeSource and
  TakeBranch left both values and the merge or rebase was refused (409,
  two values for a single-valued setting).
- A fold holding a retraction under one IRI and the assertion under the
  other committed both at one t, where the retraction wins: reverting a
  merged-in reasoning change together with the branch's own change back
  left the branch with no reasoning modes.

Each operation now renames every config graph Sid in the commits it
reads, before filtering, folding and conflict keys, to the Sid its
target names the config graph by (the merge target, the rebase base,
the reverted branch). The merge takes the target state before reading
the source; the preview loads it up front and reuses it.

Tests: a_setting_both_branches_changed_follows_the_strategy (merge with
its preview, and rebase, under TakeSource and TakeBranch),
a_revert_across_two_config_graph_iris_restores_the_setting.
…erved

An index built before any ledger's config graph IRI named the config
graph can list one as an ordinary graph, its rows under that graph's id
(a branch made before its source's first index build, then indexed).
Loading it maps the IRI to the config graph, which reads nothing there,
so the config read as absent and queries and transactions ran without
it: configured policy, uniqueness and SHACL settings went unenforced,
as they had before the IRI was mapped. A later index build would rebuild
it, but nothing makes one happen on a ledger that takes no writes.

The registry now records such a root, and every config read fails on
it (ConfigUnavailable, naming `fluree reindex`), so its queries and
transactions are refused until a reindex rebuilds the index from the
commits. A reindex reads past the failure, as it already did for an
unreadable config.

Test: an_index_holding_a_config_graph_as_an_ordinary_graph_serves_nothing_until_rebuilt
(a root whose user graph is renamed to another ledger's config graph
IRI: refused, then served after a reindex).
@bplatz bplatz added bug Something isn't working as expected area:transact Staging, commit, import/bulk-import, novelty, retraction semantics labels Nov 3, 2026
@bplatz
bplatz requested a review from a team November 3, 2026 14:34
@bplatz
bplatz marked this pull request as draft November 3, 2026 14:58
An index built before any ledger's config graph IRI named the config graph
can hold one as an ordinary graph, its rows under that graph's id: a branch
created before its source's first index build, or a copy under another name,
then indexed. Loading it remapped the IRI to the config graph, which reads
nothing there, so such a ledger refused every query and transaction until a
reindex.

Such a ledger is now left as it was. Its registry keeps the IRI as the
ordinary graph the index holds, so the ledger reads, writes and merges as it
did before (its source's config does not apply), and an incremental index
build keeps that layout instead of failing over to a full rebuild. Merges,
rebases and reverts rename a config graph IRI only where the target's
registry reads it as the config graph.

`fluree reindex` rebuilds the index from the commits, which name the config
graph, so the source's config then applies. On such an index the reindex
reads the configured full-text properties from the commits too; read from the
old index they were absent, and one reindex restored the config but not
full-text search on those properties.

Docs: the upgrade note, and that a branch's config takes its parent's later
changes only through a merge.

Tests: an_index_holding_a_config_graph_as_an_ordinary_graph_keeps_it_until_reindexed
(a copy restored with its source's older index: served as before, kept by an
incremental build, one reindex restores the config and the full-text
property), a_merge_into_an_index_holding_a_config_graph_as_an_ordinary_graph_keeps_it.
A branch's history holds config under its source's config graph IRI before
the fork and its own after, and both name the config graph. Push kept one
graph Sid per graph id, so the flakes under the other IRI had no route and
the push failed. Staging now takes the routing by graph Sid, so several Sids
can name one graph.

Test: a_push_carrying_config_under_two_iris_applies_both (a branch's history
pushed to a ledger of another name, read as pushed and after a reload).
Background and CLI index builds skip the config read when no commit
registered the config graph, probing the commit envelopes for the ledger's
own config graph IRI only. A branch or a copy that inherited its source's
f:fullTextDefaults registered the source's, so the probe found nothing and
the build indexed none of the configured properties, though queries read the
config. The probe now matches any ledger's config graph IRI.

Test: a_branch_or_copy_indexes_its_sources_full_text_property (a branch and
a copy, through a first and a second index build).
The registry reads any ledger's config graph IRI as the ledger's own config
graph, which replayed commits and writes rely on. Dataset resolution asks
the registry first, so FROM <urn:fluree:other:main#config>, or a JSON-LD
from member whose graph is that IRI, read this ledger's config instead of
being refused as another ledger's graph.

In a dataset only the config graph IRI of a branch of this ledger reads as
its config graph (a branch reads its config by its source branch's IRI,
which it inherited); another ledger's names that ledger, as before.

Tests: sparql_reserved_graphs_stay_unreachable_when_not_named_in_full, with a
JSON-LD twin through query_from(); another_ledgers_config_urn_is_that_ledger.
A request carrying no policy of its own sees only what the source's config
policy allows, and its writes to the config or the policy rules are refused
(403): on a branch of an unindexed source, before and after the branch is
indexed, and on a copy under another name.

The branch tests that rebuild an index now evict the cached ledger first: a
published index does not replace the cached state, so the indexed step read
the unindexed one.
Three it_branch_shacl tests forked a branch from a never-indexed main and had
it write a value main's uniqueness or SHACL config forbids, which the branch
took only because it read no config (#2069). The branch now refuses it.

The general merge collides a value each branch took on its own; the
fast-forward commits the value without the check, as history from before it
would, after asserting the branch's own write is refused; the config-carry
case expects the refusal naming main's config graph.
@bplatz
bplatz marked this pull request as ready for review November 3, 2026 21:28

@aaj3f aaj3f 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 this is careful work, and at a design level I'm on board with reading any ledger's config graph IRI as the config graph: it's the only reader that works on history already written, and you found the places where one graph having several Sids would bite (push routing, the merge/rebase/revert folds, commit building, branch-op staging, datasets). A few headline notes:

(1) The new rule makes every urn:fluree:<x>#config this ledger's config graph, but two reserved-graph guards written before it still compare against the ledger's own IRI, so an alias now gets through both. The cross-ledger guard (cross_ledger/types.rs:707) says a model ledger's #config is never a legitimate governance target, and its test says another ledger's config IRI "can't actually resolve to model:main's #config"; it now does, and Claude reproduced M's config graph being applied as D's policy. The Graph Store route (graph_store.rs:117) refuses this ledger's own config IRI, but a POST naming another ledger's now writes this ledger's config. Details below, and I think both belong in this PR.

(2) I'm on board with config travelling with the history here, and with the merge-from-parent change that follows from it: a policy that stays behind fails open, and same-name copies already behave this way. Worth one sentence in the release notes that a push or pull from a differently named ledger now changes the receiver's config, as it already did between same-named ledgers.

(3) On the upgrade posture, I'm fine with not refusing or rebuilding anything unasked as the baseline, but I'd like the upgrade to at least say so: has_config_in_user_slot() is already computed on every load, so a warning there naming fluree reindex <ledger>, plus a flag on ledger-info so an operator can find the affected ledgers, would make the fail-open visible. That's my minimum here (inline on writing-config.md). I'd also like you to consider going one step further, the way your first commit (a5c397b88) had it: the next index build of such a ledger is a full rebuild rather than an incremental one that keeps the layout, so a ledger that takes writes heals itself. If you'd rather not, that's fine, I'd just like to hear the reason, since you went through all three postures in this PR and I don't know what moved you off that one.

This is at least the sixth time we've hit some version of "a system graph named for its ledger loses its identity when history crosses a ledger name":

158fb3317 (#1816, an adopted branch root, main read its config as empty); 8ca7f131c (#1838, ledger_info's suffix match read another ledger's #config as this one's); cfaef222e (#2009, merges carried a branch's config into an ordinary graph); #2069 and #2179; #2247 (a config write re-encodes the txn-meta Sid mid-push)

Naming system graphs by role in new commits (#2069's own "alternatively") would stop new aliases from being minted, but not in this PR: existing history needs exactly the recognizer you built, and the point fixes are right here. On merge order, it conflicts with main only in push routing (commit_transfer.rs), plus a compile break from #2232's graph_import.rs; the resolution needs to keep #2247's txn_meta_sid_after (comment below). And with your #2251 there's one interaction worth settling in whichever lands second: a graph_drops record naming a config IRI would, under this PR's alias rule, drop the config graph on replay (comment below).

Full review below:


🔄 Request changes.

This is a really careful fix for a fail-open that matters, @bplatz: Claude ran your new tests against the merge-base and they fail there the way #2069 describes (on a branch of an unindexed source, ex:ssn comes back as 111-11-1111 under a policy that hides it), and they pass at the head along with all of grp_graphsource, grp_ledger and grp_policy. The design is right for history already written. What I'd like before it merges: (1) the two reserved-graph guards that still compare by string (cross-ledger selector, Graph Store route) go through the recognizer or a post-lookup g_id check, since this PR is what lets an alias through them (details inline); (2) the branch resolved against main, keeping #2247's single post-delta txn-meta Sid in push routing and passing the ledger id to #2232's two from_index_root calls in graph_import.rs; (3) a load-time warning and a ledger-info flag for an upgraded ledger that still holds its source's config as an ordinary graph, with the full-rebuild auto-heal for you to weigh (inline on writing-config.md). The rest are optional notes: the dataset rule reading any branch name as this ledger's config graph, the merge holding the target's write lock across the source fold, a breaking-changes note for embedders, and a sharper policy test.

Adherence to repo commitments:

  • Patterns/abstractions: ⚠️ one recognizer (names_config_graph) behind the registry, indexer dictionary, import refusal and full-text probe, which is the right chokepoint; but the older reserved-graph guards (cross_ledger/types.rs:707, graph_store.rs:117, and the backstopped ones in stage.rs:842, admin.rs:338/:960, ledger_info.rs:766) don't use it, and #2232's bind_reserved_graphs duplicates the root relabel from_index_root now does.
  • Performance (speed first, memory second): ✔ the recognizer runs per graph IRI, not per flake, on the commit, replay and staging paths; the indexer's per-flake resolve_graph takes the old dictionary hit for ordinary graphs; no performance-degradation risk on query, transaction or indexing hot paths. ⚠️ the merge now holds the target's write lock across the source fold (writer stall, not speed).
  • Deployment targets: ✔ shared code with no new background task, cache or process-lifetime state (aliases lives in the per-snapshot registry, rebuilt on every load, so concurrent processes agree); evidence is in-process fluree-db-api tests plus CI's wasm32 jobs. The upgrade posture is where hosts differ: an embedder that loads ledgers per invocation gets no index cycle on a read-only ledger.
  • Testing: ✔ the new tests are in grp_graphsource/grp_ledger/grp_query, ran green in CI on 462531ee7 and on Claude's box, fail at the merge-base, and go red under three mutations of the crux hunks; ⚠️ nothing tests an alias against the reserved-graph guards, and the policy test's write half can't tell a config refusal from a refusal of every write.
  • Conventions: ⚠️ well-factored commits with full bodies, clippy/fmt green; no "Breaking changes" note for the public signature changes (StageOptions::with_graph_ids, first_t_where_graph_registered, SharedResolverState::from_index_root, graph_id_for_iri's answer), and the branch is CONFLICTING with main.

Verified at branch HEAD 462531ee7 on an EC2 box (Rust 1.97.0, nextest --all-features): grp_graphsource + grp_ledger + grp_policy 767/767 green (excluding Claude's scratch tests), the dataset/reserved-graph/reindex/cross-ledger subsets of grp_query/grp_transact/grp_index/grp_reasoning 134/134, fluree-db-core + fluree-db-indexer lib 1537/1537; five of the new tests fail at the merge-base; three crux mutations go red; the branch merged with main (conflict resolved as noted inline, plus the two graph_import.rs arguments) passes the config, branch, merge and graph-import tests (238/238).

Just be sure to get the two guards into this PR and resolve against main before it merges; the optional notes are worth a look while you're in there.

self.iri_to_id
.get(iri)
.copied()
.or_else(|| names_config_graph(iri).then_some(CONFIG_GRAPH_ID))

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.

(real locations fluree-db-api/src/cross_ledger/types.rs:703-713, cross_ledger/mod.rs:57, and fluree-db-server/src/routes/graph_store.rs:117) — blocking.

Blocking: the new rule makes every urn:fluree:<x>#config this ledger's config graph, but two reserved-graph guards written before it still compare against the ledger's own IRI by string, so an alias now gets through both.

graph_id_for_iri now answers CONFIG_GRAPH_ID for any ledger's config IRI. The cross-ledger guard reject_if_reserved_graph (cross_ledger/types.rs:707) refuses a selector only when it equals the model ledger's own #config/#txn-meta, and then resolve_selector_g_id (cross_ledger/mod.rs:57) hands the selector to graph_id_for_iri with no check on what comes back. Its doc says a model ledger's #config "is never a legitimate target of a cross-ledger governance reference", and its unit test (types.rs:772-776) asserts another ledger's config IRI "can't actually resolve to model:main's #config". With this PR it does, and the policy, shapes, schema, rules and constraints materializers all read M's config graph. The Graph Store route has the same shape: request_graph refuses ?graph=<this ledger's #config> as "a system graph; the Graph Store Protocol reads and writes user graphs" (graph_store.rs:117), but POST ?graph=urn:fluree:<other>:main#config passes and its graph insert now writes this ledger's config graph. (PUT and DELETE are caught by the g_id < FIRST_USER_GRAPH_ID backstops in stage.rs:849-855 and stage.rs:1660-1667.)

Claude reproduced both on a box, PR head 462531ee7 vs the merge-base 249418273. A model ledger M holds a deny-on-ex:User policy node in its own config graph; a data ledger D sets f:policySource → f:ledger <M>, f:graphSelector <urn:fluree:nowhere:main#config>. At the merge-base, db_with_policy(D) fails with "graph … is not present in model ledger"; at the head, it succeeds and a query for ex:User returns [], M's config graph applied as D's policy. (Naming M's own config IRI is refused on both, as before.) And stage(..).insert_graph_payload(GraphSel::Graph("urn:fluree:elsewhere:main#config"), <a LedgerConfig turning uniqueness on>), the call the Graph Store POST makes, is refused at the merge-base ("typed f:LedgerConfig in graph … where it has no effect") and at the head commits and turns uniqueness on.

Neither lets an identity do more than it could already (modify policy is per flake and graph-agnostic, and the config guard keys on g_id after routing), but both are fences this PR quietly disarms, and the cross-ledger one is a governance boundary by its own documentation. A post-lookup check covers every spelling, now and later; Claude confirmed this version makes the reproduction above refuse with ReservedGraphSelected and keeps every cross_ledger test in grp_graphsource/grp_policy/grp_reasoning green (67/67):

// cross_ledger/mod.rs, resolve_selector_g_id
match snapshot.graph_registry.graph_id_for_iri(graph_iri) {
    Some(TXN_META_GRAPH_ID | CONFIG_GRAPH_ID) => Err(CrossLedgerError::ReservedGraphSelected {
        graph_iri: graph_iri.to_string(),
    }),
    other => Ok(other),
}

and for the Graph Store route, *iri == txn_meta_graph_iri(&ledger_id) || names_config_graph(iri). The unit test at types.rs:772-776 should then flip to assert the refusal. Commenting here because cross_ledger/ and graph_store.rs are not in this diff; this line is what changed their answer.

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.

Addressed in 22c9765

let routing =
derive_graph_routing(&base_state, &decoded).map_err(PushError::into_api_error)?;
let mut reverse_graph = reverse_graph_lookup(&routing.graph_sids);
let mut reverse_graph = routing.graph_ids.clone();

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.

optional (merge note). This is the region that conflicts with main. main now resolves the txn-meta graph's Sid once, after the push's namespace deltas (txn_meta_sid_after, #2247's 70ad8991e), and seeds reverse_graph with it; this PR's side still carries the pre-push base_state.snapshot.encode_iri(&txn_meta_iri) seed and the accumulated_ns block that main moved into txn_meta_sid_after. The resolution Claude built and tested keeps let mut reverse_graph = routing.graph_ids.clone();, takes main's reverse_graph.entry(txn_meta_g.clone()).or_insert(TXN_META_GRAPH_ID);, keeps txn_meta_sid_after, and drops reverse_graph_lookup. Taking this side of the hunk wholesale would bring back exactly the screen/routing split #2247's review found. There is also a semantic conflict git merge-tree doesn't show: #2232 added two calls to SharedResolverState::from_index_root(&root) in fluree-db-api/src/graph_import.rs (:268, :764), which no longer compile against this PR's two-argument signature; Claude passed &root.ledger_id and &record.ledger_id. #2232's bind_reserved_graphs (graph_import.rs:730-738) also relabels root slots 0 and 1 for the importing ledger, which is now what from_index_root does too, so one of the two could go. With both resolutions, the merged tree passes it_config_graph::, it_branch::, it_branch_shacl:: and it_merge:: (227/227, #2247's two push/pull tests and #2246's branch-reindex test among them) and #2232's graph-import tests (11/11) on Claude's box.

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.

Addressed in 435841e. bind_reserved_graphs stays: it renames the system graphs in the root the import publishes, which from_index_root does not do (it relabels only the resolver's dictionaries).

Comment thread fluree-db-core/src/dataset_ref.rs Outdated
found == CONFIG_GRAPH_ID
&& self.names.reserved_iri(CONFIG_GRAPH_ID) != Some(iri)
&& crate::graph_registry::config_graph_ledger(iri)
.is_some_and(|ledger| ledger.name() != self.id.name())

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.

optional. This is more of a question than a suggestion. The body says "only a config graph IRI of a branch of this ledger reads as its config graph (a branch reading its config by its source branch's IRI, which it inherited)", but other_ledgers_config compares ledger names only, so any branch name of this ledger reads as its config graph, inherited or not, existing or not. Claude ran it on scratch-child-cfg:main with a branch dev whose own config sets f:uniqueEnabled false: FROM <urn:fluree:scratch-child-cfg:dev#config> on main returns main's true, and FROM <urn:fluree:scratch-child-cfg:nosuch#config> returns it too. At the merge-base both were a 400 ("names ledger 'scratch-child-cfg:dev', which is not in this ledger"). So a query naming another branch's config graph now silently answers with this one's. Narrowing it to the IRIs the registry actually holds for the slot (its own, plus iter_aliases()) would keep the documented case and refuse the rest; if the by-name rule is intended, it probably wants a sentence in the docs. Minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.

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.

Addressed in 7b0f4ad and 63990a2. A system graph IRI (config or txn-meta) now names only the branch it was written for: another branch's or ledger's is refused in a dataset (naming the endpoint's own) and in a write, and reads as no graph in an update's WHERE. Narrowing to the registry's IRIs would have broken once a build relabelled an inherited one; history still replays under any config IRI.

Comment thread fluree-db-api/src/merge.rs Outdated
// available, serializing with regular transactions on the target
// branch. Without a manager (embedded use, no shared cache), fall
// back to a fresh storage load — there's nothing to protect.
let (write_guard, target_state) = self

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.

optional (performance, writer stall). The target's write lock now comes before collect_commit_data, so every transaction on the target waits while the merge reads each of the source's commits (from object storage, on a remote backend). Before, the fold ran unlocked and the lock was taken after it. ConfigGraphs::for_target needs only the target's namespace table and graph registry, both append-only, so it can be built from the cached head (self.ledger(&target_id)) without the lock, with the lock taken where it was. I don't think the rename can go wrong that way: a config graph IRI the target registers in between is renamed again by one_config_graph_iri at commit. Not a hot path, but a long branch merged into a busy main would stall its writers for the whole fold. Minor and non-blocking; if you agree, I'd rather see it in this PR than tracked-and-forgotten.

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.

Addressed in a47dd19. Moving the lock back widened a race already on main: the general merge staged on the head it locked, not the one it diffed, so a commit landing in between was never checked for conflicts (an abort-strategy merge went through over a conflicting commit). The merge now refuses (409) when the head moved.


Any ledger's config graph IRI names this ledger's config graph. A copy restored under another name, or a branch, replays commits that wrote its source's config graph, and that config applies to it. A write naming another ledger's config graph IRI is stored under this ledger's own.

An index built by an earlier version can hold another ledger's config graph as an ordinary graph: a branch created before its source's first index build, or a copy under another name, then indexed. Such a ledger reads that graph as an ordinary graph, as it did before, so its source's config does not apply to it, and its incremental index builds keep it so. `fluree reindex <ledger>` rebuilds the index from its commits, after which the source's config applies, configured full-text properties included.

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.

blocking (my minimum on the upgrade posture).

This paragraph is where an already-indexed branch or copy stays failing open, and I'd like that to be visible, at a minimum.

An affected ledger (a branch created before its source's first index build, or a copy under another name, then indexed) keeps its source's config in an ordinary graph, so a policy that hides data on the source doesn't apply to it, and uniqueness stays off, until someone runs fluree reindex. I'm fine with not refusing or rebuilding anything unasked as the baseline. But nothing today tells an operator which ledgers those are, and GraphRegistry::has_config_in_user_slot() (graph_registry.rs:454) already knows on every load.

So my minimum here:

  • a tracing::warn! where the loader seeds the registry and has_config_in_user_slot() is true, once per load, naming fluree reindex <ledger>;
  • a boolean on ledger-info next to the graph listing, so fluree info can list the affected ledgers;
  • a sentence in this paragraph saying the warning exists.

Beyond that, I'd like you to consider the auto-heal your first commit had (a5c397b88: "A root that lists a config graph IRI as a user graph is rebuilt"): the next index build of such a ledger is a full rebuild instead of an incremental one that keeps the layout, so a ledger that takes writes heals without anyone having to find it. It won't help a ledger that takes no writes, which is why the warning is the floor. If you'd rather not add it, that's fine, I'd just like the reason in your reply.

It also matters for #2251: on the kept layout, a DROP can record that config IRI, and the reindex this paragraph prescribes would then drop the config graph (see the comment on graph_registry.rs:454).

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.

Not adding the warning or the auto-heal. The layout only comes from an index built before this change: a branch made before its source's first index build, or a copy under another name, then indexed (or a branch or copy that adopted such an index). No index built after this change has it. Those ledgers read exactly as they did before the upgrade, so nothing regresses, and fluree reindex <ledger> restores the source's config, as the upgrade paragraph says.

A load-time warning would sit in the load path permanently for a case that should be rare and only shrinks. A forced full rebuild on the next index build is impractical on a large ledger, which is where this case is least likely to apply. That's also what moved me off a5c397b88's posture.

The DROP interaction on this layout goes to #2251 (reply on graph_registry.rs:454).

/// a root built before any ledger's config graph IRI named the config
/// graph. That config is read only once the index is rebuilt from the
/// commits.
pub fn has_config_in_user_slot(&self) -> bool {

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.

optional (with #2251). This is more of a coordination note than a finding against this PR alone. #2251 names dropped graphs by IRI (Commit::graph_drops) and on every replay maps them back through graph_ids_of_drops → graph_id_for_iri, with no reserved-id filter (its fluree-db-ledger/src/lib.rs:206, :1134, and merge_graph_drops_by_iri across an index install). Its DROP refuses reserved graphs by g_id, so once this PR lands, no new drop can name a config IRI. But a record that already names one becomes a drop of slot 2 under this PR's alias rule. Two ways such a record gets written. If #2251 lands first, DROP ALL (or DROP NAMED, DROP GRAPH, MOVE) on a branch of a never-indexed source drops the source's …:main#config while it's still an ordinary graph. In either order, the same drops are allowed on an upgraded ledger whose index keeps that IRI in a user slot (the layout has_config_in_user_slot describes). The fluree reindex the upgrade note prescribes then replays the drop onto the config graph, and the inherited config is gone instead of restored. Claude read this across the two heads; it didn't run it. Whichever of the two lands second could have graph_ids_of_drops (and the rebuild's floor mapping) skip reserved ids, so a drop record never drops a system graph. I'd rather see that folded in with the merge than found later.

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.

Taking this in #2251: its replay of drop records will skip reserved graphs, in graph_ids_of_drops and the rebuild's floor mapping, which covers either merge order. Linked from the body as Follow-up: #2251.

/// Set the graph routing map for named-graph flakes
pub fn with_graph_sids(mut self, graph_sids: &'a HashMap<GraphId, Sid>) -> Self {
self.graph_sids = Some(graph_sids);
pub fn with_graph_ids(mut self, graph_ids: &'a HashMap<Sid, GraphId>) -> Self {

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.

optional. Not a big deal, but this is a public-surface change for embedders that the body doesn't list: StageOptions::{graph_sids, with_graph_sids} becomes {graph_ids, with_graph_ids} with the map inverted, fluree_db_core::first_t_where_graph_registered takes a predicate instead of an IRI (commit.rs:540-546), SharedResolverState::from_index_root takes the building ledger's id (resolver.rs:1171, the one #2232's graph import trips on), and GraphRegistry::graph_id_for_iri now answers CONFIG_GRAPH_ID for any ledger's config IRI. A short "Breaking changes" section phrased for an embedder (and the breaking-change label) would make the release notes say so. Minor; I'd rather see it in this PR than lost.

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.

Added a "Breaking changes" section to the PR body, and the breaking-change label.

Comment thread fluree-db-api/tests/it_config_graph.rs Outdated
.expect("the config's policy governs writes");
for (what, doc) in [
(
"open the config",

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.

optional (test). The write half of assert_policy_confines runs under a config policy with no modify grant at all, so its two 403s show that writes are refused, not that a config write in particular is. A rule granting f:modify on ex:name only would make the test say what its doc says: an ex:name write is accepted, the f:defaultAllow true write is refused. While there, the same check with "@graph" set to another ledger's config IRI would pin the alias path under policy. Minor; if you agree, fold it in now.

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.

Addressed in c7627f3

/// whichever ledger it names. A commit carries the IRI of the ledger it was
/// written in, so a branch replaying its source's history, or a copy under
/// another name, reads the source's config graph as its own.
pub fn names_config_graph(iri: &str) -> bool {

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.

praise. One recognizer behind graph_id_for_iri, apply_delta, provisional_ids, the indexer's graph dictionary, bulk import's refusal and the full-text probe is the right shape, and system_graph_ledger validating the ledger part with parse_persisted (so http://…#config, urn:fluree:#config and a/../b stay ordinary, :766-783) is what keeps it from being a suffix match like the one #1838 removed. Claude's mutation checks found each crux pinned: dropping the alias arm of apply_delta, routing one Sid per graph in push, and skipping the ConfigGraphs rename each turn the tests that claim them red.

…ss-ledgers

Push routing keeps this branch's per-Sid graph ids and seeds the txn-meta
graph with main's post-delta Sid (txn_meta_sid_after). Graph import's two
from_index_root calls pass the importing ledger's id.
The registry reads any ledger's config graph IRI as the config graph. Two
guards written before that compared a graph IRI against the ledger's own
config IRI, so another ledger's passed both:

- A cross-ledger f:graphSelector naming another ledger's config graph IRI
  read the model ledger's config graph as policy, shapes, schema, rules or
  constraints. The guard before any read on the model ledger now refuses
  any ledger's config graph IRI, and selector resolution refuses an IRI the
  model's registry reads as its txn-meta or config graph, in any spelling.
  The second check also covers the virtual-source identity lookup, which
  never ran the first.
- A Graph Store POST naming another ledger's config graph IRI wrote this
  ledger's config. The route refuses any ledger's config graph IRI, as it
  refused the ledger's own.

Tests: a_config_graph_selector_is_refused_in_any_ledgers_name,
a_selector_the_registry_reads_as_a_system_graph_is_refused, and
request_errors with GET, PUT and POST of the ledger's own and another
ledger's config graph IRI.
…efuses

A general merge took the target's write lock before folding the source's
commits, so every transaction on the target waited while the merge read the
source's history. The fold needs only the target's names for the config
graph, from its namespace table and graph registry, which only grow. They
are now read from the cached head without the lock, which is taken after the
fold, where it was before config graphs were read across ledgers.

The merge's diff and conflicts are the target's as of the head it read
first, but it staged on the head it locked. A commit that landed between
the two was in neither, so its changes were not checked against the
source's: an abort-strategy merge went through over a conflicting commit,
with no conflict counted. Such a merge is now refused (409), as a
fast-forward that loses the race is, naming the head it moved to.

Test: general_merge_loses_race_to_a_target_commit_during_its_preparation (a
commit on the target after the merge reads its head, through a nameservice
that pauses after that lookup).
The write half of a_sources_policy_governs_its_branch_and_copy ran under a
policy with no modify grant, so its refusals showed only that every write
was refused. The source's policy now lets a request modify ex:name: a name
is written, while the config (named by the keyword, and by another ledger's
config graph IRI) and the policy rules are still refused. The writes are
staged, not committed, so each check sees the ledger as it was.
@bplatz bplatz added the breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section label Nov 5, 2026
The graph registry reads any ledger's config graph IRI as the ledger's own
config graph, which replayed history needs: a branch, or a copy under
another name, replays commits that wrote its source's config graph. Queries
and writes read it the same way, so naming another branch's config graph
IRI silently read or wrote the branch's own: on main, FROM
<urn:fluree:mydb:feature#config> answered with main's config, an update's
WHERE over it read main's, and a write to it, also wrapped as
<mydb:main#urn:fluree:mydb:feature#config>, changed main's.

A query or write naming the config graph IRI of another ledger, or of
another branch, now names that one. Every place a graph is named, a dataset
member and every graph position, judges the IRI as written (the <g> of
L#<g>) before the registry canonicalizes it, so a keyword that reaches the
config slot through a source's inherited IRI still reads and writes it:
- A dataset (SPARQL FROM / FROM NAMED, a JSON-LD from member) refuses it
  (400), naming the endpoint's own config graph IRI; a connection query
  reads the branch the IRI names.
- An update's WHERE reads it as no graph.
- A write is refused (400), naming the branch's own config graph IRI.

A branch no longer reads its config by its source branch's IRI, which a
branch of an indexed ledger holds at its config slot until the next build
relabels it; it reads it as `config` or by its own IRI.

Tests: a_branch_reads_config_by_its_own_urn_and_urn_named_graphs_stay_graphs
(main's URN refused on the branch's view, FROM NAMED and query_from(), read
by a connection query; a branch of an unindexed and of an indexed main),
an_updates_where_reads_another_branchs_config_graph_iri_as_no_graph,
a_write_to_another_ledgers_config_graph_iri_is_refused (TriG, JSON-LD,
SPARQL, and wrapped as L#<g>).
A branch of an indexed ledger holds its source's system graph IRIs at the
reserved slots until its next index build relabels them. The previous
commit made a config graph IRI name only the ledger it names; the txn-meta
graph IRI still resolved through the registry. On such a branch,
FROM <urn:fluree:mydb:main#txn-meta> read the branch's own txn-meta graph,
as did an update's WHERE over it. On any branch, a write naming another
ledger's or branch's txn-meta graph IRI, which no registry holds, created an
ordinary graph under that name, which a merge then refused to carry.

The rule now covers both system graphs: the system graph IRI of another
ledger, or of another branch, is refused in a dataset (400, naming the
endpoint's own), reads as no graph in an update's WHERE, and is refused as
a write or a bulk-import block (400). Writes name no txn-meta graph, so the
refusal says that a transaction adds metadata to its own commit in a
`#txn-meta` block. A branch's own system graph IRIs, its address with a
keyword, still reach its slots, whatever IRI they hold.

Tests: a_write_to_another_ledgers_system_graph_iri_is_refused (txn-meta IRIs,
as written and as L#<g>), a_branch_cannot_write_under_its_sources_system_graph_iris
(replaces the merge test whose writes can no longer be authored),
an_updates_where_reads_the_sources_txn_meta_graph_iri_as_no_graph, and the
txn-meta slot and URN in a_branch_reads_config_by_its_own_urn_and_urn_named_graphs_stay_graphs.
@bplatz
bplatz merged commit 9fdf0ce into main Nov 6, 2026
19 checks passed
@bplatz
bplatz deleted the fix/config-graph-across-ledgers branch November 6, 2026 03:55
bplatz added a commit that referenced this pull request Nov 6, 2026
Both sides extended the graph registry: the drop records here, and main's
config graph aliases (#2249). has_unregistered keeps both rules: a dropped
graph counts as unregistered, and any ledger's config graph IRI is the
config graph, registered. Snapshot metadata carries both graph_drops and
main's index_root_id; apply_index decodes the root through main's
from_root, mutably, to carry the drops.

Main's GraphPosition::OtherLedgersSystemGraph reads no graph, so the
search-index drop probe (latest_drop_read) counts no drop for it.

Main's add_copy_and_move_are_refused_regardless_of_destination_contents
expected MOVE under policy to be refused by the modify check; here MOVE
drops its source and is refused for a policed identity before either graph
is read, a policy violation (403) of its own.
bplatz added a commit that referenced this pull request Nov 7, 2026
Brings #2251 (graph DROP) and #2249 (config graph across ledgers) into next.

Resolutions:
- Root format: `graph_drops` takes main's extended bit 3 in every root
  version; next's term dictionary moves to bit 7. The section's graph ids
  follow the root's width (16-bit v2, 32-bit v5), in `IndexRoot::decode`
  and the core metadata decoder alike. It comes after the term dictionary.
- Commit envelope: `graph_drops` beside next's 32-bit `graph_delta`; the
  drop-count cap covers next's graph id space.
- Pooled graphs: `BinaryIndexStore::without_graphs` takes a dropped graph
  out of the pool's membership as well as `graph_indexes`, and
  `has_graph_index` counts pool members, so a drop after the index hides
  a pooled graph's rows too. An incremental build whose window drops a
  pooled graph returns `NeedsRebuild`: its rows share the pooled tree, so
  the purge cannot take them out. New test in it_import_pooled_graphs.
- Annotations: main's arena handling of dropped edges (`forget_graphs`,
  `arena_dropped_graphs`, `edge_graphs_dropped_since_index`, the arena
  floors in `Fir6Inputs`) is dropped. On next an annotation and its
  `rdf:reifies` link live in the edge's graph, so the drop takes them,
  and link synthesis sees only ops the resolver keeps. The two
  arena-specific graph-drop tests check the same behaviour through links.
- Novelty: `drop_graphs` and `forget_graph` work on next's graph slots and
  per-graph OrdMaps.
- Indexer: the lifecycle and purge helpers take 32-bit graph ids;
  `graph_dict_id_or_insert*` keeps next's u32 overflow check.
- Transact/push: `StageOptions` takes main's `graph_ids` (Sid → GraphId);
  `replaying_commit` stays deleted with the bundle reifier rule.
- Api: store masking (`store_without_dropped_graphs`) runs before next's
  `install_link_base`; `take_snapshot_metadata` carries the drops. Export
  and hydration keep next's link readers. Graph import refills a dropped
  graph with 32-bit ids.
- Tests: main's new tests take next's async `genesis_ledger`, storage
  namespaces, `without_storage_lock` for a peer beside a live writer, and
  the ledger config provider.
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 breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section bug Something isn't working as expected

Projects

None yet

2 participants