# Complete-range recovery example

A merge can leave a deleted key visible. This in-memory example compares that
merge with atomic replacement of a known complete key interval.

## Reproduce

From this directory using Node.js:

```sh
node model.mjs
node model.mjs --check
node --test model.test.mjs
```

[Model](model.mjs), [tests](model.test.mjs), [generated results](results.json).
The JSON contains the inputs, assumptions and all six scenarios.

## Read the result

The receiver contains `a=old`, `b=deleted-but-visible` and `z=outside`.
A complete donor range `[a,b]` contains only `a=new`.
Merging values leaves `b`; replacing that complete range removes it and preserves `z`.
A complete empty range removes both `a` and `b`.
Incomplete ranges, mismatched log positions and out-of-range patch entries are rejected.

Tests independently enumerate 4,374 receiver/donor/range combinations over three
keys, each absent or holding one of two values. They also check input validation,
idempotence and non-mutation.

## Scope

Synthetic teaching model, not DIRECT software, a consensus protocol, disk fault
injection or performance replication. Only current string values are represented.
Older versions, snapshots, log delivery, concurrency, authentication and durable
writes are outside the model. Atomicity means returning a new JavaScript array
after checks, not crash-atomic persistence.

Completeness and prefix identity are trusted inputs. A donor can incorrectly
label a partial scan complete, and this model cannot detect that lie. Removing
keys based on an ordinary partial query would therefore be unjustified.

Research context: [DIRECT, ATC 2019](https://www.usenix.org/system/files/atc19-tai.pdf),
sections 4.2.3-4.2.5; [corpus record](https://hesela.dev/terms/direct-recovery/).
No third-party paper text, figure, data or implementation is redistributed.
