Skip to content

cli: --at t:N is parsed as a commit-id prefix, so time travel by transaction number fails locally and on remotes #1805

Closed

Description

@bplatz

Summary

fluree query --at t:N … fails everywhere — locally and against a remote — because parse_time_spec treats t:N as a commit-id prefix. --at N (a bare integer) works. The t:N spelling is the one the rest of the CLI uses (fluree show t:2, ledger addresses like ledger@t:2) and the one the --at help text implies ("transaction number, commit hash, or ISO-8601 timestamp"), so this is the form users reach for first.

Observed with fluree 4.2.0 (fluree-db-cli).

Reproduction

Local ledger:

$ fluree query --direct --at t:2 mydb 'SELECT (COUNT(?s) AS ?n) WHERE { ?s ?p ?o }'
error: Internal error: Query error: Commit prefix must be at least 6 characters, got 3

Remote (a Solo standalone router), SPARQL and JSON-LD:

$ fluree query --remote demo --at t:2 compliance-content 'PREFIX cm: <…> SELECT ?v WHERE { ?r a cm:Release ; cm:version ?v }'
error: bad request: Query error: Internal error: Query error: Invalid graph source: Commit prefix must be at least 6 characters

$ fluree query --remote demo --at t:2 compliance-content '{"@context":{…},"select":["?v"],"where":{"@type":"cm:Release","cm:version":"?v"}}'
error: bad request: Query error: Internal error: Query error: Invalid graph source: Commit prefix must be at least 6 characters

Working forms, same ledger, same server:

$ fluree query --remote demo --at 2 compliance-content '<same SPARQL>'        # bare integer: works
$ fluree query --remote demo compliance-content \
    'PREFIX cm: <…> SELECT ?v FROM <compliance-content@t:2> WHERE { … }'     # explicit FROM: works

What the CLI actually sends

Captured with a throwaway remote pointed at a local echo server:

POST /v1/fluree/query/compliance-content:main?default-context=true   [application/sparql-query]
PREFIX cm: <…> SELECT ?v FROM <compliance-content:main@commit:t:2> WHERE { … }

POST /v1/fluree/query/compliance-content:main?default-context=true   [application/json]
{"@context":{…},"select":["?v"],"where":{…},"from":"compliance-content:main@commit:t:2"}

The suffix is @commit:t:2, not @t:2.

Root cause

fluree-db-cli/src/commands/query.rs, parse_time_spec (line 162 at the version checked):

pub fn parse_time_spec(at: &str) -> TimeSpec {
    if let Ok(t) = at.parse::<i64>() { TimeSpec::at_t(t) }
    else if at.contains('-') && at.contains(':') { TimeSpec::at_time(at.to_string()) }   // ISO-8601
    else { TimeSpec::at_commit(at.to_string()) }                                        // everything else
}

t:2 is not an integer and has no -, so it becomes TimeSpec::AtCommit("t:2"); time_spec_to_suffix then renders @commit:t:2. Locally the engine rejects the 3-character "commit prefix"; remotely inject_remote_time_travel_sparql / the JSON-LD from injection ship the same suffix and the server rejects it the same way. The server side is not at fault: the router accepts ledger@t:N, ledger:main@t:N, FROM <ledger@t:N> and JSON-LD "from": "ledger@t:N" (all verified directly).

Proposed fix

  • Teach parse_time_spec the explicit spellings: t:<N> → AtT, t:latest → Latest, iso:<ts> → AtTime, commit:<prefix> → AtCommit, keeping the bare-integer and ISO heuristics for backwards compatibility. This matches the commit-identifier grammar fluree show already accepts (t:<N>, hex prefix, full CID).
  • Unit tests for parse_time_spec covering 2, t:2, t:latest, an ISO timestamp, a hex prefix, and commit:<prefix>; an integration test that --at t:N on a local ledger returns the same rows as --at N.
  • Update the --at help text to list the accepted spellings.

Also noticed (secondary, possibly a separate issue)

JSON-LD SELECT results rendered with --format table come out as empty columns (++ / || rows), while --format json shows the rows correctly. Seen with --remote; not checked locally.

Activity

  1. added
    bug
    area:cli
    on Sep 8, 2026
  2. added a commit that references this issue on Sep 29, 2026
    2c6b8ea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions