Skip to content

fix: a rebased branch reads its new line, and builds never extend an index of a replaced line - #2296

Merged
bplatz merged 13 commits into
mainfrom
fix/rebase-branch-index
Nov 13, 2026
Merged

bplatz merged 13 commits into
mainfrom
fix/rebase-branch-index

Conversation

@bplatz

@bplatz bplatz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2381

A rebase that replays a branch's commits could leave the branch serving an index of the line it replaced. A fresh load (a restart, another instance, a query peer) then read that index with the new line's later commits on top, so the source commits the replay was based on were missing from every read until a full rebuild. Ways in:

  • The rebase kept the branch's own index. It copied the source's index onto the branch only where it was newer than the branch's, and copied nothing when the source had none.
  • A build raced the rebase. An index of the branch built from its record just before the rebase could be published just after it. The next incremental build extended it over the new line, mixing the two. When the rebase left the head at the build's t, no next build came at all.
  • The commit-CID index fed the build the replaced line. The incremental build's fast path trusts the nameservice's commit-CID entries when they cover every t up to the head. Entries the replaced line left below the new head still cover the range.
  • A warm cache caught up across the rebase. Another instance holding the branch applied the new line's commits onto the replaced line, checking only their count.
  • A rebase that replayed nothing (Skip on every conflict, or every replay empty, as TakeSource can leave it) got halfway to making the branch the source. It published the source's index on the branch and installed the source's state in the cache, but left the branch's head where it was: a fresh load mixed the two, and the branch's next write failed with a commit conflict.

Found while chasing an intermittent it_garbage failure on #2280, where the garbage collector trusts this index. There it recorded a live commit as garbage, so it is fixed there too.

Changes

  • Rebase: a non-fast-forward rebase writes the new head and the branch's index, reset to the source's or to none, in one nameservice write, so no reader sees the new head over the replaced line's index. A fast-forward keeps the branch's own index, which is on the new line. A rebase that replays nothing makes the branch the source: the local apply moves the branch's head and index to the source's in one reset. The Raft path, whose heads only advance, completes the entry with the branch unchanged and installs nothing.
  • Nameservice: reset_head could not lower the index on the file and object-storage nameservices, because their separate index file wins at an equal or higher t. It now rewrites that file too, as its contract ("bypasses monotonic guards") says. Memory and DynamoDB already did.
  • Indexer, incremental build: checks that its base index holds the commit the walk starts after (the head's line at the base's t), and otherwise falls back to a full rebuild. Every incremental build pays one dictionary lookup. On the commit-CID fast path it also checks that each entry's first parent is the entry before it, and otherwise walks the line itself: one envelope decode per walked commit, of bytes already fetched.
  • Indexer, publish: before publishing, the orchestrator checks that the built head is still on the branch's first-parent line, walking only the commits gained during the build (usually none), and otherwise retries from the current record.
  • Ledger manager: commit catch-up checks that the oldest new commit's parent is the cached head, and reloads otherwise.
  • Nameservice events: reset_head emits a commit event, as publish_commit does. The rebase, and a rollback after a failed merge, revert or rebase, were silent before. On the file and DynamoDB nameservices a reset also lists its head in the commit-CID index, so the next build keeps its fast path.
  • Query peers: a shared-storage peer takes the server's record whole when its head has diverged from it (a rebase can move a head to a lower or equal t, which the peer used to refuse), or when the record for the peer's own head carries a lower index or none. It then drops its cached ledger. A record for another head never lowers the index, so a stale one replayed out of order cannot.

Not covered here

Tests

  • it_rebase::a_rebase_takes_away_the_index_of_the_line_it_replaced: a branch indexed before the rebase reads every commit from a fresh load after it. Fails without the rebase reset, and without the file nameservice's index-file reset.
  • it_rebase::an_index_of_a_replaced_line_is_not_extended: an old-line index published after the rebase is refused by the incremental build, a full build reads the new line, and an index on the head's line is still extended incrementally. Fails without the indexer base check.
  • it_rebase::a_build_from_the_commit_index_reads_the_rebased_line: a build handed the commit-CID entries after a rebase indexes the new line. Fails without the linkage check.
  • it_rebase::a_rebase_that_skips_every_commit_makes_the_branch_the_source: the branch's head and index are the source's, it reads the source's line, and it accepts a write. Fails without the fix. (it_config_graph::a_setting_both_branches_changed_follows_the_strategy and the Python test_rebase_strategies pin the same outcome for TakeSource and Skip.)
  • it_rebase::a_warm_cache_reloads_across_another_instances_rebase: a second instance holding the branch reloads on refresh and reads the new line. Fails without the catch-up check.
  • it_rebase::a_build_of_the_replaced_line_is_not_published: the publish check refuses a build from the pre-rebase record and accepts builds on the head's line, including one behind the head.
  • storage_ns::reset_head_moves_the_index_back: a reset lowers the index past the separate index file. Fails without the object-storage nameservice fix.
  • notifying::a_reset_is_announced_as_a_commit: a reset emits a commit event with its head. Fails without the emit.
  • peer::sync_task: a record for the peer's head with no index lowers it; a record whose head moved back is taken whole; the record the peer holds changes nothing; a record for another head never lowers the index. The two follow paths each fail their test when disabled. a_build_from_the_commit_index_reads_the_rebased_line also fails without the commit-index mirroring on reset.

The Raft worker's install guard has no test; no Raft rebase test reaches the skip-all path. On Raft a skip-all rebase leaves the branch unchanged rather than making it the source, since its heads only advance.

A rebase that replays a branch's commits copied the source's index onto
the branch only where it was newer than the branch's own, and copied
nothing when the source had none. The branch then kept its own index,
which indexes the line the rebase replaced, and a fresh load read that
index with the new line's later commits on top: the source's commits
the replay was based on were missing from every read until a full
rebuild.

After the new head is published, the branch's index is now reset to the
source's, or to none. A reset could not lower the index on the file
and object-storage nameservices either: their separate index file wins
at an equal or higher t, so reset_head now rewrites it too. The Raft
path is unchanged; its builds are covered by the indexer refusing an
index of another line.
The incremental build walked the head's first-parent line back to the
base index's t and extended the index with what it found, without
checking that the index was of that line. An index of a branch's line
built before a rebase and published after it was extended over the new
line, mixing the two: commits the rebase replaced stayed in the index,
and those the new line holds below its t were missing.

The build now checks that the base index holds the commit the walk
starts after, the head's line at the base's t, and otherwise fails the
incremental build, which falls back to a full rebuild of the head's
line.
@bplatz bplatz added bug Something isn't working as expected area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches labels Nov 11, 2026
bplatz added a commit that referenced this pull request Nov 11, 2026
A rebase that replays a branch's commits copied the source's index onto
the branch only where it was newer than the branch's own, and copied
nothing when the source had none. The branch then kept its own index,
which indexes the line the rebase replaced, and a fresh load read that
index with the new line's later commits on top: the source's commits
the replay was based on were missing from every read until a full
rebuild.

After the new head is published, the branch's index is now reset to the
source's, or to none, and to none as well when an erasure has reached
the source since the rebase read it. A reset could not lower the index
on the file and object-storage nameservices either: their separate
index file wins at an equal or higher t, so reset_head_fenced now
rewrites it too. The Raft path is unchanged; its builds are covered by
the indexer refusing an index of another line.

The same fix as #2296 on main.
bplatz added a commit that referenced this pull request Nov 11, 2026
The incremental build walked the head's first-parent line back to the
base index's t and extended the index with what it found, without
checking that the index was of that line. An index of a branch's line
built before a rebase and published after it was extended over the new
line, mixing the two: commits the rebase replaced stayed in the index,
and those the new line holds below its t were missing.

The build now checks that the base index holds the commit the walk
starts after, the head's line at the base's t, and otherwise fails the
incremental build, which falls back to a full rebuild of the head's
line.

The same fix as #2296 on main.

@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 two moves here make sense to me: reset the index where the rebase moves the head, and have the incremental build refuse a base that isn't on the head's line. Claude checked all four "fails without" claims under mutation and they hold.

Where I'd push is that the same "is this still of the branch's line" assumption is taken on trust in three more places a rebase reaches, and each reproduced as a wrong read at this head: the commit-CID index's fast-path walk, a Skip rebase that skips every commit, and a warm cache in another instance catching up across the rebase. None of these came from this PR, but they're the bug the title promises to fix, each fix is a few lines, and Claude verified all three on a box, so I'd rather see them here.

More broadly, this is a class we keep meeting: a pointer derived from a line, trusted after a rewrite moved the line.

#1822's 1e72c31ef (a failed rebase left the source's index on the branch); both ways in here; #2280's a749fc7c5 (garbage trusted an index of another line); plus the three above

#2292's reasoning-index generations already carry their basis commit and check it against the view's line, which feels like the structural direction. Not for this PR; the point fixes are right here.

Last, a heads-up for when main merges into next: these hunks conflict with #2280's copies in five files, and the resolution wants #2280's versions (the index-file reset that keeps f:fence, and commit_sid for the commit subject).

Full review below:


Approving because the blocking items are relatively small and don't want to keep you waiting

This is a careful fix, @bplatz, and the two mechanisms are the right ones: the reset sits exactly where the rebase moves the head, the nameservice change makes reset_head do what its contract already said, and the incremental-build check is cheap and well placed. I'm requesting changes only for the three blocking items inline, all pre-existing and all reproduced at b367f4de6 on a box: the commit-CID index fast path can hand the build the replaced line (incremental_resolve.rs:394), a Skip rebase that skips everything leaves the branch on the source's index and refusing writes (rebase.rs:555), and a warm cache in another instance catches up across the rebase onto the replaced line (ledger_manager.rs, commented at rebase.rs:634). Each fix is a few lines, and Claude ran each against its repro and the surrounding suites. The race's read window and the Raft and peer hosts are inline as "should" items: fold in what's PR-sized, and have the body name what remains.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ extends reset_head to honor its own contract on every backend and guards the existing incremental path; no parallel mechanism. The class (derived pointers trusted after a rewrite) is in the headline as a follow-up, not for this PR.
  • Performance (speed first, memory second): ✔ one envelope decode and one dictionary lookup per incremental build, no query path touched, and no false refusal after a bulk import (checked). The suggested fixes add one envelope decode per walked commit and one comparison per catch-up. No performance-degradation risk.
  • Deployment targets: ⚠️ shared code every host runs, with single-process, file- and memory-backed evidence. The reset reaches fresh loads on hosts whose nameservice the rebase writes, not warm caches in other instances (reproduced), shared-storage query peers (traced), or Raft nodes (acknowledged). No short-lived-host fence is involved (nothing added runs in the background or lives for the process).
  • Testing: ⚠️ the three new tests run in CI (grp_ledger, fluree-db-nameservice) and each fails without its fix, but all take the serial walk and fresh loads only; the fast path and warm caches, where the remaining bugs live, are untested.
  • Conventions: ✔ self-describing subjects and thorough multi-line bodies; fmt and clippy green on the head SHA.

Verified at branch HEAD: CI green on b367f4de6 (run 42950114255; the test job ran the three new tests by name, 15738 of 15738 passed). On a box, it_rebase 20/20 and each of the body's four mutations red; Claude's repros R1, R2, R2b, R2c, R3, R4 and R6 red at head and R5 green; with the suggested fixes, R1, R2, R2b, R2c and R6 green, indexer lib 470/470, grp_index 180/180, ledger_manager lib 34/34.

Just be sure to get the three blocking fixes in before this merges. They're small, and the repro tests Claude wrote slot straight into it_rebase.rs if you want them.

let (walked_commits, t_walk_chain_ms) = {
let t0 = Instant::now();
let commits = walk_commit_chain_since(cs.as_ref(), &config).await?;
refuse_base_off_the_line(&commits, &subject_tree)?;

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 (pre-existing, not introduced here). On the commit-CID index fast path, the walk this check reads can itself be the replaced line, so the check passes and the build indexes the replaced line anyway.

walk_commit_chain_since takes the nameservice's commit-CID list whenever pending_covers_range (:1384-1395) says it covers the range, and that only checks the ts are contiguous and the tip is the head. A rebase publishes one entry, for its final head, so the entries the replaced line left below it are still there. If the source's index sits at the fork and the new head is one past the old one, [(2, old bob), (3, old carol), (4, carol')] passes, the oldest entry's parent is the fork commit (which the base holds), and this check is satisfied.

Claude reproduced it at this head (file nameservice, without_indexing()): main indexed at alice, branch bob and carol, main dave, rebase, then a build fed pending_commit_cids the way the orchestrator feeds it (orchestrator.rs:2316-2322). The incremental build succeeds at t=4 and a fresh load reads ["alice","bob","carol"], for good. The same build through the serial walk reads all four. The background indexer takes this path on the file and DynamoDB nameservices, while the new tests only ever take the serial walk (build_incremental_index_for_record with a default config leaves pending_commit_cids at None).

The fast path's own comment says correctness must never depend on the index, so I think the fix belongs there: require each commit's first parent to be the commit before it, and fall back to the serial walk otherwise. Claude ran this on a box: the repro goes green, the indexer lib tests stay 470/470 and grp_index 180/180.

fn first_parent_linked(walked: &[WalkedCommit]) -> Result<bool, IncrementalResolveError> {
    use fluree_db_core::commit::codec::read_commit_envelope;
    for pair in walked.windows(2) {
        let envelope = read_commit_envelope(&pair[1].bytes).map_err(|e| {
            IncrementalResolveError::CommitChain(format!("envelope of {}: {e}", pair[1].cid))
        })?;
        if envelope.parents.first() != Some(&pair[0].cid) {
            return Ok(false);
        }
    }
    Ok(true)
}

In the fast path, return Ok(commits) only when first_parent_linked(&commits)?, and otherwise fall through to the serial walk. A variant of an_index_of_a_replaced_line_is_not_extended that sets pending_commit_cids from branch_admin().pending_commit_cids(..) would pin it.

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 0f85f4c

Comment thread fluree-db-api/src/rebase.rs Outdated
// Replay itself reads the source's state, never the copied index,
// so nothing above needs this to have happened. Best-effort.
self.copy_source_index(&source_id, &branch_id, &source_record)
let source_index = 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.

Blocking (pre-existing). A Skip rebase that skips every branch commit still publishes the source's index here, and nothing resets it, so the unmoved branch reads the source's line.

This copy runs whether or not anything replayed, and copy_source_index publishes the source's index on the branch where it's newer. When every commit is skipped, new_head_id is None, so the reset at :634 never runs, and apply_rebase still installs final_state into the cache (:659-663), which on this path is the source's state relabeled to the branch.

Claude reproduced it at this head: the branch's alice-dev and main's alice-main conflict on ex:alice ex:name, main also adds dave and is indexed, and rebase_branch(.., Skip) reports replayed=0, skipped=1. The branch record goes from commit_t=2 index_t=0 to commit_t=2 index_t=3. A fresh load reads ["alice","alice-main","dave"] instead of ["alice","alice-dev"], the same instance's cache reads the same, and the branch's next write fails with CommitConflict { expected_t: 2, head_t: 3 }. The Raft worker shares prepare_rebase, and its no-advance path installs final_state too (commit_worker.rs:1127-1131).

Since the reset in apply_rebase now sets the index whenever something replayed, the copy here only needs to run then, and the install only when there's a new head. Claude ran both changes on a box: the three repros go green and it_rebase stays green.

let source_index = if pending_replays.is_empty() {
    None
} else {
    self.copy_source_index(&source_id, &branch_id, &source_record)
        .await
};

And in apply_rebase, if let Some(guard) = write_guard.filter(|_| new_head_id.is_some()), plus the same guard on the Raft worker's install.

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 f629af2 and 93c3fec

Comment thread fluree-db-api/src/rebase.rs Outdated
self.publisher()?
.publish_commit(&branch_id, new_head_t, last_head_id)
.await?;
if !fast_forward {

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 (pre-existing). This reset fixes fresh loads, but a warm cache in another instance catches up across the rebase by applying the new line's commits onto the replaced line, so the "another instance" reader the body names still reads the replaced line.

LedgerManager::notify's CommitCatchUp (ledger_manager.rs:2651-2700) walks from the record's new head back to the cached t, checks only that it found gap commits, and applies them onto the cached state. After this rebase that is carol' on top of the cached alice, bob, carol. It never looks at the index, so the reset doesn't reach it.

Claude reproduced it at this head with two Fluree instances on one directory: B holds rb:dev warm, A rebases, B.refresh("rb:dev", ..) returns CommitsApplied { count: 1 }, and B reads ["alice","bob","carol"] while A reads all four. That's the shape of a multi-instance server and of a warm embedder polling with refresh(); by Claude's trace (not run), query peers and Raft followers catch their caches up through the same notify (subscription.rs:143; the Raft apply's commit event, app.rs:336-357).

It's the read-side twin of refuse_base_off_the_line: require the oldest walked commit's first parent to be the cached head, and reload otherwise. Claude ran this on a box: B reloads and reads all four, it_rebase is 22/22 and the ledger_manager lib tests 34/34.

// right after the `current_t != local_t` check; `commits` is already oldest-first
let oldest_parent = commits.first().and_then(|c| c.parent_ids().next().cloned());
if oldest_parent.as_ref() != write_guard.state().head_commit_id.as_ref() {
    drop(write_guard);
    self.reload(&input.ledger_id).await?;
    return Ok(NotifyResult::Reloaded);
}

Commenting here because fluree-db-api/src/ledger_manager.rs is not in this diff.

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 c0a90d8

.rebase_branch("rb", "dev", ConflictStrategy::default())
.await
.unwrap();
support::publish_built_index(&fluree, "rb:dev", stale.index_t, &stale.root_id).await;

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.

Should (the race the body names as the second way in). The check stops the stale index from being extended, but between this publish and the next build it is read, and in one shape no build ever comes.

Right after this line, a fresh load reads ["alice","bob","carol"] (Claude ran this test's setup with a read inserted here). The next build is a full rebuild, since the check refuses the old-line base, so on a big ledger the window is a full rebuild long. And when the rebase skipped a commit so the new head's t equals the stale index's t, a build has nothing to do: in Claude's variant (branch bob then alice-dev, main alice-main and dave, Skip), the stale index publishes at t=3, an incremental build at the head returns Ok(3), and the branch reads the replaced line (["alice","alice-dev","bob"]) until its next commit.

We may want the publish side to refuse it: before publish_index_result (orchestrator.rs:2336), re-read the record and drop a build whose head is no longer on the branch's first-parent line (a walk of current_t - index_t envelopes, usually none). That closes both shapes for every host that publishes through the orchestrator, a Raft leader included. Claude didn't run this one, so treat it as a sketch. The load is the other place to catch it, and a cheap one: it already walks from the head down to the index's t for novelty, so the same lookup as refuse_base_off_the_line (the oldest walked commit's parent, or the head itself when the walk is empty, which is the R3 shape) would tell a load that its index is of another line. What a load does then is the harder part, since dropping the index means replaying the whole history, so I'd see it as detection that triggers a rebuild alongside the publish-side refusal rather than instead of it. I recognize it's more than a one-liner, but if you agree it's right I'd rather see it here than lost in the backlog; failing that, I think the body should say the race still serves the stale index until the next build.

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 547eadc (publish-side refusal). Load-time detection: #2382

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.

Publish side in 547eadc; the reset is now one write (). Load-time detection stays on #2382.

let (index_head_id, index_t) =
source_index.map_or((None, 0), |(id, t)| (Some(id), t));
self.branch_admin()?
.reset_head(

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.

Should (deployment targets). This reset reaches hosts whose nameservice the rebase writes directly; two others keep reading the replaced line's index until a full rebuild lands.

  • Raft, which the body calls out: process_rebase (commit_worker.rs:1061-1135) never resets, so every node reads the branch's old-line index under the new head until the post-rebase build, which the new check makes a full rebuild. The Raft reset_head can't be reused from the worker as it stands, since it clears the branch's queue (state_machine.rs:1718-1780).
  • Shared-storage query peers, which the body names as an affected reader (Claude traced this, didn't run it): NotifyingNameService::reset_head emits no event (notifying.rs:119-121), PeerSyncTask skips a record with no index (sync_task.rs:235), and the peer's local FileNameService refuses an IndexHead CAS to a lower t (file.rs:1575-1579). So a peer never lowers its index after a rebase.

For peers, emitting an event on reset and having PeerSyncTask follow a lower or absent index, the way it already force-follows a diverged commit head, seems PR-sized. For Raft, a command that lowers the index without clearing the queue closes it. If that's more than this PR should carry (it's a replicated-log change), I'd at least want the body's Raft sentence to say what the window is: every node, until a full rebuild lands.

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.

Follow-up: #2380 (Raft) and #2381 (query peers); the body states the window for each.

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.

Query peers: addressed in (and for the reset event). Raft stays on #2380; the body states its window.

Comment thread fluree-db-api/src/rebase.rs Outdated
@@ -621,6 +631,24 @@ impl crate::Fluree {
self.publisher()?

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. These are two writes, and the second rewrites the commit head too, unchecked. A commit another process publishes between them drops off the head, and a reader that loads between them caches the replaced line's index under the new head, which a lower index never triggers a reload of (ledger_manager.rs:2443-2452). The window is one await, so I don't think it's likely, but a single reset guarded on the head it expects would close it. 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.

Follow-up: #2382 (listed in the body under remaining windows).

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 : the head and index now move in one reset. The reset is not yet guarded on the expected head; that remainder is on #2382.

/// starts after: the head's line at the base's `t`. An index of a line a
/// rebase replaced does not, and extending it would mix the two lines. The
/// build falls back to a full rebuild, which reads the head's line alone.
fn refuse_base_off_the_line(

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. This is a nice, cheap check: one envelope decode of a commit the walk already holds and one dictionary lookup per build, nothing per commit or per flake. Claude also checked the positive path where a false refusal would hurt most: after a fresh bulk import, a later write still indexes incrementally (and CI covers a graph import, later_writes_index_incrementally_over_the_spliced_root). Each of the four "fails without" claims in the body held under mutation on a box.

…s line

The incremental build takes its commits from the nameservice's commit-CID
index when the entries cover every t up to the head and end at the head.
A rebase publishes an entry for its new head only, so the entries the
replaced line left below it still cover the range. The oldest one's parent
is the fork commit, which the base index holds, so the base check passed
and the build indexed the replaced line under the new head.

The build now checks that each entry's first parent is the entry before
it, and walks the head's line itself when they are not. One envelope
decode per walked commit, of bytes the walk already fetched.
A Skip rebase that skipped every commit still published the source's index
on the branch where it was newer, and installed the replay's final state,
the source's state relabeled to the branch, in the cache. The branch kept
its head but read the source's line from its index and its cache, and its
next write failed with a commit conflict at the source's t.

The source's index is now copied only when a commit was replayed, and the
final state is installed only when the branch has a new head, on the local
and the Raft path.
…ther line

A cached ledger caught up to its nameservice record by walking the head's
first-parent line back to the cached t and applying what it found, checking
only the count. After a rebase in another instance, those commits sit on a
different commit at the cached t, and applying them mixed the new line onto
the replaced one: the cache kept the replaced line's commits and missed the
source's.

Catch-up now checks that the oldest commit's parent is the cached head and
reloads otherwise.
The background indexer published a build without checking that the
branch was still on the built head's line. A build from the branch's
record just before a rebase, published just after it, served the replaced
line under the new head until the next build; when the rebase skipped a
commit and left the head at the build's t, no next build came.

Before publishing, the orchestrator now checks that the built head is on
the current head's first-parent line, walking only the commits the branch
gained during the build, and otherwise retries from the current record.
A rebase whose branch commits all drop out (Skip on every conflict, or
every replay empty after resolution, as TakeSource leaves a branch whose
only change the source overrode) means the branch is the source. Before
the previous commit the local apply got there halfway: it installed the
source's state in the cache and published the source's index on the
branch, but left the branch's head where it was, so its next write
failed with a commit conflict and a fresh load mixed the source's index
with the branch's head. The previous commit kept the branch as it was
instead, which broke that outcome.

The local apply now moves the branch's head and index to the source's in
one reset and installs the source's state. The Raft path, whose heads
only advance, still completes the entry with the branch unchanged and
installs nothing.
A non-fast-forward rebase published the new head and then reset the head
and index; a reader between the two saw the new head over the replaced
line's index. The reset alone writes both. A reset now emits a commit
event, so subscribers re-read the record: the rebase, and a rollback after
a failed merge, revert or rebase, were silent before.
…branch

The peer's refs only move forward. A rebase that resets a branch's index
to the source's, or to none, left the peer serving the replaced line's
index, and one that moved the head to a lower or equal t was refused as
'should never happen'. The server's record is authoritative, so a peer
that has diverged from it, or that holds a newer index than the record for
its own head, takes the record whole and drops its cached ledger.
publish_commit mirrors each head into the file and DynamoDB commit
indexes; reset_head did not. With the rebase now writing its head through
a reset, the next build found the index short of the head and walked the
chain serially. A reset records its head as a publish does; the build's
linkage check already rejects entries of the line a reset replaced.
@bplatz

bplatz commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Since your approval: all three Blocking threads and the peer and two-writes items are addressed, and origin/main is merged in. Raft (#2380) and load-time detection (#2382) remain follow-ups.

One behavior to look at: for a rebase that skips every branch commit, your thread expected the branch to stay on its own line. It now becomes the source instead, with head and index moved together (93c3fec). That matches what it_config_graph and the Python test_rebase_strategies already pinned for TakeSource and Skip. The Raft path can't move a head backwards, so there the branch is left unchanged, and the two paths differ for that case.

@bplatz
bplatz requested a review from aaj3f November 13, 2026 19:22
@bplatz
bplatz merged commit ba861b9 into main Nov 13, 2026
19 checks passed
@bplatz
bplatz deleted the fix/rebase-branch-index branch November 13, 2026 19:40
bplatz added a commit that referenced this pull request Nov 13, 2026
Brings #2296, #2309, #2313, #2315, #2316, #2317, #2367, #2368, #2369,
#2373, #2374, #2378 and #2379.

Ports onto next:

- #2374 (bound-object probe reads POST): main's POST walk and per-type
  flush replace next's OPST walk. The lane keys (o_type, o_key), so next's
  triple-term handles are one more covered type (object_probe_covers takes
  TripleTermDict) rather than a flush per type; a term's matches are read
  whole, as a ref's are. The wildcard cursor still keys refs only. Pooled
  graphs decline through dedicated_branch(Post); o_i is 64-bit. Next's
  pair join keys its subject through the shared LaneKey.
- #2373 (leaflet type constant under replay): replays_history and
  o_type_const_for beside next's may_hold_keys; the row-labelling lanes
  take main's const-unless-replaying form over next's always-read-column.
- #2368: the cyclic join decodes for eager callers with next's list index
  sentinel; both reasoning tests kept (cyclic operator and pair lane).
- #2317 (GRAPH streams): main's work queue and InnerStream with next's
  pooled-graph pruning before each enumerated graph.
- #2315: list predicates are an ordered set in next's multi-ledger view;
  the annotation edge probe stays deleted (no bundle lane on next).
- #2296 (rebase reads its new line): ported onto next's fenced resets,
  erasure checks and peer sync (follow_record keeps next's unchanged-head
  arm); a non-fast-forward rebase moves head and index in one fenced
  reset.
- Main's new tests: async genesis_ledger, graph_source_store for mapping
  writes, leaf_rows for leaflets-per-leaf, storage lock off for two file
  instances. New pattern/function matches cover TermComponents and the
  triple-term functions; AnnotationTarget arms dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:storage Storage backends, nameservice, ledger lifecycle, index storage, caches bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared-storage query peers never lower a branch's index after a rebase

2 participants