Skip to content

Rebase leaves the branch's own index in place when the source's is older or absent, so the rebased branch reads pre-rebase data #1985

Open

Description

@bplatz

Summary

After rebase_branch, the branch's commit head moves to the new chain, but its index head can stay on the index built from its pre-rebase chain. The next load reads that stale index for everything at or below its t, and replays only new-chain commits above it. The source's commits at or below that t go missing, and the branch's pre-rebase state shows through.

Nothing fails: the rebase reports success and later reads are silently wrong.

Cause

prepare_rebase replaces the branch's index through copy_source_index (fluree-db-api/src/rebase.rs:844). It copies the source's index artifacts, then calls publish_index(branch, source.index_t, …). Two cases leave the branch's own index in place:

  • The source has no index (index_head_id is None): nothing is published.
  • The source's index_t is at or below the branch's: publish_index is monotonic on every nameservice backend (memory, file, storage) and silently ignores the older publish.

The second case is probably the common one. A branch that sees more activity than its source is indexed further ahead.

The in-memory state the rebase produces is correct: it is the source's state plus the replays. The stale index only takes effect on the next load, which is when the wrong data appears.

Reproduction

  1. mydb:main, t=1: insert Alice.
  2. create_branch("mydb", "dev", None, None).
  3. mydb:dev, t=2: insert Dave.
  4. Index dev, giving index_t = 2. Use the background indexer, or rebuild_index_from_commits over branched_content_store (see reindex fails on any branch: it reads commits through the flat store and misses the ones before the fork #1984 for why reindex can't do it).
  5. mydb:main, t=2: insert Carol. main stays unindexed.
  6. rebase_branch("mydb", "dev", TakeBoth). This reports replayed = 1; dev now has commit_t = 3 and index_t = 2.

Result:

  • Querying mydb:dev for names returns Alice and Dave; Carol is missing. This holds on a fresh load and after disconnect_ledger.
  • create_branch("mydb", "x", Some("dev"), Some(TimeSpec::AtT(2))) resolves t=2 to the discarded pre-rebase commit, then fails with a 404 saying the commit is not on the line of commits.

Controls: the same scenario returns Alice, Carol and Dave, with t:1–t:3 all on the new chain, when:

  • dev is not indexed before the rebase, or
  • dev is reindexed after it.

Suggested fix

Make the rebase set the branch's index head outright, instead of publishing through the monotonic path:

  • to the source's copied index when the source has one;
  • otherwise to no index, so the branch replays from genesis until the indexer catches up.

reset_head with an NsRecordSnapshot already restores both heads for the rebase's rollback path.

Other paths:

  • Raft: the apply path (AdvanceRef through consensus) needs the same change.
  • Fast-forward: this path uses the same copy_source_index. It looks safe, because a branch with no commits of its own can only have indexed the source's chain, but a test should pin that.

Tests: a source with no index, and a source indexed below the branch. Each should assert the branch's data after a reload, not from the cache the rebase leaves behind.

Found while checking a claim in #1969.

Activity

  1. added
    bug
    P1
    area:transact
    on Sep 29, 2026
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

    P1area:transactbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions