Skip to content

fix(id): refuse replication snapshot header-version downgrade (#4487) - #7357

Closed
dezren39 wants to merge 2 commits into
mainfrom
queue/12693-4487-snapshot-downgrade-guard
Closed

dezren39 wants to merge 2 commits into
mainfrom
queue/12693-4487-snapshot-downgrade-guard

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #4487

ReplicationTracker::accept rebased onto any Snapshot frame's chain — including a snapshot with a lower header version than the chain already verified. Tail and Terminal frames refuse any version change (HeaderVersionChanged), but the Snapshot branch assigned self.header_version = envelope.header_version unconditionally, so a stale snapshot silently rolled the replica back to an older journal version and re-admitted old-version tails.

Change

  • pkgs/id/src/world/replication.rs — Snapshot branch: refuse envelope.header_version < self.header_version with ReplicationError::HeaderVersionChanged, before any state changes. Equal-version rebase (first sync / compaction) and header bumps stay accepted, per the existing design comment and snapshot_rebases_the_chain_on_a_header_bump.

Tests (oracle: tracker state invariants — a refused frame leaves the last complete replica state intact)

  • snapshot_with_a_lower_header_version_is_refused — after a bump to version 2, a version-1 snapshot is refused and header_version/cursor are unchanged.
  • snapshot_at_the_current_header_version_still_rebases — same-version snapshot after a tail is still accepted.

Queue task 12693 (lane code-w).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

ReplicationTracker::accept rebased onto any snapshot chain, including
one with a lower header version than the verified chain — silently
rolling the replica back and re-admitting old-version tails. Refuse
downgrades with HeaderVersionChanged; equal-version rebase and header
bumps stay accepted. Fixes #4487
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 06:41
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8995249e-32fb-43fb-8bde-baf6f53ea262
Commits

Reviewing files that changed from the base of the PR and between 0929995 and d6449f8.

Files selected for processing: 1

  • pkgs/id/src/world/replication.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T06:50:31.573634Z d6449f8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ddbab0a1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1536 to +1537
#[test]
fn snapshot_with_a_lower_header_version_is_refused() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add property coverage for snapshot version monotonicity

The new replication invariant is covered only by fixed downgrade and equal-version examples. Root AGENTS.md explicitly requires property tests for replication/state-machine invariants and says examples do not replace them. Add a proptest over supported snapshot-version sequences that checks accepted versions never decrease and rejected snapshots preserve the complete tracker state, including last_frame_digest; the current assertions check only the version and cursor.

AGENTS.md reference: AGENTS.md:L41-L45

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d6449f8: added snapshot_versions_never_decrease_and_refusals_preserve_state, a proptest (64 cases) over generated snapshot-version sequences (1..=MAX_JOURNAL_VERSION). It asserts accepted versions never decrease, and that every refused downgrade returns HeaderVersionChanged while preserving the complete tracker state — header_version, cursor, and last_frame_digest (read directly from the tracker in-module). Verified passing on the laptop along with the replication suite (44 tests).

Codex review finding on PR #7357: the downgrade invariant was covered
only by fixed examples. Add a proptest over snapshot-version sequences
asserting accepted versions never decrease and refused snapshots
preserve the complete tracker state (version, cursor, last frame
digest).
@dezren39

Copy link
Copy Markdown
Member Author

Closing as superseded — shepherd pass, queue task 17324 (90-day review open-PR pass). Fresh evidence, all checked 2026-11-16:

Outcome recorded per the shepherd acceptance: closed with fresh evidence the change is landed elsewhere. Head branch left in place (packet scope excludes deleting it while closing is in flight; it is inert).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(replication): ReplicationTracker accepts a snapshot with a lower header version — replica silently rolls back and re-admits old-version tails

1 participant