Skip to content

Fix stale block content after SQLite INSERT OR REPLACE - #68

Open
marcobambini wants to merge 1 commit into
fix/block-lww-upsert-tombstonefrom
codex/block-replace-stale-blocks
Open

marcobambini wants to merge 1 commit into
fix/block-lww-upsert-tombstonefrom
codex/block-replace-stale-blocks

Conversation

@marcobambini

Copy link
Copy Markdown
Member

With SQLite’s default recursive_triggers=OFF, INSERT OR REPLACE skips the old row’s delete trigger. Replacing block text AAA\nBBB\nCCC with ZZZ could therefore produce ZZZ\nBBB\nCCC on replicas and after local materialization.

This change snapshots the existing block names for the exact primary key and column, tombstones and removes those blocks, then writes the replacement. Block-write errors propagate so the enclosing replacement rolls back. Existing INSERT NULL handling is preserved.

Dependency

This PR is stacked on #46 and targets fix/block-lww-upsert-tombstone. Its parity-preserving metadata upsert is required when replacement blocks reuse retired position IDs. Merge #46 first, then retarget this PR to main.

Validation

  • Full SQLite unit suite passes, including 120 replacement cycles with recursive triggers OFF and ON, shorter/longer/empty/NULL values, fractional positions, duplicate payload delivery, source/replica materialization, and injected write-failure rollback.
  • The new regression fails against the previous implementation.
  • Initial implementation: 30,000 mixed writes, 10,800 payload deliveries and 600 convergence comparisons across three replicas.
  • Final commit after allocation-cleanup hardening: full suite plus 3,000 mixed writes, 1,080 deliveries and 60 convergence comparisons.
  • Focused sanitizer runs pass; the full suite retains two pre-existing signed-shift UBSan diagnostics in random row-ID test generation.
  • Remote CI run failed; this PR is not yet CI-green.

Implementation and regression details: docs/block-replace-fix.md.

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