Skip to content

Reject KV map acquisition across rollback - #8799

Draft
Eddy Ashton (eddyashton) wants to merge 8 commits into
mainfrom
agents/cpp-kv-semantics-discussion
Draft

Eddy Ashton (eddyashton) wants to merge 8 commits into
mainfrom
agents/cpp-kv-semantics-discussion

Conversation

@eddyashton

@eddyashton Eddy Ashton (eddyashton) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Prevent a C++ KV transaction from combining map views from different rollback branches. The issue is described in the original discussion and the model-based opacity follow-up, #8795.

Transactions capture the store's validity epoch with their read version. Each map tracks its last-observed epoch; new acquisitions check compatibility under the map lock before returning state or recording successful acquisition. This permits unaffected maps across rollback while rejecting histories invalidated or subsequently written on a replacement branch. Snapshot installation and map swaps also invalidate replaced histories.

The Lean model specifies original map birth/revision identities and retention, rather than implementation epochs. It permits conservative refusal only after the transaction's captured snapshot crosses a truncating rollback of its store. Replay checks successful acquisitions and explicit unavailability against those transitions.

Safety and compatibility

Acquisition can be conservatively rejected even when the requested revision survives, for example when rollback removes a newer revision of the same map. Existing captured handles remain usable, and read-only transactions can complete using those views.

Acquisition conflicts use the existing CompactedVersionConflict, preserving callers' retry handling. The entire attempt must be retried after an acquisition conflict.

Validation

Post-merge KV, frontend, node-frontend and retry-helper unit suites pass. Lean build, kernel/axiom checks, import checks, lint/format, all 70 replay fixtures and captured C++ suite/fuzz traces pass. Kernel checks required the no-sandbox option because bubblewrap permissions were unavailable locally.

Add regression coverage for mixed snapshots and preserve read-only completion through already acquired handles. Cover reserved handle acquisition on either side of rollback. The mixed-snapshot assertion requires the following fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Capture the store rollback epoch with the read snapshot and check it before exposing a newly acquired map view. Preserve existing handles and read-only completion, and leave write-only reserved transactions on their existing reservation validation path.

Capture proposal history snapshots and their epoch under the store version lock. Reuse CompactedVersionConflict so callers retain their existing retry handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove assertions requiring cross-rollback acquisition to succeed. Retain removed-map handles, unaffected-map epoch checks, replacement-version reuse, and stale-writer rejection without restarting the transaction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Check a local copy of the captured rollback count so clang-tidy can track optional validity, and avoid dereferencing the read TxID solely for the conflict message.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eddyashton
Eddy Ashton (eddyashton) marked this pull request as ready for review November 19, 2026 14:00
@eddyashton
Eddy Ashton (eddyashton) requested a review from a team as a code owner November 19, 2026 14:00
Copilot AI balanced review requested due to automatic review settings November 19, 2026 14:00

Copilot AI 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.

🟡 Changes recommended

Rollback during KV-backed endpoint lookup can escape the retry and HTTP exception handlers and reach the task worker’s abort handler.

2 open issues
What changed in this PR

This PR addresses the mixed-snapshot behavior identified in #8795 by tying CCF transaction snapshots to a store rollback epoch and rejecting new map acquisitions after rollback.

Changes:

  • Capture and validate the rollback epoch, including explicitly selected proposal snapshots.
  • Preserve existing handles and reserved-transaction behavior while reusing CompactedVersionConflict for retries.
  • Update rollback regression scenarios, trace requirements, and release notes.

Custom instructions used

  • .github/instructions/reviewing.instructions.md
File Description
tests/​kv_trace_validation.py Require the rollback map-acquisition trace scenario.
src/​node/​test/​retry_on_compacted_version_conflict.cpp Adapt the test store to the expanded snapshot API.
src/​node/​rpc/​frontend.h Pass the rollback epoch with proposal snapshots.
src/​kv/​tx.cpp Capture the epoch and reject acquisitions after rollback.
src/​kv/​tx_pimpl.h Store the transaction's read rollback epoch.
src/​kv/​test/​kv_trace.cpp Add and update rollback acquisition scenarios.
src/​kv/​test/​kv_test.cpp Cover reserved handles acquired after rollback.
src/​kv/​store.h Return rollback epochs alongside snapshot metadata.
src/​kv/​kv_types.h Extend the abstract store snapshot API.
src/​kv/​compacted_version_conflict.h Document rollback-triggered retry conflicts.
src/​kv/​committable_tx.h Record epochs for explicitly selected snapshots.
include/​ccf/​tx.h Validate the epoch after capturing a new map view.
.changes/​kv-rollback-map-acquisition.fixed.md Describe the rollback consistency fix.

Review effort: Balanced

Comment thread src/kv/tx.cpp Resolved
Comment thread include/ccf/tx.h Resolved
Check captured validity epochs while acquiring map state, before recording acquisition success. Permit unaffected maps across rollback and invalidate histories consistently on rollback, snapshot installation and map swaps.

Keep the Lean model abstract: acquired birth and revision identities must match the captured snapshot, with conservative refusal permitted only after crossing a truncating rollback. Update replay, proofs and rollback fixtures to validate the observable outcomes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

Labels

run-long-test Run Long Test job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants