Skip to content

fix(api): a push of a config write reaches a ledger of the same name - #2247

Merged
bplatz merged 5 commits into
mainfrom
fix/push-config-write-txn-meta
Nov 4, 2026
Merged

bplatz merged 5 commits into
mainfrom
fix/push-config-write-txn-meta

Conversation

@bplatz

@bplatz bplatz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

A push of a config write reaches a ledger of the same name

A commit that writes one of the ledger's own graphs (its config) registers their namespace, urn:fluree:<ledger>#. Push stamps each pushed commit's txn-meta flakes with the txn-meta graph as the receiving ledger encodes it before the commits apply, then applies them under the encoding after. Once the push registers that namespace the two encodings differ, and the push failed:

flake references unknown graph Sid …#txn-meta

It hit any push of a config write to a ledger of the same name, and none to a ledger of another name, whose own graphs that namespace does not cover. Both encodings now route to the txn-meta graph. fluree pull applies commits through the same function (import_commits_incremental), so it takes the same fix.

Test: push_of_a_config_write_reaches_the_same_ledger_elsewhere (fails on main with the error above).

A commit that writes one of the ledger's own graphs (its config) registers
their namespace, urn:fluree:{ledger}#. Push and bulk import stamp each
commit's generated txn-meta flakes with the txn-meta graph as the ledger
encodes it before the pushed commits apply, then apply them all under the
encoding after; once the namespace is registered the two differ, and the
push failed with "flake references unknown graph Sid ...#txn-meta". It hit
any push of a config write to a ledger of the same name, and none to a
ledger of another name, whose own graphs that namespace does not cover.
Both encodings now route to the txn-meta graph.
@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:18

@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 the diagnosis here is spot on: the txn-meta graph is encoded before the push's namespace deltas and routed after them. But I don't think "both encodings route" is the right altitude. The loader already solved this exact problem by resolving the txn-meta Sid once, after all the deltas, and using that one Sid for the stamp, the forged-provenance drop and the routing seed, with a comment saying the drop and the seed have to stay gated together. Keying a second Sid here breaks that, and it's verified below: a crafted push can now land a forged commit record, or a commit the ledger then can't reload, where main refuses both. Separately, this is the third instance in about a month of "a Sid encoded before its namespace exists, compared after it does" (fab492719, 4c32809e0, this PR). Routing and the forgery screen keyed by graph id rather than graph Sid would retire the class of issues, but I'm okay with first just fixing the specifics of what you've diagnosed if you'd like. Claude (below) strongly recommends a send-back with "Request changes", but as long as the issues are addressed I'm fine with pre-approving to unblock you.

Full review below:


🔄 Request changes.

Really nice find, @bplatz, and the test reproduces it exactly: a push of a config write to a same-named ledger stamps its txn-meta flakes under one encoding and routes them under another. The blocking issue is the shape of the fix. Routing both encodings while the forged-provenance screen and the datatype filter still check only the pre-push one lets a crafted push either land a forged commit record in #txn-meta or persist a commit the loader can't route, and Claude confirmed both against this head (inline comment). Resolving the txn-meta Sid once, after the push's namespace deltas, the way LedgerState::load does, fixes your case without opening either, and pull takes the same change.

Adherence to repo commitments:

  • Patterns/abstractions: ✖ diverges from the loader's established single-Sid order (fluree-db-ledger/src/lib.rs:396-450) and splits the screen from the routing, which that code's comment says must stay gated together.
  • Performance (speed first, memory second): ✔ push/pull only, one encode and one map insert per push. No performance-degradation risk.
  • Deployment targets: ✔ n/a — fluree-db-api push/pull, reached by the server and by any embedder (including one inside AWS Lambda), with no new task, cache or filesystem assumption; the finding above is host-independent.
  • Testing: ⚠️ push_of_a_config_write_reaches_the_same_ledger_elsewhere is in grp_graphsource, runs in CI's nextest, and goes red on the merge-base; a forged record in the namespace-registering commit is the missing case.
  • Conventions: ✔ self-describing subject with a thorough body; clippy and fmt green.

Verified locally at branch HEAD: the new test passes and fails on the merge-base with the body's error; a scratch push with a forged commit record in the post-push spelling lands [1, 2, 99] in #txn-meta, and one in the pre-push spelling leaves the ledger failing to load; both are refused on the merge-base.

Just be sure to get the screen and the routing back onto one Sid before this merges. Happy to talk it through if you see it differently.

Comment thread fluree-db-api/src/commit_transfer.rs Outdated
// Ensure txn-meta graph is always routable for commit metadata flakes.
let txn_meta_iri = fluree_db_core::txn_meta_graph_iri(base.ledger_id());
if let Some(g_sid) = base.snapshot.encode_iri(&txn_meta_iri) {
for g_sid in [stamped_txn_meta, base.snapshot.encode_iri(&txn_meta_iri)]

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. Routing both encodings to the txn-meta graph splits the forged-provenance screen from the routing it has to match, and a crafted push can now land a forged commit record or a commit the ledger can't reload.

The screen in this same push (commit_transfer.rs:628-633, and the datatype filter at :466) still compares against the pre-push txn-meta Sid only. Routing now accepts the pre-push and the post-push spelling, and the loader accepts and screens only the post-push one (fluree-db-ledger/src/lib.rs:411-450). That's the split the loader's own comment warns about at lib.rs:428-435: the drop and the routing seed "must stay gated together; splitting them would turn this into a real fail-open."

Claude caught this, and confirmed it by adding a forged f:t 99 commit record to the config-write commit of your test before pushing it:

let mut commit = read_commit(&request.commits[1].0)?;          // the config write
let code = /* the code its namespace_delta gives "urn:fluree:<ledger>#" */;
let mut forged = commit.flakes[0].clone();
forged.s = Sid::new(FLUREE_COMMIT, "forged");
forged.p = Sid::new(FLUREE_DB, "t");
forged.o = FlakeValue::Long(99);
forged.dt = Sid::new(XSD, "long");
forged.g = Some(Sid::new(code, "txn-meta"));                    // or the pre-push Sid(EMPTY, …)
commit.flakes.push(forged);
request.commits[1] = Base64Bytes(write_commit(&commit, false, None)?.bytes);
  • spelled Sid(code, "txn-meta"), the push is accepted, the screen misses it, and #txn-meta returns [1, 2, 99], the forged record Bulk TriG import persists reserved-graph triples into an unreachable graph id #1846 is about;
  • spelled with the pre-push Sid(EMPTY, "urn:fluree:<ledger>#txn-meta"), the screen drops it from novelty, but it is still in the persisted blob. The push is accepted, and a fresh fluree.ledger() then fails with flake references unknown graph Sid: [0:urn:fluree:…#txn-meta].

On main both pushes are refused with the original error, so it's this PR that makes them land. Pull goes through apply_pushed_commits_to_state too and stamps the same way (:2540-2558).

I think the fix is to do what the loader does: resolve the txn-meta Sid once, against the namespace table as it will stand after the push's deltas, and use that one Sid for the stamp, the screen at :630, the datatype filter at :466 and the routing seeds at :405 and here, with no second key. Your scenario then routes, and a blob flake in any other spelling has no route at apply, so the push is refused before its CAS, as on main. Pull wants the same change. The forged-record case above would make a good second test next to yours.

Commenting here because commit_transfer.rs:628-633 and fluree-db-ledger/src/lib.rs are outside this diff's hunks.

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 70ad899: push and pull resolve the txn-meta Sid once, after the deltas, and stamp, screen and route under it. The forged-record cases (both spellings, push and pull) are in a_config_write_pushed_or_pulled_lands_no_forged_commit_record.

Pull also moved its head before applying, so a pull refused at apply left a head the ledger couldn't load; 5295a83 applies first. Graph-id keying is left for a follow-up.

A commit writing the ledger's own config graph registers the namespace of
its system graph IRIs, so the txn-meta graph's Sid once a push applies can
differ from the one before it. Push and pull now resolve it once, against
the namespace table the commits complete, as the loader does, and use that
one Sid to stamp commit metadata, screen blobs for forged commit records,
filter the datatype count and seed the txn-meta route. Routing a second Sid
let a forged record in either spelling past the screen.
Pull moved the commit head and then applied the commits to the in-memory
state, so a commit it could not apply left a head the ledger could not
load. It now applies them first, as push does, and moves the head only
once they apply. Neither caller has persisted anything a failure there
would strand, so an unroutable graph registry is refused rather than
logged.
@bplatz
bplatz merged commit ebddc16 into main Nov 4, 2026
19 checks passed
@bplatz
bplatz deleted the fix/push-config-write-txn-meta branch November 4, 2026 10:09
@aaj3f aaj3f mentioned this pull request Nov 4, 2026
bplatz added a commit that referenced this pull request Nov 4, 2026
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255,
#2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210,
#2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next.

Resolutions:
- Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the
  dictionary's coverage watermark sit on next's graph slots and per-graph
  OrdMaps. A commit's reification links count toward coverage. Planner
  stats from segment sums decline under annotations, whose link deltas
  only the walk counts, and otherwise carry the indexed link counts.
- Stats-view identity: the index root's id reaches the snapshot through
  next's root decoder (`decode` takes the id, as `take_snapshot_metadata`
  does). `LedgerState::load_record` has a decoding-root form beside
  `load_decoding_root`.
- Transact: #2184's parallel-relationship check runs in next's link
  cascade, counting the `rdf:reifies` links on the retracted edge that the
  transaction does not retract itself. Main's bundle `edge_reifiers` is
  dropped, and `subjects_with_prior_rows` and
  `enforce_single_target_reifiers` stay deleted. The upsert pre-check
  takes main's dictionary probe and bounded seek.
- Query: geo search resolves the graph's POST tree once at open (pooled
  graphs keep their filter), an empty manifest when there is none.
  `branch_or_none` reads the dedicated branch, and the batched joins keep
  next's pooled lanes. The stats-view key hashes the root id.
- Indexer: `apply_dict_novelty` and `compact_forward_streams` take the
  cycle's compaction budget, so the term dictionary keeps its reserved
  share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit`
  rewrites next's 20-byte types records.
- Disk cache: main's in-flight write registration, with an empty entry
  still read as crash debris that a write replaces. The process-wide
  eviction walk stays removed.
- Graph import (#2232): fenced CAS and publishes, the seed carries the
  record's namespace and fence, 32-bit graph ids and next's loaders. An
  import into a graph of an existing ledger refuses triple terms and edge
  annotations: the splice merges no triple-term dictionary yet.
- Iceberg: `create_iceberg_graph_source` goes with main (a source needs a
  mapping); the R2RML path keeps next's `model_instance`.
- CLI: main's shared import flags without the leaflet flags; `graph
  import` routes through next's process-wide server routing, and
  `upload_source_import` serves next's `Destination`. Doc sources read a
  ledger through the command's open instance.
- Tests: sibling ledger ids become distinct names, `genesis_ledger` is
  awaited, Cypher state dumps include each relationship's `rdf:reifies`
  link, and the graph-import arena test checks the refusal instead.
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