Repository navigation
Description
fluree history builds the ledger address for its from/to fields by pasting :main onto whatever alias it was handed. If that alias already carries a branch — and carrying a branch is the only way to name one — the result is a three-segment string that the nameservice rejects, so the command fails outright on every branch except main.
$ fluree branch create dev
Created branch 'dev' from 'main' at t=1
Ledger ID: hdb:dev
$ fluree history http://example.org/a -l hdb:dev
error: Ledger error: Nameservice error: Invalid ID format: Invalid ledger ID format 'hdb:dev:main': expected 'name' or 'name:branch'
$ fluree use hdb:dev
Now using ledger 'hdb:dev'
$ fluree history http://example.org/a
error: Ledger error: Nameservice error: Invalid ID format: Invalid ledger ID format 'hdb:dev:main': expected 'name' or 'name:branch'
Both routes that can reach a non-main branch fail identically, and there is no third route — fluree branch has no checkout/switch subcommand, so fluree use <name>:<branch> is the mechanism for selecting a branch, and it is the one that breaks.
Mechanism
format_time_spec (fluree-db-cli/src/commands/history.rs:169-180) has the :main written into all four of its arms:
fn format_time_spec(alias: &str, spec: &str) -> String {
if spec == "latest" {
format!("{alias}:main@t:latest")
} else if let Ok(_t) = spec.parse::<i64>() {
format!("{alias}:main@t:{spec}")
// ... @iso: and @commit: arms, same shapealias reaches it from context::resolve_ledger (history.rs:21 → context.rs:548), which returns the -l value verbatim when one is given and otherwise the active ledger straight out of config. Neither is normalized, and both can carry a branch. So hdb:dev becomes hdb:dev:main@t:1, split_ledger_id's splitn(2, ':') reads that as branch dev:main, and the nameservice refuses it.
The part I find most annoying is that the correct value is already computed in the same function, just twelve lines too late — history.rs:52 does let ledger_id = context::to_ledger_id(&alias), which normalizes properly, but build_history_query was already called at :40 and the from/to fields were built from the raw alias.
It's specific to history
Same ledger, same branch, same session — query is fine:
$ fluree query -l hdb:dev --sparql -e 'SELECT ?v WHERE { ?s <http://example.org/v> ?v }'
| on-dev-only |
| on-main |
And branch + time travel together work, which is what makes me fairly confident the fix is confined to this one function rather than something deeper:
$ fluree query -l hdb:dev --at t:1 => on-main
$ fluree query -l hdb:dev --at t:2 => on-dev-only, on-main
So the engine resolves hdb:dev@t:N perfectly well. Only history's construction of that string is wrong.
Fix
The direction seems straightforward — build the suffix onto the normalized ledger id rather than onto {alias}:main, i.e. hoist the to_ledger_id(&alias) that already exists at :52 above the build_history_query call at :40 and thread that through instead of alias. to_ledger_id already applies the default branch when the alias doesn't name one, so the main case keeps working without a special case.
I may be missing a reason it was written this way. If history is deliberately main-only for some reason I've forgotten, then the fix is a clear error rather than a silent name:branch:main, and the --from/--to help should say so — but I can't see what that reason would be given query handles it.
Worth a regression test either way: history on a branch-qualified ledger, asserting it returns the rows written on that branch rather than main's. There is currently no CLI test covering history on a non-main branch at all, which is why this survived.
Note on the near-miss
PR #1871 (--at time-spec parsing) rewrites format_time_spec — it replaces the hand-rolled spec parsing on one side and the suffix rendering on the other, so the function now reads format!("{alias}:main{suffix}"). The :main sits exactly between the two halves that PR touches and it deliberately left it alone as out of scope. Flagging that only so nobody reads the blame on that line as the origin; this predates it.
Environment
main @ 3d89e8f71, debug build with PR #1871 applied (the defect reproduces identically without it), macOS.
Activity
Build history's time range from the normalized ledger id
aaj3f commentedon Sep 16, 2026
Correcting the scope in my own title before this closes, because as written it tells the wrong people they're safe.
-l mydb:mainwas broken too, not only non-mainbranches. The explicit spelling of the default branch is equally branch-qualified, so it becamemydb:main:mainand was rejected identically — only the bare-l mydbform ever worked. So "unusable on any branch butmain" reads as "you're fine if you're onmain", and someone who spells that out explicitly is not.That came out of writing the regression test rather than from re-reading the code, which is the bit I'd take away from it:
mydb:mainlooked like the safe case right up until it was the control that failed.PR #1871 fixes all four spellings —
mydb,mydb:main,mydb:dev, andfluree use mydb:dev— and its body carries the full scope.Not renaming it myself since it's a small edit and one I've already made once today, but if anyone wants to, something like: