Skip to content

fix(core): only rewind payload ops in direct-rewind catch-up - #309

Draft
marcus-pousette wants to merge 1 commit into
mainfrom
fix/direct-rewind-rejected-moves
Draft

marcus-pousette wants to merge 1 commit into
mainfrom
fix/direct-rewind-rejected-moves

Conversation

@marcus-pousette

Copy link
Copy Markdown
Collaborator

Direct-rewind catch-up could not undo an insert or move exactly. It reattached the node, but the op stayed in last_change, which defensive deletion reads. It also restored the latest earlier structural op even when a cycle check had rejected that op.

Example: ROOT → G → D → T, with D deleted and N under ROOT. S (lamport 7) moves N under T, which revives D. X (lamport 6) moves G under N and arrives after S. In canonical order S is a cycle, so D stays deleted. After the direct rewind, last_change(T) still held S, so D stayed visible.

Change

  • The direct rewind now only rewinds payload ops. Payloads are last-writer-wins, so the previous value is the latest earlier payload op.
  • When the already-materialized part of the suffix holds an insert or move, it returns None and the caller runs catch_up_materialized_state.
  • rewind_structure_op_in_place and latest_structural_before (core default, sqlite and Postgres) are removed.

Cost

Out-of-order appends with an insert or move in the materialized suffix now take the full catch-up instead of the direct rewind. That costs nothing over main.

orchestrate_persisted_remote_append calls .unwrap_or(catch_up(..)?), which evaluates the full catch-up eagerly. It has run after every successful direct rewind since #123 and repaired the rows, but its outcome was discarded. That is why reads converged on main while onMaterialized, onMaterializedDurable and changedSince missed D's deletion. These appends now skip the redundant rewind.

Making the fallback lazy, so payload-only suffixes actually skip the full catch-up, is left for a follow-up.

Tests

  • New conformance scenario: "defensive delete: a late move that rejects a reviving move hides the node again". One replica applies the ops in canonical order, the other receives X late. The scenario checks that their dumps match and that the late append reports D deleted.
    • On main it fails on the event check on sqlite-node and postgres-napi.
    • With a lazy fallback on main, the dumps differ as well.
  • replayed_conflicting_moves_report_final_parents drops its full_replay flag. A move in the materialized suffix now forces the full catch-up by itself, so both variants ran the same path.
  • Local runs, all passing:
    • Rust: core, sqlite-ext round trip, postgres-rs (local postgres:16)
    • sqlite-node: 52/52
    • wa-sqlite: 83/83
    • postgres-napi: 38 passed, 11 skipped
    • wa-sqlite browser e2e: 17 passed, 7 skipped by project or CI gates
    • clippy -D warnings, rustfmt, prettier

Direct rewind reattached a rewound insert or move but left it in
`last_change`, which defensive deletion reads, and restored the latest
earlier structural op even when a cycle check had rejected it. When a
late op made an applied move a cycle, the node that move had revived
stayed visible in the reported outcome.

Return None when the materialized part of the suffix holds an insert or
move, so the caller runs the full catch-up. That catch-up already ran
eagerly after every direct rewind, so this adds no work. Remove the
structural rewind helpers and `FrontierRewindStorage::latest_structural_before`.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant